MCPcopy Create free account
hub / github.com/exercism/cli / TestDumpRequest

Function TestDumpRequest

debug/debug_test.go:33–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestDumpRequest(t *testing.T) {
34 testCases := []struct {
35 desc string
36 auth string
37 verbose bool
38 unmask bool
39 }{
40 {
41 desc: "Do not attempt to dump request if 'Verbose' is set to false",
42 auth: "",
43 verbose: false,
44 unmask: false,
45 },
46 {
47 desc: "Dump request without authorization header",
48 auth: "", //not set
49 verbose: true,
50 unmask: false,
51 },
52 {
53 desc: "Dump request with malformed 'Authorization' header",
54 auth: "malformed",
55 verbose: true,
56 unmask: true,
57 },
58 {
59 desc: "Dump request with properly formed 'Authorization' header",
60 auth: "Bearer abc12-345abcde1234-5abc12",
61 verbose: true,
62 unmask: false,
63 },
64 }
65
66 b := &bytes.Buffer{}
67 output = b
68 for _, tc := range testCases {
69 Verbose = tc.verbose
70 UnmaskAPIKey = tc.unmask
71 r, _ := http.NewRequest("GET", "https://api.example.com/bogus", nil)
72 if tc.auth != "" {
73 r.Header.Set("Authorization", tc.auth)
74 }
75
76 DumpRequest(r)
77 if tc.verbose {
78 assert.Regexp(t, "GET /bogus", b.String(), tc.desc)
79 assert.Equal(t, tc.auth, r.Header.Get("Authorization"), tc.desc)
80 if tc.unmask {
81 assert.Regexp(t, "Authorization: "+tc.auth, b.String(), tc.desc)
82 }
83 } else {
84 assert.NotRegexp(t, "GET /bogus", b.String(), tc.desc)
85 }
86 }
87}
88
89func TestDumpResponse(t *testing.T) {
90 b := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 3

DumpRequestFunction · 0.85
NewRequestMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected