(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestGetSessionKeyFromCookie(t *testing.T) { |
| 27 | testCases := []struct { |
| 28 | cookie *http.Cookie |
| 29 | expected string |
| 30 | }{ |
| 31 | { |
| 32 | cookie: &http.Cookie{ |
| 33 | Name: "id", |
| 34 | Value: "foo", |
| 35 | HttpOnly: true, |
| 36 | }, |
| 37 | expected: "foo", |
| 38 | }, |
| 39 | { |
| 40 | cookie: nil, |
| 41 | expected: "", |
| 42 | }, |
| 43 | { |
| 44 | cookie: &http.Cookie{ |
| 45 | Name: "foo", |
| 46 | Value: "bar", |
| 47 | HttpOnly: true, |
| 48 | }, |
| 49 | expected: "", |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | for _, tc := range testCases { |
| 54 | // set up |
| 55 | r, err := http.NewRequest("GET", "/", nil) |
| 56 | if err != nil { |
| 57 | t.Fatal(errors.Wrap(err, "constructing request")) |
| 58 | } |
| 59 | |
| 60 | if tc.cookie != nil { |
| 61 | r.AddCookie(tc.cookie) |
| 62 | } |
| 63 | |
| 64 | // execute |
| 65 | got, err := getSessionKeyFromCookie(r) |
| 66 | if err != nil { |
| 67 | t.Fatal(errors.Wrap(err, "executing")) |
| 68 | } |
| 69 | |
| 70 | assert.Equal(t, got, tc.expected, "result mismatch") |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func TestGetSessionKeyFromAuth(t *testing.T) { |
| 75 | testCases := []struct { |
nothing calls this directly
no test coverage detected