-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain_test.go
103 lines (89 loc) · 2.45 KB
/
main_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
package main_test
import (
"encoding/json"
"os"
"os/exec"
"github.com/cloudfoundry/uptimer/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("uptimer", func() {
var (
cfg *config.Config
session *Session
)
BeforeEach(func() {
cfg = &config.Config{
While: []*config.Command{
{
Command: "sleep",
CommandArgs: []string{"5"},
},
},
CF: &config.Cf{
API: "api.my-cf.com",
AppDomain: "my-cf.com",
AdminUser: "admin",
AdminPassword: "pass",
},
AllowedFailures: config.AllowedFailures{
AppPushability: 2,
HttpAvailability: 5,
RecentLogs: 2,
StreamingLogs: 2,
},
}
})
JustBeforeEach(func() {
tmpDir := GinkgoT().TempDir()
f, err := os.Create(tmpDir + "/config.json")
Expect(err).NotTo(HaveOccurred())
defer f.Close()
b, err := json.Marshal(cfg)
Expect(err).NotTo(HaveOccurred())
_, err = f.Write(b)
Expect(err).NotTo(HaveOccurred())
cmd := exec.Command(uptimerPath, "-configFile", f.Name())
session, err = Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session, "10s").Should(Exit())
})
Context("when configured to test app syslog availability", func() {
BeforeEach(func() {
cfg.OptionalTests.RunAppSyslogAvailability = true
cfg.AllowedFailures.AppSyslogAvailability = 2
})
Context("when tcp_domain and available_port are not provided", func() {
BeforeEach(func() {
cfg.CF.AvailablePort = 0
cfg.CF.TCPDomain = ""
})
It("exits with a error code of 1", func() {
Expect(session.ExitCode()).To(Equal(1))
})
It("prints an error", func() {
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests."))
})
})
})
Context("when configured to test TCP availability", func() {
BeforeEach(func() {
cfg.OptionalTests.RunTcpAvailability = true
cfg.AllowedFailures.TCPAvailability = 2
})
Context("when tcp_domain and tcp_port are not provided", func() {
BeforeEach(func() {
cfg.CF.TCPDomain = ""
cfg.CF.TCPPort = 0
})
It("exits with a error code of 1", func() {
Expect(session.ExitCode()).To(Equal(1))
})
It("prints an error", func() {
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests."))
})
})
})
})