Skip to content

Commit c5ea1b4

Browse files
authored
Merge refactor pull request
2 parents f99387c + e5cb92d commit c5ea1b4

File tree

5 files changed

+134
-42
lines changed

5 files changed

+134
-42
lines changed

cmd/erised/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.16
44

55
require (
66
github.com/franela/goblin v0.0.0-20210113153425-413781f5e6c8
7+
github.com/onsi/gomega v1.11.0
78
github.com/rs/zerolog v1.20.0
89
)

cmd/erised/go.sum

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
11
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
22
github.com/franela/goblin v0.0.0-20210113153425-413781f5e6c8 h1:QVPknD9yAYAmmmERIxdPFY6yf8d7xqoieNs/1C9ieCk=
33
github.com/franela/goblin v0.0.0-20210113153425-413781f5e6c8/go.mod h1:VzmDKDJVZI3aJmnRI9VjAn9nJ8qPPsN1fqzr9dqInIo=
4+
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
5+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
7+
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
8+
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
9+
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
10+
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
11+
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
12+
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
13+
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
14+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
15+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
16+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
17+
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
18+
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
19+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
20+
github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ=
21+
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
22+
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
23+
github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug=
24+
github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg=
425
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
526
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
627
github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs=
728
github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
829
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
30+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
31+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
32+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
933
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
34+
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
35+
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
36+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1037
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
38+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1139
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
40+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41+
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
42+
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
43+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
44+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1245
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
46+
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
47+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
48+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
1349
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
1450
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
51+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
52+
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
53+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
54+
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
55+
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
56+
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
57+
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
58+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
59+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
61+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
62+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
63+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
64+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
65+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

cmd/erised/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/rs/zerolog/log"
1414
)
1515

16-
const version = "v0.3.1"
16+
const version = "v0.3.3"
1717

