MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / assertSuccessfulRequest

Function assertSuccessfulRequest

pkg/requests/builder_test.go:252–322  ·  view source on GitHub ↗
(builder func() Builder, expectedRequest testHTTPRequest)

Source from the content-addressed store, hash-verified

250})
251
252func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPRequest) {
253 Context("Do", func() {
254 var result Result
255
256 BeforeEach(func() {
257 result = builder().Do()
258 Expect(result.Error()).ToNot(HaveOccurred())
259 })
260
261 It("returns a successful status", func() {
262 Expect(result.StatusCode()).To(Equal(http.StatusOK))
263 })
264
265 It("made the expected request", func() {
266 actualRequest := testHTTPRequest{}
267 Expect(json.Unmarshal(result.Body(), &actualRequest)).To(Succeed())
268
269 Expect(actualRequest).To(Equal(expectedRequest))
270 })
271 })
272
273 Context("UnmarshalInto", func() {
274 var actualRequest testHTTPRequest
275
276 BeforeEach(func() {
277 Expect(builder().Do().UnmarshalInto(&actualRequest)).To(Succeed())
278 })
279
280 It("made the expected request", func() {
281 Expect(actualRequest).To(Equal(expectedRequest))
282 })
283 })
284
285 Context("UnmarshalJSON", func() {
286 var response *simplejson.Json
287
288 BeforeEach(func() {
289 var err error
290 response, err = builder().Do().UnmarshalSimpleJSON()
291 Expect(err).ToNot(HaveOccurred())
292 })
293
294 It("made the expected reqest", func() {
295 header := http.Header{}
296 for key, value := range response.Get("Header").MustMap() {
297 vs, ok := value.([]interface{})
298 Expect(ok).To(BeTrue())
299 svs := []string{}
300 for _, v := range vs {
301 sv, ok := v.(string)
302 Expect(ok).To(BeTrue())
303 svs = append(svs, sv)
304 }
305 header[key] = svs
306 }
307
308 // Other json unmarhsallers base64 decode byte slices automatically
309 body, err := base64.StdEncoding.DecodeString(response.Get("Body").MustString())

Callers 1

builder_test.goFile · 0.85

Calls 8

ErrorMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
builderStruct · 0.85
DoMethod · 0.65
UnmarshalIntoMethod · 0.65
UnmarshalSimpleJSONMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected