MCPcopy
hub / github.com/tailscale/golink / TestServeGo

Function TestServeGo

golink_test.go:24–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestServeGo(t *testing.T) {
25 var err error
26 db, err = NewSQLiteDB(":memory:")
27 if err != nil {
28 t.Fatal(err)
29 }
30 db.Save(&Link{Short: "who", Long: "http://who/"})
31 db.Save(&Link{Short: "me", Long: "/who/{{.User}}"})
32 db.Save(&Link{Short: "invalid-var", Long: "/who/{{.Invalid}}"})
33
34 tests := []struct {
35 name string
36 link string
37 currentUser func(*http.Request) (user, error)
38 wantStatus int
39 wantLink string
40 }{
41 {
42 name: "simple link",
43 link: "/who",
44 wantStatus: http.StatusFound,
45 wantLink: "http://who/",
46 },
47 {
48 name: "simple link, anonymous request",
49 link: "/who",
50 currentUser: func(*http.Request) (user, error) { return user{}, nil },
51 wantStatus: http.StatusFound,
52 wantLink: "http://who/",
53 },
54 {
55 name: "simple link with path",
56 link: "/who/p",
57 wantStatus: http.StatusFound,
58 wantLink: "http://who/p",
59 },
60 {
61 name: "simple link with query",
62 link: "/who?q=1",
63 wantStatus: http.StatusFound,
64 wantLink: "http://who/?q=1",
65 },
66 {
67 name: "simple link with path and query",
68 link: "/who/p?q=1",
69 wantStatus: http.StatusFound,
70 wantLink: "http://who/p?q=1",
71 },
72 {
73 name: "simple link with double slash in path",
74 link: "/who/http://host",
75 wantStatus: http.StatusFound,
76 wantLink: "http://who/http://host",
77 },
78 {
79 name: "user link",
80 link: "/me",
81 wantStatus: http.StatusFound,

Callers

nothing calls this directly

Calls 3

NewSQLiteDBFunction · 0.85
serveHandlerFunction · 0.85
SaveMethod · 0.80

Tested by

no test coverage detected