1818
type server struct {
1919
mux *http.ServeMux

cmd/erised/serverRoutes.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ func (s *server) handleLanding() http.HandlerFunc {
4343
res.Header().Set("Content-Type", ct)
4444
res.Header().Set("Content-Encoding", ce)
4545

46-
if rd, err := strconv.Atoi(req.Header.Get("X-Erised-Response-Delay")); err == nil {
46+
if rd, err := strconv.Atoi(req.Header.Get("X-Erised-Response-Delay")); rd > 0 && err == nil {
4747
delay = time.Duration(rd) * time.Millisecond
48-
} else {
49-
log.Debug().Msg("Invalid X-Erised-Response-Delay")
5048
}
5149

5250
hd := req.Header.Get("X-Erised-Headers")
@@ -58,8 +56,6 @@ func (s *server) handleLanding() http.HandlerFunc {
5856
res.Header().Set(k, fmt.Sprintf("%v", v))
5957
}
6058
}
61-
} else {
62-
log.Debug().Msg("Invalid X-Erised-Headers JSON list")
6359
}
6460

6561
sc := httpStatusCode(req.Header.Get("X-Erised-Status-Code"))

cmd/erised/serverRoutes_test.go

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import (
44
"net/http"
55
"net/http/httptest"
66
"testing"
7+
"time"
78

89
"github.com/franela/goblin"
10+
. "github.com/onsi/gomega"
11+
"github.com/rs/zerolog"
912
)
1013

1114
func TestErisedInfoRoute(t *testing.T) {
15+
zerolog.SetGlobalLevel(zerolog.Disabled)
1216
g := goblin.Goblin(t)
17+
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
1318
exp := `{"Host":"localhost:8080","Method":"GET","Protocol":"HTTP/1.1","Request URI":"http://localhost:8080/erised/info"}`
1419
svr := server {}
1520
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/erised/info", nil)
@@ -18,22 +23,23 @@ func TestErisedInfoRoute(t *testing.T) {
1823

1924
g.Describe("Test erised/info", func() {
2025
g.It("Should return StatusOK", func() {
21-
g.Assert(res.Code).Equal(http.StatusOK)
26+
Ω(res.Code).Should(Equal(http.StatusOK))
2227
})
2328

2429
g.It("Should match expected body", func() {
25-
g.Assert(res.Body.String()).Equal(exp)
30+
Ω(res.Body.String()).Should(Equal(exp))
2631
})
2732

2833
g.It("Should match Content-Type header", func() {
29-
g.Assert(res.Header().Get("Content-Type")).Equal("application/json")
34+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/json"))
3035
})
31-
3236
})
3337
}
3438

3539
func TestErisedIPRoute(t *testing.T) {
40+
zerolog.SetGlobalLevel(zerolog.Disabled)
3641
g := goblin.Goblin(t)
42+
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
3743
exp := `{"Client IP":"192.0.2.1:1234"}`
3844
svr := server {}
3945
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/erised/ip", nil)
@@ -42,21 +48,23 @@ func TestErisedIPRoute(t *testing.T) {
4248

4349
g.Describe("Test erised/ip", func() {
4450
g.It("Should return StatusOK", func() {
45-
g.Assert(res.Code).Equal(http.StatusOK)
51+
Ω(res.Code).Should(Equal(http.StatusOK))
4652
})
4753

4854
g.It("Should match expected body", func() {
49-
g.Assert(res.Body.String()).Equal(exp)
55+
Ω(res.Body.String()).Should(Equal(exp))
5056
})
5157

5258
g.It("Should match Content-Type header", func() {
53-
g.Assert(res.Header().Get("Content-Type")).Equal("application/json")
59+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/json"))
5460
})
5561
})
5662
}
5763

5864
func TestErisedHeadersRoute(t *testing.T) {
65+
zerolog.SetGlobalLevel(zerolog.Disabled)
5966
g := goblin.Goblin(t)
67+
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
6068
exp := `{"Host":"localhost:8080"}`
6169
svr := server {}
6270
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/erised/headers", nil)
@@ -65,21 +73,23 @@ func TestErisedHeadersRoute(t *testing.T) {
6573

6674
g.Describe("Test erised/headers", func() {
6775
g.It("Should return StatusOK", func() {
68-
g.Assert(res.Code).Equal(http.StatusOK)
76+
Ω(res.Code).Should(Equal(http.StatusOK))
6977
})
7078

7179
g.It("Should match expected body", func() {
72-
g.Assert(res.Body.String()).Equal(exp)
80+
Ω(res.Body.String()).Should(Equal(exp))
7381
})
7482

7583
g.It("Should match Content-Type header", func() {
76-
g.Assert(res.Header().Get("Content-Type")).Equal("application/json")
84+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/json"))
7785
})
7886
})
7987
}
8088

8189
func TestErisedLandingRoute(t *testing.T) {
90+
zerolog.SetGlobalLevel(zerolog.Disabled)
8291
g := goblin.Goblin(t)
92+
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
8393
svr := server {}
8494

8595
g.Describe("Test /", func() {
@@ -88,32 +98,33 @@ func TestErisedLandingRoute(t *testing.T) {
8898
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
8999
svr.handleLanding().ServeHTTP(res, req)
90100

91-
g.Assert(res.Code).Equal(http.StatusOK)
92-
g.Assert(res.Body.String()).Equal("")
101+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
102+
Ω(res.Body.String()).Should(BeEmpty())
93103
})
94104

95-
g.It("Should return TemporaryRedirect and Location", func() {
105+
g.It("Should return TemporaryRedirect and Location url", func() {
96106
res := httptest.NewRecorder()
97107
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
98108
req.Header.Set("X-Erised-Status-Code", "TemporaryRedirect")
99109
req.Header.Set("X-Erised-Location", "https://www.example.com")
100110
svr.handleLanding().ServeHTTP(res, req)
101111

102-
g.Assert(res.Code).Equal(http.StatusTemporaryRedirect)
103-
g.Assert(res.Header().Get("Location")).Equal("https://www.example.com")
112+
Ω(res).Should(HaveHTTPStatus(http.StatusTemporaryRedirect))
113+
Ω(res.Header().Get("Location")).Should(Equal("https://www.example.com"))
104114
})
105115

106-
g.It("Should return JSON body", func() {
116+
g.It("Should return json body", func() {
107117
exp := `{"hello":"world"}`
108118
res := httptest.NewRecorder()
109119
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
110120
req.Header.Set("X-Erised-Content-Type", "json")
111121
req.Header.Set("X-Erised-Data", exp)
112122
svr.handleLanding().ServeHTTP(res, req)
113123

114-
g.Assert(res.Code).Equal(http.StatusOK)
115-
g.Assert(res.Header().Get("Content-Type")).Equal("application/json")
116-
g.Assert(res.Body.String()).Equal(exp)
124+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
125+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/json"))
126+
Ω(res.Header().Get("Content-Encoding")).Should(Equal("identity"))
127+
Ω(res.Body.String()).Should(Equal(exp))
117128
})
118129

119130
g.It("Should return text body", func() {
@@ -124,9 +135,40 @@ func TestErisedLandingRoute(t *testing.T) {
124135
req.Header.Set("X-Erised-Data", exp)
125136
svr.handleLanding().ServeHTTP(res, req)
126137

127-
g.Assert(res.Code).Equal(http.StatusOK)
128-
g.Assert(res.Header().Get("Content-Type")).Equal("text/plain")
129-
g.Assert(res.Body.String()).Equal(exp)
138+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
139+
Ω(res.Header().Get("Content-Type")).Should(Equal("text/plain"))
140+
Ω(res.Header().Get("Content-Encoding")).Should(Equal("identity"))
141+
Ω(res.Body.String()).Should(Equal(exp))
142+
})
143+
144+
g.It("Should return xml body", func() {
145+
exp := "<hello>world</hello>"
146+
res := httptest.NewRecorder()
147+
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
148+
req.Header.Set("X-Erised-Content-Type", "xml")
149+
req.Header.Set("X-Erised-Data", exp)
150+
svr.handleLanding().ServeHTTP(res, req)
151+
152+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
153+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/xml"))
154+
Ω(res.Header().Get("Content-Encoding")).Should(Equal("identity"))
155+
Ω(res.Body.String()).Should(Equal(exp))
156+
})
157+
158+
g.It("Should return gzip body", func() {
159+
exp := "Lorem ipsum"
160+
gz := "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\xf2\xc9/J\xcdU\xc8,(.\xcd\x05\x04\x00\x00\xff\xffY\xfbK\xf4\v\x00\x00\x00"
161+
162+
res := httptest.NewRecorder()
163+
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
164+
req.Header.Set("X-Erised-Content-Type", "gzip")
165+
req.Header.Set("X-Erised-Data", exp)
166+
svr.handleLanding().ServeHTTP(res, req)
167+
168+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
169+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/octet-stream"))
170+
Ω(res.Header().Get("Content-Encoding")).Should(Equal("gzip"))
171+
Ω(res.Body.String()).Should(Equal(gz))
130172
})
131173

132174
g.It("Should return headers", func() {
@@ -136,19 +178,23 @@ func TestErisedLandingRoute(t *testing.T) {
136178
req.Header.Set("X-Erised-Headers", exp)
137179
svr.handleLanding().ServeHTTP(res, req)
138180

139-
g.Assert(res.Code).Equal(http.StatusOK)
140-
g.Assert(res.Header().Get("X-Headers-One")).Equal("I'm header one")
141-
g.Assert(res.Header().Get("X-Headers-Two")).Equal("I'm header two")
181+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
182+
Ω(res.Header().Get("X-Headers-One")).Should(Equal("I'm header one"))
183+
Ω(res.Header().Get("X-Headers-Two")).Should(Equal("I'm header two"))
142184
})
143185

144186
g.It("Should wait 2000ms", func() {
145187
res := httptest.NewRecorder()
146188
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/", nil)
147189
req.Header.Set("X-Erised-Response-Delay", "2000")
190+
191+
st := time.Now()
148192
svr.handleLanding().ServeHTTP(res, req)
193+
el := time.Since(st)
149194

150-
g.Assert(res.Code).Equal(http.StatusOK)
151-
g.Assert(res.Body.String()).Equal("")
195+
Ω(res).Should(HaveHTTPStatus(http.StatusOK))
196+
Ω(el).Should(BeNumerically("~", time.Millisecond * 2000 , time.Millisecond * 10))
197+
Ω(res.Body.String()).Should(BeEmpty())
152198
})
153199

154200
g.It("Should not fail", func() {
@@ -159,18 +205,16 @@ func TestErisedLandingRoute(t *testing.T) {
159205
req.Header.Set("X-Erised-Data", exp)
160206
req.Header.Set("X-Erised-Headers", exp)
161207
req.Header.Set("X-Erised-Location", "https://www.example.com")
162-
req.Header.Set("X-Erised-Response-Delay", "1")
208+
req.Header.Set("X-Erised-Response-Delay", "0")
163209
req.Header.Set("X-Erised-Status-Code", "MovedPermanently")
164210
svr.handleLanding().ServeHTTP(res, req)
165211

166-
g.Assert(res.Code).Equal(http.StatusMovedPermanently)
167-
g.Assert(res.Header().Get("Location")).Equal("https://www.example.com")
168-
g.Assert(res.Header().Get("Content-Type")).Equal("application/json")
169-
g.Assert(res.Header().Get("Content-Encoding")).Equal("identity")
170-
g.Assert(res.Header().Get("hello")).Equal("world")
171-
g.Assert(res.Body.String()).Equal(exp)
212+
Ω(res).Should(HaveHTTPStatus(http.StatusMovedPermanently))
213+
Ω(res.Header().Get("Location")).Should(Equal("https://www.example.com"))
214+
Ω(res.Header().Get("Content-Type")).Should(Equal("application/json"))
215+
Ω(res.Header().Get("Content-Encoding")).Should(Equal("identity"))
216+
Ω(res.Header().Get("hello")).Should(Equal("world"))
217+
Ω(res.Body.String()).Should(Equal(exp))
172218
})
173-
174219
})
175220
}
176-

0 commit comments

Comments
 (0)