Skip to content

Commit

Permalink
Enable unit testing in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Apr 4, 2024
1 parent b08170c commit db079dd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/unitcoverage.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Unit Test Coverage
on:
push:
paths-ignore:
- "**.md"
- "channels.yaml"
- "install.sh"
- "tests/**"
- ".github/**"
- "!.github/workflows/unittest.yaml"
pull_request:
paths-ignore:
- "**.md"
- "channels.yaml"
- "install.sh"
- "tests/**"
- ".github/**"
- "!.github/workflows/unittest.yaml"

permissions:
contents: read

jobs:
test:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run Unit Tests
run: |
go test -coverpkg=./... -coverprofile=coverage.out ./pkg/... -run Unit
go tool cover -func coverage.out
- name: Upload Results To Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
flags: unittests # optional
verbose: true # optional (default = false)
9 changes: 4 additions & 5 deletions pkg/rke2/rke2_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func Test_UnitInitExecutor(t *testing.T) {
{
name: "agent",
args: args{
clx: cli.NewContext(nil, flag.NewFlagSet("test", 0), nil),
cfg: Config{
ControlPlaneProbeConf: []string{"kube-proxy-startup-initial-delay-seconds=42"},
ControlPlaneResourceLimits: []string{"kube-proxy-cpu=123m"},
Expand Down Expand Up @@ -62,7 +61,6 @@ func Test_UnitInitExecutor(t *testing.T) {
{
name: "server",
args: args{
clx: cli.NewContext(nil, flag.NewFlagSet("test", 0), nil),
cfg: Config{
ControlPlaneProbeConf: []string{"kube-proxy-startup-initial-delay-seconds=123"},
ControlPlaneResourceLimits: []string{"kube-proxy-cpu=42m"},
Expand Down Expand Up @@ -96,7 +94,6 @@ func Test_UnitInitExecutor(t *testing.T) {
{
name: "bad probe conf",
args: args{
clx: cli.NewContext(nil, flag.NewFlagSet("test", 0), nil),
cfg: Config{
ControlPlaneProbeConf: []string{"kube-proxy-startup-initial-delay-seconds=-123"},
},
Expand All @@ -106,7 +103,6 @@ func Test_UnitInitExecutor(t *testing.T) {
{
name: "bad control plane limits",
args: args{
clx: cli.NewContext(nil, flag.NewFlagSet("test", 0), nil),
cfg: Config{
ControlPlaneResourceLimits: []string{"kube-proxy-cpu"},
},
Expand All @@ -116,7 +112,6 @@ func Test_UnitInitExecutor(t *testing.T) {
{
name: "bad control plane requests",
args: args{
clx: cli.NewContext(nil, flag.NewFlagSet("test", 0), nil),
cfg: Config{
ControlPlaneResourceRequests: []string{"kube-proxy-memory"},
},
Expand All @@ -126,6 +121,10 @@ func Test_UnitInitExecutor(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Override the pss location so we attempt to create a file that needs sudo, not what we are testing anyways
flagSet := flag.NewFlagSet("test", 0)
flagSet.String("pod-security-admission-config-file", "/tmp/pss.yaml", "")
tt.args.clx = cli.NewContext(nil, flagSet, nil)
got, err := initExecutor(tt.args.clx, tt.args.cfg, tt.args.isServer)
if (err != nil) != tt.wantErr {
t.Errorf("initExecutor() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit db079dd

Please sign in to comment.