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-272039: Fail when no tests are run #1809

Merged
merged 6 commits into from
Sep 12, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ jobs:
"teams",
"backup-config",
"datafederation",
"deletion-protection",
"atlas-search-nodes",
"atlas-search-index",
"cache-watch",
Expand Down
7 changes: 6 additions & 1 deletion scripts/int_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ if [ -z "${label+x}" ]; then
label=""
fi

cluster_wide_labels=("ClusterWide")

int_test_folder=int
if [[ ${cluster_wide_labels[*]} =~ ${label} ]]; then
int_test_folder=int/clusterwide
fi
public_key=$(grep "ATLAS_PUBLIC_KEY" .actrc | cut -d "=" -f 2)
private_key=$(grep "ATLAS_PRIVATE_KEY" .actrc | cut -d "=" -f 2)
org_id=$(grep "ATLAS_ORG_ID" .actrc | cut -d "=" -f 2)
Expand All @@ -16,4 +21,4 @@ export MCLI_PUBLIC_API_KEY="${MCLI_PUBLIC_API_KEY:-$public_key}"
export MCLI_PRIVATE_API_KEY="${MCLI_PRIVATE_API_KEY:-$private_key}"
export MCLI_ORG_ID="${MCLI_ORG_ID:-$org_id}"

AKO_INT_TEST=1 ginkgo run --race --label-filter="${label}" --timeout 80m -v ./test/int ./test/int/clusterwide -coverprofile cover.out
AKO_INT_TEST=1 ginkgo run --race --label-filter="${label}" --timeout 80m -v ./test/${int_test_folder} -coverprofile cover.out
4 changes: 4 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var _ = BeforeSuite(func() {
GinkgoWriter.Write([]byte("========================End of Before==============================\n"))
})

var _ = ReportAfterSuite("Ensure test suite was not empty", func(r Report) {
Expect(r.PreRunStats.SpecsThatWillRun > 0).To(BeTrue(), "Suite must run at least 1 test")
})

