(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func TestCreateLinkStoresTargetAndOwner(t *testing.T) { |
| 47 | resetLinks(t) |
| 48 | |
| 49 | a := createLink(t, "https://example.com/a", "alice@example.com") |
| 50 | b := createLink(t, "https://example.com/b", "alice@example.com") |
| 51 | if a == b { |
| 52 | t.Fatalf("two links got the same short name %q", a) |
| 53 | } |
| 54 | |
| 55 | mux := http.NewServeMux() |
| 56 | mux.HandleFunc("GET /{link}", ServeLink) |
| 57 | for short, want := range map[string]string{a: "https://example.com/a", b: "https://example.com/b"} { |
| 58 | w := httptest.NewRecorder() |
| 59 | mux.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/"+short, nil)) |
| 60 | if got := w.Header().Get("Location"); w.Code != http.StatusFound || got != want { |
| 61 | t.Errorf("GET /%s = %d Location %q, want 302 %q", short, w.Code, got, want) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func TestListLinksUsesSessionNotHeader(t *testing.T) { |
| 67 | resetLinks(t) |
nothing calls this directly
no test coverage detected