Skip to content

Commit

Permalink
Run smoke tests in parallel
Browse files Browse the repository at this point in the history
Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
  • Loading branch information
danail-branekov and georgethebeatle committed Oct 29, 2024
1 parent 3d6a043 commit 56b15ef
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 89 deletions.
1 change: 0 additions & 1 deletion scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/processes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("Processes", func() {
})
})

Describe("List sidecars", Ordered, func() {
Describe("List sidecars", func() {
var list resourceList[resource]

JustBeforeEach(func() {
Expand Down
6 changes: 3 additions & 3 deletions tests/smoke/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")),
))
Expand Down
35 changes: 6 additions & 29 deletions tests/smoke/bind_service_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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))
})
})

Expand All @@ -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))
})
})
})
4 changes: 2 additions & 2 deletions tests/smoke/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

Expand All @@ -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)))))
})
})

Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/run_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})
2 changes: 1 addition & 1 deletion tests/smoke/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

Expand Down
109 changes: 60 additions & 49 deletions tests/smoke/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package smoke_test
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"strings"
Expand All @@ -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",
Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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())
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 56b15ef

Please sign in to comment.