Skip to content

Commit 528b6e0

Browse files
committed
Refactored the logs tests in hoverctl functional tests
1 parent 3a77130 commit 528b6e0

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

functional-tests/hoverctl/logs_test.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,41 @@ var _ = Describe("When I use hoverctl", func() {
2020
proxyPort = strconv.Itoa(freeport.GetPort())
2121
)
2222

23-
Context("I can get the logs using the log command", func() {
23+
BeforeEach(func() {
24+
WriteConfiguration("localhost", adminPort, proxyPort)
25+
})
2426

25-
BeforeEach(func() {
26-
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
27-
WriteConfiguration("localhost", adminPort, proxyPort)
28-
})
27+
AfterEach(func() {
28+
exec.Command(hoverctlBinary, "stop", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
29+
})
2930

30-
AfterEach(func() {
31-
exec.Command(hoverctlBinary, "stop", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
32-
})
31+
Context("I can get the logs using the log command", func() {
3332

3433
It("should return the logs", func() {
34+
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
35+
3536
out, _ := exec.Command(hoverctlBinary, "logs", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
3637

3738
output := strings.TrimSpace(string(out))
3839
Expect(output).To(ContainSubstring("listening on :" + adminPort))
3940
})
4041

4142
It("should return an error if the logs don't exist", func() {
43+
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
44+
4245
out, _ := exec.Command(hoverctlBinary, "logs", "--admin-port=hotdogs", "--proxy-port=burgers").Output()
4346

4447
output := strings.TrimSpace(string(out))
4548
Expect(output).To(ContainSubstring("Could not open Hoverfly log file"))
4649
})
4750
})
4851

49-
Describe("and start Hoverfly using hoverctl", func() {
52+
Context("and start Hoverfly using hoverctl", func() {
5053

5154
Context("the logs get captured in a .log file", func() {
52-
BeforeEach(func() {
55+
It("and I can see it has started", func() {
5356
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
54-
WriteConfiguration("localhost", adminPort, proxyPort)
55-
})
56-
57-
AfterEach(func() {
58-
exec.Command(hoverctlBinary, "stop", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
59-
})
6057

61-
It("and I can see it has started", func() {
6258
workingDir, _ := os.Getwd()
6359
filePath := filepath.Join(workingDir, ".hoverfly/", "hoverfly." + adminPort + "." + proxyPort +".log")
6460

@@ -69,6 +65,7 @@ var _ = Describe("When I use hoverctl", func() {
6965
})
7066

7167
It("and they get updated when you use hoverfly", func() {
68+
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
7269

7370
adminPortAsString, _ := strconv.Atoi(adminPort)
7471

@@ -85,6 +82,8 @@ var _ = Describe("When I use hoverctl", func() {
8582
})
8683

8784
It("and the stderr is captured in the log file", func() {
85+
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
86+
8887
req := sling.New().Post(fmt.Sprintf("http://localhost:%v/api/state", adminPort)).Body(strings.NewReader(`{"mode":"not-a-mode"}`))
8988
DoRequest(req)
9089

0 commit comments

Comments
 (0)