Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-192976: Unit test everything but int and e2e #1075

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/int-test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-int.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
2 changes: 1 addition & 1 deletion scripts/int_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
AKO_INT_TEST=1 ginkgo --label-filter="${label}" --timeout 80m -v ./test/int -coverprofile cover.out
9 changes: 9 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e_test

import (
"fmt"
"os"
"testing"
"time"
Expand All @@ -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 (
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/helper/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package helper

import (
"os"
"strings"
)

func Enabled(envvar string) bool {
value := strings.ToLower(os.Getenv(envvar))
return value == "1"
}
josvazg marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions test/int/clusterwide/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package int

import (
"fmt"
"net/http"
"os"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions test/int/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
}
Expand All @@ -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{
Expand Down
Loading