-
Notifications
You must be signed in to change notification settings - Fork 6
/
bara_suite_test.go
125 lines (99 loc) · 3.94 KB
/
bara_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package bara_test
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/cloudfoundry/cf-test-helpers/v2/workflowhelpers"
. "github.com/cloudfoundry/capi-bara-tests/bara_suite_helpers"
"github.com/cloudfoundry/capi-bara-tests/helpers/assets"
_ "github.com/cloudfoundry/capi-bara-tests/baras"
. "github.com/cloudfoundry/capi-bara-tests/helpers/cli_version_check"
"github.com/cloudfoundry/capi-bara-tests/helpers/config"
"github.com/cloudfoundry/cf-test-helpers/v2/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
const minCliVersion = "6.33.1"
func TestBARA(t *testing.T) {
RegisterFailHandler(Fail)
var validationError error
Config, validationError = config.NewBaraConfig(os.Getenv("CONFIG"))
if validationError != nil {
defer GinkgoRecover()
fmt.Println("Invalid configuration. ")
fmt.Println(validationError)
fmt.Println("Please fix the contents of $CONFIG:\n " + os.Getenv("CONFIG") + "\nbefore proceeding.")
t.FailNow()
}
var _ = SynchronizedBeforeSuite(func() []byte {
installedVersion, err := GetInstalledCliVersionString()
Expect(err).ToNot(HaveOccurred(), "Error trying to determine CF CLI version")
fmt.Println("Running BARAs with CF CLI version ", installedVersion)
Expect(ParseRawCliVersionString(installedVersion).AtLeast(ParseRawCliVersionString(minCliVersion))).To(BeTrue(), "CLI version "+minCliVersion+" is required")
buildCmd := exec.Command("go", "build", "-o", "bin/catnip")
buildCmd.Dir = "assets/catnip"
buildCmd.Env = append(os.Environ(),
"GOOS=linux",
"GOARCH=amd64",
)
buildCmd.Stdout = GinkgoWriter
buildCmd.Stderr = GinkgoWriter
session, err := gexec.Start(buildCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session, 30*time.Second).Should(gexec.Exit(0))
buildCmd = exec.Command("go", "build", "-o", "../sidecar-dependent/sidecar")
buildCmd.Dir = "assets/sidecar"
buildCmd.Env = append(os.Environ(),
"GOOS=linux",
"GOARCH=amd64",
)
session, err = gexec.Start(buildCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session, 30*time.Second).Should(gexec.Exit(0))
assetPaths := assets.NewAssets()
ZipAsset(assetPaths.Dora, assetPaths.DoraZip)
ZipAsset(assetPaths.BadDora, assetPaths.BadDoraZip)
ZipAsset(assetPaths.Staticfile, assetPaths.StaticfileZip)
ZipAsset(assetPaths.Catnip, assetPaths.CatnipZip)
ZipAsset(assetPaths.PythonWithoutProcfile, assetPaths.PythonWithoutProcfileZip)
ZipAsset(assetPaths.SleepySidecarBuildpack, assetPaths.SleepySidecarBuildpackZip)
if Config.GetGcloudProjectName() != "" {
gcloudCommand := exec.Command("gcloud", "container", "clusters", "get-credentials", Config.GetClusterName(), "--project", Config.GetGcloudProjectName(), "--zone", Config.GetClusterZone())
session, err = gexec.Start(gcloudCommand, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session, 30*time.Second).Should(gexec.Exit(0))
}
return []byte{}
}, func([]byte) {})
BeforeEach(func() {
SetDefaultEventuallyTimeout(Config.DefaultTimeoutDuration())
SetDefaultEventuallyPollingInterval(1 * time.Second)
TestSetup = workflowhelpers.NewTestSuiteSetup(Config)
TestSetup.Setup()
})
AfterEach(func() {
if TestSetup != nil {
TestSetup.Teardown()
}
})
SynchronizedAfterSuite(func() {}, func() {
os.Remove(assets.NewAssets().DoraZip)
os.Remove(assets.NewAssets().BadDoraZip)
os.Remove(assets.NewAssets().StaticfileZip)
os.Remove(assets.NewAssets().CatnipZip)
os.Remove(assets.NewAssets().PythonWithoutProcfileZip)
os.Remove(assets.NewAssets().SleepySidecarBuildpackZip)
})
_, rc := GinkgoConfiguration()
if validationError == nil {
if Config.GetArtifactsDirectory() != "" {
helpers.EnableCFTrace(Config, "BARA")
rc.JUnitReport = filepath.Join(Config.GetArtifactsDirectory(), fmt.Sprintf("junit-%s-%d.xml", "BARA", GinkgoParallelProcess()))
}
}
RunSpecs(t, "BARA", rc)
}