diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index b1129ea1b..a753dc904 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -36,7 +36,6 @@ function configure_crd_tests() { function configure_smoke_tests() { export API_SERVER_ROOT="${API_SERVER_ROOT:-https://localhost}" export APP_FQDN="${APP_FQDN:-apps-127-0-0-1.nip.io}" - export NO_PARALLEL=true deploy_korifi } diff --git a/tests/e2e/processes_test.go b/tests/e2e/processes_test.go index 2e51dd012..f13672d85 100644 --- a/tests/e2e/processes_test.go +++ b/tests/e2e/processes_test.go @@ -51,7 +51,7 @@ var _ = Describe("Processes", func() { }) }) - Describe("List sidecars", Ordered, func() { + Describe("List sidecars", func() { var list resourceList[resource] JustBeforeEach(func() { diff --git a/tests/smoke/apps_test.go b/tests/smoke/apps_test.go index a2d11709e..f4d088ef7 100644 --- a/tests/smoke/apps_test.go +++ b/tests/smoke/apps_test.go @@ -9,21 +9,21 @@ import ( var _ = Describe("apps", func() { It("buildpack app is reachable via its route", func() { - appResponseShould(buildpackAppName, "/", SatisfyAll( + appResponseShould(sharedData.BuildpackAppName, "/", SatisfyAll( HaveHTTPStatus(http.StatusOK), HaveHTTPBody(ContainSubstring("Hi, I'm Dorifi!")), )) }) It("docker app is reachable via its route", func() { - appResponseShould(dockerAppName, "/", SatisfyAll( + appResponseShould(sharedData.DockerAppName, "/", SatisfyAll( HaveHTTPStatus(http.StatusOK), HaveHTTPBody(ContainSubstring("Hi, I'm not Dora!")), )) }) It("broker app is reachable via its route", func() { - appResponseShould(brokerAppName, "/", SatisfyAll( + appResponseShould(sharedData.BrokerAppName, "/", SatisfyAll( HaveHTTPStatus(http.StatusOK), HaveHTTPBody(ContainSubstring("Hi, I'm the sample broker!")), )) diff --git a/tests/smoke/bind_service_test.go b/tests/smoke/bind_service_test.go index 2c3121320..894f02f29 100644 --- a/tests/smoke/bind_service_test.go +++ b/tests/smoke/bind_service_test.go @@ -1,10 +1,7 @@ package smoke_test import ( - "net/http" - "code.cloudfoundry.org/korifi/tests/helpers" - . "code.cloudfoundry.org/korifi/tests/matchers" "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" @@ -14,41 +11,27 @@ import ( var _ = Describe("cf bind-service", func() { var ( - appName string serviceName string + bindSession *Session ) BeforeEach(func() { - // Binding apps to service instances changes their VCAP_SERVICES to - // reflect all the app bindings. Therefore, bind tests need dedicated - // test app (i.e. cannot use one created by the suite) - appName = uuid.NewString() - Expect(helpers.Cf("push", appName, "-p", "../assets/dorifi")).To(Exit(0)) + serviceName = uuid.NewString() }) JustBeforeEach(func() { - Expect(helpers.Cf("bind-service", appName, serviceName)).To(Exit(0)) - Expect(helpers.Cf("restart", appName)).To(Exit(0)) + bindSession = helpers.Cf("bind-service", sharedData.BuildpackAppName, serviceName) }) Describe("Binding to user-provided service instances", func() { BeforeEach(func() { - serviceName = uuid.NewString() Expect( helpers.Cf("create-user-provided-service", serviceName, "-p", `{"key1":"value1","key2":"value2"}`), ).To(Exit(0)) }) It("binds the service to the app", func() { - appResponseShould(appName, "/env.json", SatisfyAll( - HaveHTTPStatus(http.StatusOK), - HaveHTTPBody( - MatchJSONPath("$.VCAP_SERVICES", SatisfyAll( - MatchJSONPath(`$["user-provided"][0].credentials.key1`, "value1"), - MatchJSONPath(`$["user-provided"][0].credentials.key2`, "value2"), - )), - ), - )) + Expect(bindSession).To(Exit(0)) }) }) @@ -60,21 +43,15 @@ var _ = Describe("cf bind-service", func() { brokerName, "broker-user", "broker-password", - helpers.GetInClusterURL(getAppGUID(brokerAppName)), + helpers.GetInClusterURL(getAppGUID(sharedData.BrokerAppName)), )).To(Exit(0)) - serviceName = uuid.NewString() session := helpers.Cf("create-service", "sample-service", "sample", serviceName, "-b", brokerName) Expect(session).To(Exit(0)) }) It("binds the service to the app", func() { - appResponseShould(appName, "/env.json", SatisfyAll( - HaveHTTPStatus(http.StatusOK), - HaveHTTPBody( - MatchJSONPath("$.VCAP_SERVICES", Not(BeEmpty())), - ), - )) + Expect(bindSession).To(Exit(0)) }) }) }) diff --git a/tests/smoke/catalog_test.go b/tests/smoke/catalog_test.go index 2c46e8776..de8091a1f 100644 --- a/tests/smoke/catalog_test.go +++ b/tests/smoke/catalog_test.go @@ -20,7 +20,7 @@ var _ = Describe("Service Catalog", func() { brokerName, "broker-user", "broker-password", - helpers.GetInClusterURL(getAppGUID(brokerAppName)), + helpers.GetInClusterURL(getAppGUID(sharedData.BrokerAppName)), )).To(Exit(0)) }) @@ -35,7 +35,7 @@ var _ = Describe("Service Catalog", func() { lines := it.MustCollect(it.LinesString(session.Out)) Expect(lines).To(ContainElement( - matchSubstrings(brokerName, helpers.GetInClusterURL(getAppGUID(brokerAppName))))) + matchSubstrings(brokerName, helpers.GetInClusterURL(getAppGUID(sharedData.BrokerAppName))))) }) }) diff --git a/tests/smoke/logs_test.go b/tests/smoke/logs_test.go index 26ed6fa11..8b67a31b2 100644 --- a/tests/smoke/logs_test.go +++ b/tests/smoke/logs_test.go @@ -14,13 +14,13 @@ import ( var _ = Describe("cf logs", func() { Describe("cf logs --recent", func() { It("prints app recent logs", func() { - Eventually(helpers.Cf("logs", buildpackAppName, "--recent")).Should(gbytes.Say("Listening on port 8080")) + Eventually(helpers.Cf("logs", sharedData.BuildpackAppName, "--recent")).Should(gbytes.Say("Listening on port 8080")) }) }) Describe("cf logs", func() { It("blocks waiting for new log entries", func() { - logsSession := cf.Cf("logs", buildpackAppName) + logsSession := cf.Cf("logs", sharedData.BuildpackAppName) defer logsSession.Signal(syscall.SIGTERM) Eventually(logsSession).Should(gbytes.Say("Listening on port 8080")) diff --git a/tests/smoke/run_task_test.go b/tests/smoke/run_task_test.go index 361238365..cbc9edaa2 100644 --- a/tests/smoke/run_task_test.go +++ b/tests/smoke/run_task_test.go @@ -10,6 +10,6 @@ import ( var _ = Describe("cf run-task", func() { It("succeeds", func() { - Eventually(helpers.Cf("run-task", buildpackAppName, "-c", `echo "Hello from the task"`)).Should(Exit(0)) + Eventually(helpers.Cf("run-task", sharedData.BuildpackAppName, "-c", `echo "Hello from the task"`)).Should(Exit(0)) }) }) diff --git a/tests/smoke/services_test.go b/tests/smoke/services_test.go index 366375635..cb940d8d1 100644 --- a/tests/smoke/services_test.go +++ b/tests/smoke/services_test.go @@ -20,7 +20,7 @@ var _ = Describe("Services", func() { brokerName, "broker-user", "broker-password", - helpers.GetInClusterURL(getAppGUID(brokerAppName)), + helpers.GetInClusterURL(getAppGUID(sharedData.BrokerAppName)), )).To(Exit(0)) }) diff --git a/tests/smoke/suite_test.go b/tests/smoke/suite_test.go index 050a8eb40..adb62684e 100644 --- a/tests/smoke/suite_test.go +++ b/tests/smoke/suite_test.go @@ -3,6 +3,7 @@ package smoke_test import ( "context" "crypto/tls" + "encoding/json" "fmt" "net/http" "strings" @@ -28,17 +29,18 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" ) -var ( - appsDomain string - buildpackAppName string - cfAdmin string - dockerAppName string - brokerAppName string - orgName string - rootNamespace string - serviceAccountFactory *helpers.ServiceAccountFactory - spaceName string -) +type SmokeTestSharedData struct { + CfAdmin string `json:"cf_admin"` + RootNamespace string `json:"root_namespace"` + OrgName string `json:"org_name"` + SpaceName string `json:"space_name"` + AppsDomain string `json:"apps_domain"` + BuildpackAppName string `json:"buildpack_app_name"` + DockerAppName string `json:"docker_app_name"` + BrokerAppName string `json:"broker_app_name"` +} + +var sharedData SmokeTestSharedData func TestSmoke(t *testing.T) { RegisterFailHandler(fail_handler.New("CF CLI Tests", @@ -47,7 +49,7 @@ func TestSmoke(t *testing.T) { Hook: func(config *rest.Config, failure fail_handler.TestFailure) { printCfApp(config) fail_handler.PrintKorifiLogs(config, "", failure.StartTime) - printBuildLogs(config, spaceName) + printBuildLogs(config, sharedData.SpaceName) }, }).Fail) @@ -56,42 +58,51 @@ func TestSmoke(t *testing.T) { RunSpecs(t, "CF CLI Tests Suite") } -var _ = BeforeSuite(func() { - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - Expect(korifiv1alpha1.AddToScheme(scheme.Scheme)).To(Succeed()) - - rootNamespace = helpers.GetDefaultedEnvVar("ROOT_NAMESPACE", "cf") - serviceAccountFactory = helpers.NewServiceAccountFactory(rootNamespace) +var _ = SynchronizedBeforeSuite(func() []byte { + data := SmokeTestSharedData{ + CfAdmin: uuid.NewString(), + RootNamespace: helpers.GetDefaultedEnvVar("ROOT_NAMESPACE", "cf"), + OrgName: uuid.NewString(), + SpaceName: uuid.NewString(), + AppsDomain: helpers.GetRequiredEnvVar("APP_FQDN"), + BuildpackAppName: uuid.NewString(), + DockerAppName: uuid.NewString(), + BrokerAppName: uuid.NewString(), + } + serviceAccountFactory := helpers.NewServiceAccountFactory(data.RootNamespace) - cfAdmin = uuid.NewString() - cfAdminToken := serviceAccountFactory.CreateAdminServiceAccount(cfAdmin) - helpers.AddUserToKubeConfig(cfAdmin, cfAdminToken) + cfAdminToken := serviceAccountFactory.CreateAdminServiceAccount(data.CfAdmin) + helpers.AddUserToKubeConfig(data.CfAdmin, cfAdminToken) Expect(helpers.Cf("api", helpers.GetRequiredEnvVar("API_SERVER_ROOT"), "--skip-ssl-validation")).To(Exit(0)) - Expect(helpers.Cf("auth", cfAdmin)).To(Exit(0)) - - appsDomain = helpers.GetRequiredEnvVar("APP_FQDN") - orgName = uuid.NewString() - spaceName = uuid.NewString() - buildpackAppName = uuid.NewString() - dockerAppName = uuid.NewString() - brokerAppName = uuid.NewString() - - Expect(helpers.Cf("create-org", orgName)).To(Exit(0)) - Expect(helpers.Cf("create-space", "-o", orgName, spaceName)).To(Exit(0)) - Expect(helpers.Cf("target", "-o", orgName, "-s", spaceName)).To(Exit(0)) - - Expect(helpers.Cf("push", buildpackAppName, "-p", "../assets/dorifi")).To(Exit(0)) - Expect(helpers.Cf("push", brokerAppName, "-p", "../assets/sample-broker")).To(Exit(0)) - Expect(helpers.Cf("push", dockerAppName, "-o", "eirini/dorini")).To(Exit(0)) + Expect(helpers.Cf("auth", data.CfAdmin)).To(Exit(0)) + + Expect(helpers.Cf("create-org", data.OrgName)).To(Exit(0)) + Expect(helpers.Cf("create-space", "-o", data.OrgName, data.SpaceName)).To(Exit(0)) + Expect(helpers.Cf("target", "-o", data.OrgName, "-s", data.SpaceName)).To(Exit(0)) + + Expect(helpers.Cf("push", data.BuildpackAppName, "-p", "../assets/dorifi")).To(Exit(0)) + Expect(helpers.Cf("push", data.BrokerAppName, "-p", "../assets/sample-broker")).To(Exit(0)) + Expect(helpers.Cf("push", data.DockerAppName, "-o", "eirini/dorini")).To(Exit(0)) + + sharedDataBytes, err := json.Marshal(data) + Expect(err).NotTo(HaveOccurred()) + return sharedDataBytes +}, func(sharedDataBytes []byte) { + sharedData = SmokeTestSharedData{} + Expect(json.Unmarshal(sharedDataBytes, &sharedData)).To(Succeed()) + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + Expect(korifiv1alpha1.AddToScheme(scheme.Scheme)).To(Succeed()) }) -var _ = AfterSuite(func() { - Expect(helpers.Cf("delete-org", orgName, "-f").Wait()).To(Exit()) +var _ = SynchronizedAfterSuite(func() { +}, func() { + Expect(helpers.Cf("delete-org", sharedData.OrgName, "-f").Wait()).To(Exit()) + serviceAccountFactory := helpers.NewServiceAccountFactory(sharedData.RootNamespace) - serviceAccountFactory.DeleteServiceAccount(cfAdmin) - helpers.RemoveUserFromKubeConfig(cfAdmin) + serviceAccountFactory.DeleteServiceAccount(sharedData.CfAdmin) + helpers.RemoveUserFromKubeConfig(sharedData.CfAdmin) }) func sessionOutput(session *Session) (string, error) { @@ -114,7 +125,7 @@ func appResponseShould(appName, requestPath string, matchExpectations types.Gome } Eventually(func(g Gomega) { - resp, err := httpClient.Get(fmt.Sprintf("https://%s.%s%s", appName, appsDomain, requestPath)) + resp, err := httpClient.Get(fmt.Sprintf("https://%s.%s%s", appName, sharedData.AppsDomain, requestPath)) g.Expect(err).NotTo(HaveOccurred()) g.Expect(resp).To(matchExpectations) }).Should(Succeed()) @@ -128,14 +139,14 @@ func printCfApp(config *rest.Config) { return } - cfAppNamespace, err := sessionOutput(helpers.Cf("space", spaceName, "--guid")) + cfAppNamespace, err := sessionOutput(helpers.Cf("space", sharedData.SpaceName, "--guid")) if err != nil { - fmt.Fprintf(GinkgoWriter, "failed to run 'cf space %s --guid': %v\n", spaceName, err) + fmt.Fprintf(GinkgoWriter, "failed to run 'cf space %s --guid': %v\n", sharedData.SpaceName, err) return } - cfAppGUID, err := sessionOutput(helpers.Cf("app", buildpackAppName, "--guid")) + cfAppGUID, err := sessionOutput(helpers.Cf("app", sharedData.BuildpackAppName, "--guid")) if err != nil { - fmt.Fprintf(GinkgoWriter, "failed to run 'cf app %s --guid': %v\n", buildpackAppName, err) + fmt.Fprintf(GinkgoWriter, "failed to run 'cf app %s --guid': %v\n", sharedData.BuildpackAppName, err) return } @@ -166,7 +177,7 @@ func printObject(k8sClient client.Client, obj client.Object) error { } func printBuildLogs(config *rest.Config, spaceName string) { - spaceGUID, err := sessionOutput(helpers.Cf("space", spaceName, "--guid").Wait()) + spaceGUID, err := sessionOutput(helpers.Cf("space", sharedData.SpaceName, "--guid").Wait()) if err != nil { fmt.Fprintf(GinkgoWriter, "failed to get space guid: %v\n", err) return @@ -186,7 +197,7 @@ func cleanupBroker(brokerName string) { GinkgoHelper() Expect(helpers.Cf("delete-service-broker", "-f", brokerName)).To(Exit(0)) - broker.NewCatalogPurger(rootNamespace).ForBrokerName(brokerName).Purge() + broker.NewCatalogPurger(sharedData.RootNamespace).ForBrokerName(brokerName).Purge() } func matchSubstrings(substrings ...string) types.GomegaMatcher {