Skip to content

Commit 85e06a0

Browse files
authored
Fix in tests to check the runtime logs of cf (#357)
* add correct checking of runtime logs
1 parent 70daf92 commit 85e06a0

1 file changed

Lines changed: 42 additions & 47 deletions

File tree

src/nginx/integration/default_test.go

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package integration_test
22

33
import (
4-
"os/exec"
54
"path/filepath"
65
"testing"
76

@@ -25,6 +24,7 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
2524
var err error
2625
name, err = switchblade.RandomName()
2726
Expect(err).NotTo(HaveOccurred())
27+
println(name)
2828
})
2929

3030
it.After(func() {
@@ -44,12 +44,12 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
4444

4545
Eventually(deployment).Should(Serve(ContainSubstring(`{ "abcd": 12345 }{ 'ef' : "ab" }`)).WithEndpoint("test"))
4646

47-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
4847

49-
output, err := cmd.CombinedOutput()
50-
Expect(err).NotTo(HaveOccurred())
51-
52-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET /test HTTP/1.1" 200`))
48+
Eventually(func() string {
49+
logs, _ := deployment.RuntimeLogs()
50+
return logs
51+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET /test HTTP/1.1" 200`),
52+
))
5353
})
5454
})
5555

@@ -66,12 +66,11 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
6666

6767
Eventually(deployment).Should(Serve(ContainSubstring(`{ "abcd": 12345 }{ 'ef' : "ab" }`)).WithEndpoint("test"))
6868

69-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
70-
71-
output, err := cmd.CombinedOutput()
72-
Expect(err).NotTo(HaveOccurred())
73-
74-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET /test HTTP/1.1" 200`))
69+
Eventually(func() string {
70+
logs, _ := deployment.RuntimeLogs()
71+
return logs
72+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET /test HTTP/1.1" 200`),
73+
))
7574
})
7675
})
7776

@@ -83,12 +82,12 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
8382

8483
Eventually(deployment).Should(Serve(ContainSubstring("Exciting Content")))
8584

86-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
85+
Eventually(func() string {
86+
logs, _ := deployment.RuntimeLogs()
87+
return logs
88+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
89+
))
8790

88-
output, err := cmd.CombinedOutput()
89-
Expect(err).NotTo(HaveOccurred())
90-
91-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
9291
})
9392
})
9493

@@ -100,12 +99,12 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
10099

101100
Eventually(deployment).Should(Serve(ContainSubstring("Exciting Content")))
102101

103-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
104-
105-
output, err := cmd.CombinedOutput()
106-
Expect(err).NotTo(HaveOccurred())
102+
Eventually(func() string {
103+
logs, _ := deployment.RuntimeLogs()
104+
return logs
105+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
106+
))
107107

108-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
109108
})
110109
})
111110

@@ -120,12 +119,11 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
120119

121120
Eventually(deployment).Should(Serve(ContainSubstring("Exciting Content")))
122121

123-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
124-
125-
output, err := cmd.CombinedOutput()
126-
Expect(err).NotTo(HaveOccurred())
127-
128-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
122+
Eventually(func() string {
123+
logs, _ := deployment.RuntimeLogs()
124+
return logs
125+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
126+
))
129127
})
130128
})
131129

@@ -139,12 +137,11 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
139137

140138
Eventually(deployment).Should(Serve(ContainSubstring("Exciting Content")))
141139

142-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
143-
144-
output, err := cmd.CombinedOutput()
145-
Expect(err).NotTo(HaveOccurred())
146-
147-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
140+
Eventually(func() string {
141+
logs, _ := deployment.RuntimeLogs()
142+
return logs
143+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
144+
))
148145
})
149146
})
150147

@@ -158,13 +155,12 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
158155
Eventually(logs).Should(ContainSubstring(`Warning: usage of "stable" versions of NGINX is discouraged in most cases by the NGINX team.`))
159156

160157
Eventually(deployment).Should(Serve(ContainSubstring("Exciting Content")))
161-
162-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
163-
164-
output, err := cmd.CombinedOutput()
165-
Expect(err).NotTo(HaveOccurred())
166-
167-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
158+
159+
Eventually(func() string {
160+
logs, _ := deployment.RuntimeLogs()
161+
return logs
162+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
163+
))
168164
})
169165
})
170166

@@ -208,12 +204,11 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
208204

209205
Eventually(deployment).Should(Serve(ContainSubstring("<p>hello, world</p>")))
210206

211-
cmd := exec.Command("docker", "container", "logs", deployment.Name)
212-
213-
output, err := cmd.CombinedOutput()
214-
Expect(err).NotTo(HaveOccurred())
215-
216-
Expect(string(output)).To(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`))
207+
Eventually(func() string {
208+
logs, _ := deployment.RuntimeLogs()
209+
return logs
210+
}, "10s", "1s").Should(Or(ContainSubstring(`NginxLog "GET / HTTP/1.1" 200`),
211+
))
217212
})
218213
})
219214
}

0 commit comments

Comments
 (0)