(t *testing.T)
| 111 | } |
| 112 | |
| 113 | func TestGetCredential(t *testing.T) { |
| 114 | r1 := mustMakeRequest(t) |
| 115 | r2 := mustMakeRequest(t) |
| 116 | r2.Header.Set("Authorization", "Bearer foo") |
| 117 | r3 := mustMakeRequest(t) |
| 118 | r3.Header.Set("Authorization", "Bearer bar") |
| 119 | |
| 120 | r4 := mustMakeRequest(t) |
| 121 | c4 := http.Cookie{ |
| 122 | Name: "id", |
| 123 | Value: "foo", |
| 124 | HttpOnly: true, |
| 125 | } |
| 126 | r4.AddCookie(&c4) |
| 127 | |
| 128 | r5 := mustMakeRequest(t) |
| 129 | c5 := http.Cookie{ |
| 130 | Name: "id", |
| 131 | Value: "foo", |
| 132 | HttpOnly: true, |
| 133 | } |
| 134 | r5.AddCookie(&c5) |
| 135 | r5.Header.Set("Authorization", "Bearer foo") |
| 136 | |
| 137 | testCases := []struct { |
| 138 | request *http.Request |
| 139 | expected string |
| 140 | }{ |
| 141 | { |
| 142 | request: r1, |
| 143 | expected: "", |
| 144 | }, |
| 145 | { |
| 146 | request: r2, |
| 147 | expected: "foo", |
| 148 | }, |
| 149 | { |
| 150 | request: r3, |
| 151 | expected: "bar", |
| 152 | }, |
| 153 | { |
| 154 | request: r4, |
| 155 | expected: "foo", |
| 156 | }, |
| 157 | { |
| 158 | request: r5, |
| 159 | expected: "foo", |
| 160 | }, |
| 161 | } |
| 162 | |
| 163 | for _, tc := range testCases { |
| 164 | // execute |
| 165 | got, err := GetCredential(tc.request) |
| 166 | if err != nil { |
| 167 | t.Fatal(errors.Wrap(err, "executing")) |
| 168 | } |
| 169 | |
| 170 | assert.Equal(t, got, tc.expected, "result mismatch") |
nothing calls this directly
no test coverage detected