From ff07673e39683c688004eb0639ddf17b36d40d56 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Mon, 8 Apr 2024 09:25:01 -0700 Subject: [PATCH] Reenable Unit Testing in GitHub Actions (#5676) * Remove invalid stale input Signed-off-by: Derek Nola * Enable unit testing in CI Signed-off-by: Derek Nola --------- Signed-off-by: Derek Nola --- .github/workflows/stale.yml | 1 - .github/workflows/unitcoverage.yaml | 41 ------------------------- .github/workflows/unittest.yaml | 47 +++++++++++++++++++++++++++++ pkg/rke2/rke2_linux_test.go | 9 +++--- 4 files changed, 51 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/unitcoverage.yaml create mode 100644 .github/workflows/unittest.yaml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index d4f78c6329..cacc3e212c 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -15,7 +15,6 @@ jobs: with: # ensure PRs are exempt days-before-pr-stale: -1 - day-before-pr-closed: -1 days-before-issue-stale: 45 days-before-issue-close: 14 diff --git a/.github/workflows/unitcoverage.yaml b/.github/workflows/unitcoverage.yaml deleted file mode 100644 index c19cad73f6..0000000000 --- a/.github/workflows/unitcoverage.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# name: Unit Test Coverage -# on: -# push: -# paths-ignore: -# - "install.sh" -# - "tests/vagrant/**" -# pull_request: -# paths-ignore: -# - "install.sh" -# - "tests/vagrant/**" -# jobs: -# test: -# name: Unit Tests -# runs-on: ${{ matrix.os }} -# strategy: -# matrix: -# os: [ubuntu-20.04] -# timeout-minutes: 20 -# steps: -# - name: Install Go -# uses: actions/setup-go@v3 -# with: -# go-version: '1.19.3' -# - name: Checkout -# uses: actions/checkout@v3 -# with: -# fetch-depth: 1 -# - name: Run Unit Tests -# run: | -# go test -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./pkg/... -run Unit -# go tool cover -func coverage.out -# - name: On Failure, Launch Debug Session -# if: ${{ failure() }} -# uses: mxschmitt/action-tmate@v3 -# timeout-minutes: 2 -# - name: Upload Results To Codecov -# uses: codecov/codecov-action@v1 -# with: -# files: ./coverage.out -# flags: unittests # optional -# verbose: true # optional (default = false) diff --git a/.github/workflows/unittest.yaml b/.github/workflows/unittest.yaml new file mode 100644 index 0000000000..24a66f54f4 --- /dev/null +++ b/.github/workflows/unittest.yaml @@ -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) diff --git a/pkg/rke2/rke2_linux_test.go b/pkg/rke2/rke2_linux_test.go index 555066e791..424e4fcb29 100644 --- a/pkg/rke2/rke2_linux_test.go +++ b/pkg/rke2/rke2_linux_test.go @@ -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"}, @@ -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"}, @@ -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"}, }, @@ -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"}, }, @@ -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"}, }, @@ -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)