// checkUpEnvironment initial check setup
func checkUpEnvironment() {
Expect(os.Getenv("MCLI_ORG_ID")).ShouldNot(BeEmpty(), "Please, setup MCLI_ORG_ID environment variable")
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/helm_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("HELM charts", Ordered, func() {
GinkgoWriter.Write([]byte("Operator namespace: " + data.Resources.Namespace + "\n"))
GinkgoWriter.Write([]byte("===============================================\n"))
if CurrentSpecReport().Failed() {
GinkgoWriter.Write([]byte("Resources wasn't clean"))
GinkgoWriter.Write([]byte("Resources wasn't clean\n"))
namespaceDeployment, err := k8s.GetDeployment("mongodb-atlas-operator", data.Resources.Namespace)
Expect(err).Should(BeNil())
namespaceDeploymentJSON, err := json.MarshalIndent(namespaceDeployment, "", " ")
Expand All @@ -62,15 +62,15 @@ var _ = Describe("HELM charts", Ordered, func() {

bytes, err := k8s.GetPodLogsByDeployment("mongodb-atlas-operator", config.DefaultOperatorNS, corev1.PodLogOptions{})
if err != nil {
GinkgoWriter.Write([]byte(err.Error()))
GinkgoWriter.Write([]byte(fmt.Sprintf("%v\n", err)))
}
utils.SaveToFile(
fmt.Sprintf("output/%s/operator-logs-default.txt", data.Resources.Namespace),
bytes,
)
bytes, err = k8s.GetPodLogsByDeployment("mongodb-atlas-operator", data.Resources.Namespace, corev1.PodLogOptions{})
if err != nil {
GinkgoWriter.Write([]byte(err.Error()))
GinkgoWriter.Write([]byte(fmt.Sprintf("%v\n", err)))
}
utils.SaveToFile(
fmt.Sprintf("output/%s/operator-logs.txt", data.Resources.Namespace),
Expand Down Expand Up @@ -236,7 +236,7 @@ var _ = Describe("HELM charts", Ordered, func() {
releaseMajorVersion := strings.Split(releasedVersion, ".")[0]
if releaseMajorVersion != devMajorVersion {
skipped = true
Skip(fmt.Sprintf("cannot test upgrade from incompatible major release version %s to version %s",
Skip(fmt.Sprintf("cannot test upgrade from incompatible major release version %q to version %q",
releaseMajorVersion, devMajorVersion))
}
})
Expand Down
46 changes: 32 additions & 14 deletions test/helper/e2e/actions/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,40 @@ func CheckUsersCanUseApp(data *model.TestDataProvider) {
func CheckUsersCanUseOldApp(data *model.TestDataProvider) {
input := data.Resources
for i, user := range data.Resources.Users {
// data
port := strconv.Itoa(i + data.PortGroup)
key := port
expectedData := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)

cli.Execute("kubectl", "delete", "pod", "-l", "app=test-app-"+user.Spec.Username, "-n", input.Namespace).Wait("2m")
WaitTestApplication(data, input.Namespace, "app", "test-app-"+user.Spec.Username)
By(fmt.Sprintf("Checking user %s (%d) can use old App", user.Spec.Username, i), func() {
// data
port := strconv.Itoa(i + data.PortGroup)
key := port
expectedData := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)

By("Deleting pod to force an app restart and wait for it", func() {
cli.Execute(
"kubectl", "delete", "pod", "-l", "app=test-app-"+user.Spec.Username, "-n", input.Namespace,
).Wait("2m")
WaitTestApplication(data, input.Namespace, "app", "test-app-"+user.Spec.Username)
})

app := appclient.NewTestAppClient(port)
ExpectWithOffset(1, app.Get("")).Should(Equal("It is working"))
ExpectWithOffset(1, app.Get("/mongo/"+key)).Should(Equal(expectedData))
app := appclient.NewTestAppClient(port)
By("Test restarted App access", func() {
getRoot := app.Get("")
GinkgoWriter.Write([]byte(fmt.Sprintf("Test App GET: %q\n", getRoot)))
ExpectWithOffset(1, getRoot).Should(Equal("It is working"))
getKey := app.Get("/mongo/" + key)
GinkgoWriter.Write([]byte(fmt.Sprintf("Test App GET /mongo/%s: %q\n", key, getKey)))
ExpectWithOffset(1, getKey).Should(Equal(expectedData))
})

key = port + "up"
dataUpdated := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)
ExpectWithOffset(1, app.Post(dataUpdated)).ShouldNot(HaveOccurred())
ExpectWithOffset(1, app.Get("/mongo/"+key)).Should(Equal(dataUpdated))
By("Test restarted App update", func() {
key = port + "up"
dataUpdated := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)
err := app.Post(dataUpdated)
GinkgoWriter.Write([]byte(fmt.Sprintf("Test App POST %v: %v\n", dataUpdated, err)))
ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
getKey := app.Get("/mongo/" + key)
GinkgoWriter.Write([]byte(fmt.Sprintf("Test App GET /mongo/%s: %q\n", key, getKey)))
ExpectWithOffset(1, getKey).Should(Equal(dataUpdated))
})
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/helper/e2e/appclient/test_app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (app *App) Get(endpoint string) string {
res, err := http.Get(app.uri + endpoint)
if err != nil {
fmt.Print(err)
return ""
return err.Error()
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
Expand Down
24 changes: 18 additions & 6 deletions test/helper/e2e/cli/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ func InstallOperatorNamespacedSubmodule(input model.UserInputs) {
func addPullSecret(installArgs []string, pullSecretPassword, namespace string) []string {
registry := os.Getenv("IMAGE_PULL_SECRET_REGISTRY")
pullSecretUsername := os.Getenv("IMAGE_PULL_SECRET_USERNAME")
secretName := fmt.Sprintf("ako-pull-secret-%s", registry)
secretName := pullSecretName(registry)
createPullSecret(secretName, namespace, registry, pullSecretUsername, pullSecretPassword)
return appendPullSecretArg(installArgs, secretName)
}

func pullSecretName(registry string) string {
return fmt.Sprintf("ako-pull-secret-%s", registry)
}

func appendPullSecretArg(installArgs []string, pullSecretName string) []string {
return append(installArgs,
"--set-string", fmt.Sprintf("imagePullSecrets[0].name=%s", secretName))
"--set-string", fmt.Sprintf("imagePullSecrets[0].name=%s", pullSecretName))
}

func createNamespace(namespace string) {
Expand Down Expand Up @@ -234,17 +242,21 @@ func InstallDeploymentRelease(input model.UserInputs) {
func UpgradeOperatorChart(input model.UserInputs) {
repo, tag := splitDockerImage()
packageChart(config.AtlasOperatorCRDHelmChartPath, filepath.Join(config.AtlasOperatorHelmChartPath, "charts"))
Upgrade(
"atlas-operator-"+input.Project.GetProjectName(),
upgradeArgs := []string{
"atlas-operator-" + input.Project.GetProjectName(),
config.AtlasOperatorHelmChartPath,
"--set-string", fmt.Sprintf("atlasURI=%s", config.AtlasHost),
"--set-string", fmt.Sprintf("image.repository=%s", repo),
"--set-string", fmt.Sprintf("image.tag=%s", tag),
"--set", "objectDeletionProtection=false",
"--set", "subobjectDeletionProtection=false",
"--atomic",
"-n", input.Namespace,
// "--wait", "--timeout", "5m", // TODO helm upgrade do not exit
)
}
registry := os.Getenv("IMAGE_PULL_SECRET_REGISTRY")
upgradeArgs = appendPullSecretArg(upgradeArgs, pullSecretName(registry))
Upgrade(upgradeArgs...)
}

func UpgradeAtlasDeploymentChartDev(input model.UserInputs) {
Expand Down Expand Up @@ -276,7 +288,7 @@ func GetDevelopmentMayorVersion() (string, error) {
if err != nil {
return "", err
}
return string(majorVersion), nil
return strings.TrimSpace(string(majorVersion)), nil
}

func packageChart(sPath, dPath string) {
Expand Down
4 changes: 4 additions & 0 deletions test/int/clusterwide/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ var _ = AfterSuite(func() {
Expect(err).ToNot(HaveOccurred())
})
})

var _ = ReportAfterSuite("Ensure test suite was not empty", func(r Report) {
Expect(r.PreRunStats.SpecsThatWillRun > 0).To(BeTrue(), "Suite must run at least 1 test")
})
4 changes: 4 additions & 0 deletions test/int/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ var _ = SynchronizedAfterSuite(func() {}, func() {
})
})

var _ = ReportAfterSuite("Ensure test suite was not empty", func(r Report) {
Expect(r.PreRunStats.SpecsThatWillRun > 0).To(BeTrue(), "Suite must run at least 1 test")
})

func defaultTimeouts() {
SetDefaultEventuallyTimeout(EventuallyTimeout)
SetDefaultEventuallyPollingInterval(PollingInterval)
Expand Down
Loading