forked from cloudfoundry/cf-networking-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke_suite_test.go
110 lines (90 loc) · 2.66 KB
/
smoke_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
package smoke_test
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
helpersConfig "github.com/cloudfoundry/cf-test-helpers/v2/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
const Timeout_Push = 5 * time.Minute
var (
appsDir string
config SmokeConfig
)
type SmokeConfig struct {
ApiEndpoint string `json:"api"`
AppsDomain string `json:"apps_domain"`
SmokeUser string `json:"smoke_user"`
SmokePassword string `json:"smoke_password"`
AppInstances int `json:"app_instances"`
Prefix string `json:"prefix"`
SmokeOrg string `json:"smoke_org"`
}
func Auth(username, password string) {
By("authenticating as " + username)
cmd := exec.Command("cf", "auth", username, password)
sess, err := gexec.Start(cmd, nil, nil)
Expect(err).NotTo(HaveOccurred())
Eventually(sess.Wait(Timeout_Short)).Should(gexec.Exit(0))
}
func TestSmoke(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
configPath := helpersConfig.ConfigPath()
configBytes, err := os.ReadFile(configPath)
Expect(err).NotTo(HaveOccurred())
err = json.Unmarshal(configBytes, &config)
Expect(err).NotTo(HaveOccurred())
if config.AppInstances <= 0 {
Fail("AppInstances count needs to be greater than 0")
}
Expect(cf.Cf("api", "--skip-ssl-validation", config.ApiEndpoint).Wait(Timeout_Short)).To(gexec.Exit(0))
Auth(config.SmokeUser, config.SmokePassword)
appsDir = os.Getenv("APPS_DIR")
Expect(appsDir).NotTo(BeEmpty())
})
RunSpecs(t, "Smoke Suite")
}
func appReport(appName string, timeout time.Duration) {
By(fmt.Sprintf("reporting app %s", appName))
Eventually(cf.Cf("app", appName, "--guid"), timeout).Should(gexec.Exit())
Eventually(cf.Cf("logs", appName, "--recent"), timeout).Should(gexec.Exit())
}
func appDir(appType string) string {
return filepath.Join(appsDir, appType)
}
func defaultManifest(appType string) string {
return filepath.Join(appDir(appType), "manifest.yml")
}
func pushApp(appName, kind string, extraArgs ...string) {
args := append([]string{
"push", appName,
"-p", appDir(kind),
"-f", defaultManifest(kind),
}, extraArgs...)
Expect(cf.Cf(args...).Wait(Timeout_Push)).To(gexec.Exit(0))
}
func scaleApp(appName string, instances int) {
Expect(cf.Cf(
"scale", appName,
"-i", fmt.Sprintf("%d", instances),
).Wait(Timeout_Short)).To(gexec.Exit(0))
}
func setEnv(appName, envVar, value string) {
Expect(cf.Cf(
"set-env", appName,
envVar, value,
).Wait(Timeout_Short)).To(gexec.Exit(0))
}
func start(appName string) {
Expect(cf.Cf(
"start", appName,
).Wait(Timeout_Push)).To(gexec.Exit(0))
}