MCPcopy Index your code
hub / github.com/livebud/bud / TestIndexString

Function TestIndexString

framework/controller/controller_test.go:44–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func TestIndexString(t *testing.T) {
45 is := is.New(t)
46 ctx := context.Background()
47 dir := t.TempDir()
48 td := testdir.New(dir)
49 td.Files["controller/controller.go"] = `
50 package controller
51 type Controller struct {}
52 func (c *Controller) Index() string {
53 return "Root"
54 }
55 `
56 td.Files["controller/about/controller.go"] = `
57 package about
58 type Controller struct {}
59 func (c *Controller) Index() string {
60 return "About"
61 }
62 `
63 td.Files["controller/posts/comments/controller.go"] = `
64 package comments
65 type Controller struct {}
66 func (c *Controller) Index() string {
67 return "Comments"
68 }
69 `
70 is.NoErr(td.Write(ctx))
71 cli := testcli.New(dir)
72 app, err := cli.Start(ctx, "run")
73 is.NoErr(err)
74 defer app.Close()
75 // HTML response
76 res, err := app.Get("/")
77 is.NoErr(err)
78 is.NoErr(res.DiffHeaders(`
79 HTTP/1.1 200 OK
80 Content-Type: text/html
81 `))
82 is.In(res.Body().String(), "Root")
83 // JSON response
84 res, err = app.GetJSON("/")
85 is.NoErr(err)
86 is.NoErr(res.Diff(`
87 HTTP/1.1 200 OK
88 Content-Type: application/json
89
90 "Root"
91 `))
92 // HTML response
93 res, err = app.Get("/about")
94 is.NoErr(err)
95 is.NoErr(res.DiffHeaders(`
96 HTTP/1.1 200 OK
97 Content-Type: text/html
98 `))
99 is.In(res.Body().String(), "About")
100 // JSON response
101 res, err = app.GetJSON("/about")

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
DiffHeadersMethod · 0.80
InMethod · 0.80
BodyMethod · 0.80
GetJSONMethod · 0.80
DiffMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected