@@ -2,7 +2,7 @@ package matchers_test
2
2
3
3
import (
4
4
"bytes"
5
- "io/ioutil "
5
+ "io"
6
6
"net/http"
7
7
"net/http/httptest"
8
8
"strings"
@@ -15,13 +15,13 @@ var _ = Describe("HaveHTTPBody", func() {
15
15
When ("ACTUAL is *http.Response" , func () {
16
16
It ("matches the body" , func () {
17
17
const body = "this is the body"
18
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
18
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
19
19
Expect (resp ).To (HaveHTTPBody (body ))
20
20
})
21
21
22
22
It ("mismatches the body" , func () {
23
23
const body = "this is the body"
24
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
24
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
25
25
Expect (resp ).NotTo (HaveHTTPBody ("something else" ))
26
26
})
27
27
})
@@ -52,33 +52,33 @@ var _ = Describe("HaveHTTPBody", func() {
52
52
When ("EXPECTED is []byte" , func () {
53
53
It ("matches the body" , func () {
54
54
const body = "this is the body"
55
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
55
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
56
56
Expect (resp ).To (HaveHTTPBody ([]byte (body )))
57
57
})
58
58
59
59
It ("mismatches the body" , func () {
60
60
const body = "this is the body"
61
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
61
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
62
62
Expect (resp ).NotTo (HaveHTTPBody ([]byte ("something else" )))
63
63
})
64
64
})
65
65
66
66
When ("EXPECTED is a submatcher" , func () {
67
67
It ("matches the body" , func () {
68
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (`{"some":"json"}` ))}
68
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (`{"some":"json"}` ))}
69
69
Expect (resp ).To (HaveHTTPBody (MatchJSON (`{ "some": "json" }` )))
70
70
})
71
71
72
72
It ("mismatches the body" , func () {
73
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (`{"some":"json"}` ))}
73
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (`{"some":"json"}` ))}
74
74
Expect (resp ).NotTo (HaveHTTPBody (MatchJSON (`{ "something": "different" }` )))
75
75
})
76
76
})
77
77
78
78
When ("EXPECTED is something else" , func () {
79
79
It ("errors" , func () {
80
80
failures := InterceptGomegaFailures (func () {
81
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader ("body" ))}
81
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader ("body" ))}
82
82
Expect (resp ).To (HaveHTTPBody (map [int ]bool {}))
83
83
})
84
84
Expect (failures ).To (HaveLen (1 ))
@@ -90,7 +90,7 @@ var _ = Describe("HaveHTTPBody", func() {
90
90
Context ("EXPECTED is string" , func () {
91
91
It ("returns a match failure message" , func () {
92
92
failures := InterceptGomegaFailures (func () {
93
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader ("this is the body" ))}
93
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader ("this is the body" ))}
94
94
Expect (resp ).To (HaveHTTPBody ("this is a different body" ))
95
95
})
96
96
Expect (failures ).To (HaveLen (1 ))
@@ -104,7 +104,7 @@ to equal
104
104
Context ("EXPECTED is []byte" , func () {
105
105
It ("returns a match failure message" , func () {
106
106
failures := InterceptGomegaFailures (func () {
107
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader ("this is the body" ))}
107
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader ("this is the body" ))}
108
108
Expect (resp ).To (HaveHTTPBody ([]byte ("this is a different body" )))
109
109
})
110
110
Expect (failures ).To (HaveLen (1 ))
@@ -118,7 +118,7 @@ to equal
118
118
Context ("EXPECTED is submatcher" , func () {
119
119
It ("returns a match failure message" , func () {
120
120
failures := InterceptGomegaFailures (func () {
121
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (`{"some":"json"}` ))}
121
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (`{"some":"json"}` ))}
122
122
Expect (resp ).To (HaveHTTPBody (MatchJSON (`{"other":"stuff"}` )))
123
123
})
124
124
Expect (failures ).To (HaveLen (1 ))
@@ -139,7 +139,7 @@ to match JSON of
139
139
It ("returns a negated failure message" , func () {
140
140
const body = "this is the body"
141
141
failures := InterceptGomegaFailures (func () {
142
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
142
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
143
143
Expect (resp ).NotTo (HaveHTTPBody (body ))
144
144
})
145
145
Expect (failures ).To (HaveLen (1 ))
@@ -154,7 +154,7 @@ not to equal
154
154
It ("returns a match failure message" , func () {
155
155
const body = "this is the body"
156
156
failures := InterceptGomegaFailures (func () {
157
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
157
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
158
158
Expect (resp ).NotTo (HaveHTTPBody ([]byte (body )))
159
159
})
160
160
Expect (failures ).To (HaveLen (1 ))
@@ -169,7 +169,7 @@ not to equal
169
169
It ("returns a match failure message" , func () {
170
170
const body = `{"some":"json"}`
171
171
failures := InterceptGomegaFailures (func () {
172
- resp := & http.Response {Body : ioutil .NopCloser (strings .NewReader (body ))}
172
+ resp := & http.Response {Body : io .NopCloser (strings .NewReader (body ))}
173
173
Expect (resp ).NotTo (HaveHTTPBody (MatchJSON (body )))
174
174
})
175
175
Expect (failures ).To (HaveLen (1 ))
0 commit comments