Skip to content

Commit

Permalink
Split the monolithic smoke test into smaller ones
Browse files Browse the repository at this point in the history
  • Loading branch information
danail-branekov authored and georgethebeatle committed Aug 29, 2024
1 parent b89a55f commit 873f63a
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 111 deletions.
47 changes: 47 additions & 0 deletions tests/smoke/apps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package smoke_test

import (
"crypto/tls"
"fmt"
"net/http"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
)

var _ = Describe("apps", func() {
It("buildpack app is reachable via its route", func() {
appResponseShould(buildpackAppName, "/", SatisfyAll(
HaveHTTPStatus(http.StatusOK),
HaveHTTPBody(ContainSubstring("Hi, I'm Dorifi!")),
))
})

It("docker app is reachable via its route", func() {
appResponseShould(dockerAppName, "/", SatisfyAll(
HaveHTTPStatus(http.StatusOK),
HaveHTTPBody(ContainSubstring("Hi, I'm not Dora!")),
))
})

It("broker app is reachable via its route", func() {
appResponseShould(brokerAppName, "/", SatisfyAll(
HaveHTTPStatus(http.StatusOK),
HaveHTTPBody(ContainSubstring("Hi, I'm the sample broker!")),
))
})
})

func appResponseShould(appName, requestPath string, matchExpectations types.GomegaMatcher) {
var httpClient http.Client
httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

Eventually(func(g Gomega) {
resp, err := httpClient.Get(fmt.Sprintf("https://%s.%s%s", appName, appsDomain, requestPath))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(resp).To(matchExpectations)
}).Should(Succeed())
}
38 changes: 38 additions & 0 deletions tests/smoke/bind_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("cf bind-service", func() {
BeforeEach(func() {
serviceName := uuid.NewString()

Expect(
helpers.Cf("create-user-provided-service", serviceName, "-p", `{"key1":"value1","key2":"value2"}`),
).To(Exit(0))

Expect(helpers.Cf("bind-service", buildpackAppName, serviceName)).To(Exit(0))
Expect(helpers.Cf("restart", buildpackAppName)).To(Exit(0))
})

It("binds the service to the app", func() {
appResponseShould(buildpackAppName, "/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"),
)),
),
))
})
})
35 changes: 35 additions & 0 deletions tests/smoke/logs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package smoke_test

import (
"syscall"

"code.cloudfoundry.org/korifi/tests/helpers"
"github.com/cloudfoundry/cf-test-helpers/cf"
"github.com/onsi/gomega/gbytes"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

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"))
})
})

Describe("cf logs", func() {
It("blocks waiting for new log entries", func() {
logsSession := cf.Cf("logs", buildpackAppName)
defer logsSession.Signal(syscall.SIGQUIT)

Eventually(logsSession).Should(gbytes.Say("Listening on port 8080"))
outputLen := len(string(logsSession.Out.Contents()))

Consistently(func(g Gomega) {
Expect(logsSession.ExitCode()).To(Equal(-1))
Expect(string(logsSession.Out.Contents())).To(HaveLen(outputLen))
}).Should(Succeed())
})
})
})
15 changes: 15 additions & 0 deletions tests/smoke/run_task_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package smoke_test

import (
"code.cloudfoundry.org/korifi/tests/helpers"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("cf run-task", func() {
It("succeeds", func() {
Eventually(helpers.Cf("run-task", buildpackAppName, "-c", `echo "Hello from the task"`)).Should(Exit(0))
})
})
102 changes: 0 additions & 102 deletions tests/smoke/smoke_test.go

This file was deleted.

18 changes: 9 additions & 9 deletions tests/smoke/smoke_suite_test.go → tests/smoke/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"code.cloudfoundry.org/korifi/tests/helpers"
"code.cloudfoundry.org/korifi/tests/helpers/fail_handler"

"github.com/cloudfoundry/cf-test-helpers/generator"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -25,21 +24,20 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

const NamePrefix = "cf-on-k8s-smoke"

var (
appsDomain string
buildpackAppName string
cfAdmin string
dockerAppName string
brokerAppName string
orgName string
rootNamespace string
serviceAccountFactory *helpers.ServiceAccountFactory
spaceName string
)

func TestSmoke(t *testing.T) {
RegisterFailHandler(fail_handler.New("Smoke Tests",
RegisterFailHandler(fail_handler.New("CF CLI Tests",
fail_handler.Hook{
Matcher: fail_handler.Always,
Hook: func(config *rest.Config, failure fail_handler.TestFailure) {
Expand All @@ -51,7 +49,7 @@ func TestSmoke(t *testing.T) {

SetDefaultEventuallyTimeout(helpers.EventuallyTimeout())
SetDefaultEventuallyPollingInterval(helpers.EventuallyPollingInterval())
RunSpecs(t, "Smoke Tests Suite")
RunSpecs(t, "CF CLI Tests Suite")
}

var _ = BeforeSuite(func() {
Expand All @@ -68,16 +66,18 @@ var _ = BeforeSuite(func() {
Expect(helpers.Cf("auth", cfAdmin)).To(Exit(0))

appsDomain = helpers.GetRequiredEnvVar("APP_FQDN")
orgName = generator.PrefixedRandomName(NamePrefix, "org")
spaceName = generator.PrefixedRandomName(NamePrefix, "space")
buildpackAppName = generator.PrefixedRandomName(NamePrefix, "buildpackapp")
dockerAppName = generator.PrefixedRandomName(NamePrefix, "dockerapp")
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))
})

Expand Down

0 comments on commit 873f63a

Please sign in to comment.