diff --git a/.github/actions/int-test/entrypoint.sh b/.github/actions/int-test/entrypoint.sh index 3cec53f2e1..22140df096 100644 --- a/.github/actions/int-test/entrypoint.sh +++ b/.github/actions/int-test/entrypoint.sh @@ -7,4 +7,4 @@ export ATLAS_PRIVATE_KEY="${INPUT_ATLAS_PRIVATE_KEY}" # otherwise we may get strange "Detected Programmatic Focus - setting exit status to 197" export GINKGO_EDITOR_INTEGRATION="true" -ginkgo --label-filter="${INPUT_TEST_NAME}" --timeout 80m -v -nodes="${INPUT_PARALLEL_NODES}" "${INPUT_TEST_PATH}" +AKO_INT_TEST=1 ginkgo --label-filter="${INPUT_TEST_NAME}" --timeout 80m -v -nodes="${INPUT_PARALLEL_NODES}" "${INPUT_TEST_PATH}" diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 292eb612a6..d0310f2334 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -242,8 +242,8 @@ jobs: # no `long-run`, no `broken` tests. `Long-run` tests run as a separate job [[ $TEST_NAME == 'long-run' ]] && filter='long-run && !broken' || filter="$TEST_NAME"' && !long-run && !broken' && \ - echo 'Running: ginkgo --label-filter="${filter}" --timeout 120m --nodes=10 --cover --v' && \ - ginkgo --label-filter="${filter}" --timeout 120m --nodes=10 --flake-attempts=1 --cover --v --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/pkg/... + echo 'Running: AKO_E2E_TEST=1 ginkgo --label-filter="${filter}" --timeout 120m --nodes=10 --cover --v' && \ + AKO_E2E_TEST=1 ginkgo --label-filter="${filter}" --timeout 120m --nodes=10 --flake-attempts=1 --cover --v --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/pkg/... - name: Upload operator logs if: ${{ failure() }} uses: actions/upload-artifact@v3 diff --git a/.github/workflows/test-int.yml b/.github/workflows/test-int.yml index ef6605cc3b..02cee8c4dd 100644 --- a/.github/workflows/test-int.yml +++ b/.github/workflows/test-int.yml @@ -66,7 +66,7 @@ jobs: go install github.com/onsi/gomega/... cd ${{ matrix.path }} - ginkgo --label-filter="${TEST_NAME}" --timeout 90m --v --nodes="${PARALLEL_NODES}" --flake-attempts=1 --cover --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/pkg/... + AKO_INT_TEST=1 ginkgo --label-filter="${TEST_NAME}" --timeout 90m --v --nodes="${PARALLEL_NODES}" --flake-attempts=1 --cover --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/pkg/... - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index c6344d7f4e..6b3c4b6057 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -38,7 +38,7 @@ jobs: - run: go version - name: Run testing - run: CGO_ENABLED=0 go test -v $(go list ./pkg/...) -coverprofile=coverage.out + run: CGO_ENABLED=0 go test -v $(go list ./... |grep -v 'test/int\|test/e2e') -coverprofile=coverage.out - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/Makefile b/Makefile index ae40316383..3e0d4364f6 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,8 @@ ifndef TARGET_OS TARGET_OS := $(shell go env GOOS) endif +GO_UNIT_TEST_FOLDERS=$(shell go list ./... |grep -v 'test/int\|test/e2e') + # DEFAULT_CHANNEL defines the default channel used in the bundle. # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") # To re-generate a bundle for any other default channel without changing the default setup, you can: @@ -92,7 +94,7 @@ all: manager ## Build all binaries .PHONY: unit-test unit-test: - go test -race -cover ./pkg/... + go test -race -cover $(GO_UNIT_TEST_FOLDERS) .PHONY: int-test int-test: ENVTEST_ASSETS_DIR = $(shell pwd)/testbin diff --git a/scripts/e2e_local.sh b/scripts/e2e_local.sh index c5fa5c5e1a..c326f56eba 100755 --- a/scripts/e2e_local.sh +++ b/scripts/e2e_local.sh @@ -40,4 +40,4 @@ export MCLI_PUBLIC_API_KEY="${public_key}" export MCLI_PRIVATE_API_KEY="${private_key}" export MCLI_ORG_ID="${org_id}" export IMAGE_URL="${image}" #for helm chart -ginkgo --label-filter="${focus_key}" --timeout 120m -v test/e2e/ +AKO_E2E_TEST=1 ginkgo --label-filter="${focus_key}" --timeout 120m -v test/e2e/ diff --git a/scripts/int_local.sh b/scripts/int_local.sh index 53cb93fd4f..a5fde120c8 100755 --- a/scripts/int_local.sh +++ b/scripts/int_local.sh @@ -16,4 +16,4 @@ export MCLI_PUBLIC_API_KEY="${public_key}" export MCLI_PRIVATE_API_KEY="${private_key}" export MCLI_ORG_ID="${org_id}" -ginkgo --label-filter="${label}" --timeout 80m -v ./test/int -coverprofile cover.out \ No newline at end of file +AKO_INT_TEST=1 ginkgo --label-filter="${label}" --timeout 80m -v ./test/int -coverprofile cover.out \ No newline at end of file diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 5513d5d422..88995144df 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -1,6 +1,7 @@ package e2e_test import ( + "fmt" "os" "testing" "time" @@ -11,6 +12,7 @@ import ( "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas" "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/config" "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/utils" + "github.com/mongodb/mongodb-atlas-kubernetes/test/helper" ) const ( @@ -27,11 +29,18 @@ var ( ) func TestE2e(t *testing.T) { + if !helper.Enabled("AKO_E2E_TEST") { + t.Skip("Skipping e2e tests, AKO_E2E_TEST is not set") + } RegisterFailHandler(Fail) RunSpecs(t, "E2E Suite") } var _ = BeforeSuite(func() { + if !helper.Enabled("AKO_E2E_TEST") { + fmt.Println("Skipping e2e BeforeSuite, AKO_E2E_TEST is not set") + return + } GinkgoWriter.Write([]byte("==============================Before==============================\n")) SetDefaultEventuallyTimeout(EventuallyTimeout) SetDefaultEventuallyPollingInterval(PollingInterval) diff --git a/test/helper/enable.go b/test/helper/enable.go new file mode 100644 index 0000000000..f860b7093b --- /dev/null +++ b/test/helper/enable.go @@ -0,0 +1,11 @@ +package helper + +import ( + "os" + "strings" +) + +func Enabled(envvar string) bool { + value := strings.ToLower(os.Getenv(envvar)) + return value == "1" +} diff --git a/test/int/clusterwide/integration_suite_test.go b/test/int/clusterwide/integration_suite_test.go index bc1311cc03..0f46fbd409 100644 --- a/test/int/clusterwide/integration_suite_test.go +++ b/test/int/clusterwide/integration_suite_test.go @@ -17,6 +17,7 @@ limitations under the License. package int import ( + "fmt" "net/http" "os" "path/filepath" @@ -37,6 +38,7 @@ import ( "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdatabaseuser" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch" + "github.com/mongodb/mongodb-atlas-kubernetes/test/helper" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -74,11 +76,18 @@ func init() { } func TestAPIs(t *testing.T) { + if !helper.Enabled("AKO_INT_TEST") { + t.Skip("Skipping int tests, AKO_INT_TEST is not set") + } RegisterFailHandler(Fail) RunSpecs(t, "Project Controller Suite") } var _ = BeforeSuite(func() { + if !helper.Enabled("AKO_INT_TEST") { + fmt.Println("Skipping int BeforeSuite, AKO_INT_TEST is not set") + return + } done := make(chan interface{}) go func() { logger := ctrzap.NewRaw(ctrzap.UseDevMode(true), ctrzap.WriteTo(GinkgoWriter), ctrzap.StacktraceLevel(zap.ErrorLevel)) diff --git a/test/int/integration_suite_test.go b/test/int/integration_suite_test.go index 797c98a3d8..2f386ba504 100644 --- a/test/int/integration_suite_test.go +++ b/test/int/integration_suite_test.go @@ -28,6 +28,7 @@ import ( "time" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdatafederation" + "github.com/mongodb/mongodb-atlas-kubernetes/test/helper" "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -91,6 +92,9 @@ func init() { } func TestAPIs(t *testing.T) { + if !helper.Enabled("AKO_INT_TEST") { + t.Skip("Skipping int tests, AKO_INT_TEST is not set") + } RegisterFailHandler(Fail) RunSpecs(t, "Atlas Operator Integration Test Suite") } @@ -100,6 +104,10 @@ func TestAPIs(t *testing.T) { // The first function starts the envtest (done only once by the 1st node). The second function is called on each of // the ginkgo nodes and initializes all reconcilers and clients that will be used by the test. var _ = SynchronizedBeforeSuite(func() []byte { + if !helper.Enabled("AKO_INT_TEST") { + fmt.Println("Skipping int SynchronizedBeforeSuite, AKO_INT_TEST is not set") + return nil + } By("bootstrapping test environment") testEnv = &envtest.Environment{