Skip to content

Commit

Permalink
Refactored the logs tests in hoverctl functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjih committed Jul 20, 2016
1 parent 3a77130 commit 528b6e0
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions functional-tests/hoverctl/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,41 @@ var _ = Describe("When I use hoverctl", func() {
proxyPort = strconv.Itoa(freeport.GetPort())
)

Context("I can get the logs using the log command", func() {
BeforeEach(func() {
WriteConfiguration("localhost", adminPort, proxyPort)
})

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

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

It("should return the logs", func() {
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()

out, _ := exec.Command(hoverctlBinary, "logs", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()

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

It("should return an error if the logs don't exist", func() {
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()

out, _ := exec.Command(hoverctlBinary, "logs", "--admin-port=hotdogs", "--proxy-port=burgers").Output()

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

Describe("and start Hoverfly using hoverctl", func() {
Context("and start Hoverfly using hoverctl", func() {

Context("the logs get captured in a .log file", func() {
BeforeEach(func() {
It("and I can see it has started", func() {
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
WriteConfiguration("localhost", adminPort, proxyPort)
})

AfterEach(func() {
exec.Command(hoverctlBinary, "stop", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()
})

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

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

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

adminPortAsString, _ := strconv.Atoi(adminPort)

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

It("and the stderr is captured in the log file", func() {
exec.Command(hoverctlBinary, "start", "--admin-port=" + adminPort, "--proxy-port=" + proxyPort).Output()

req := sling.New().Post(fmt.Sprintf("http://localhost:%v/api/state", adminPort)).Body(strings.NewReader(`{"mode":"not-a-mode"}`))
DoRequest(req)

Expand Down

0 comments on commit 528b6e0

Please sign in to comment.