MCPcopy
hub / github.com/livebud/bud / TestCreateRedirect

Function TestCreateRedirect

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

Source from the content-addressed store, hash-verified

127}
128
129func TestCreateRedirect(t *testing.T) {
130 is := is.New(t)
131 ctx := context.Background()
132 dir := t.TempDir()
133 td := testdir.New(dir)
134 td.Files["controller/controller.go"] = `
135 package controller
136 type Controller struct {}
137 func (c *Controller) Create() {}
138 `
139 td.Files["controller/users/controller.go"] = `
140 package users
141 type Controller struct {}
142 func (c *Controller) Create() {}
143 `
144 td.Files["controller/posts/comments/controller.go"] = `
145 package comments
146 type Controller struct {}
147 func (c *Controller) Create() {}
148 `
149 is.NoErr(td.Write(ctx))
150 cli := testcli.New(dir)
151 app, err := cli.Start(ctx, "run")
152 is.NoErr(err)
153 defer app.Close()
154 // Redirect /
155 res, err := app.Post("/", nil)
156 is.NoErr(err)
157 is.NoErr(res.DiffHeaders(`
158 HTTP/1.1 302 Found
159 Location: /
160 `))
161 is.Equal(res.Body().Len(), 0)
162 // Redirect /users
163 res, err = app.Post("/users", nil)
164 is.NoErr(err)
165 is.NoErr(res.Diff(`
166 HTTP/1.1 302 Found
167 Location: /users
168 `))
169 is.Equal(res.Body().Len(), 0)
170 // Redirect /posts/10/comments
171 res, err = app.Post("/posts/10/comments", nil)
172 is.NoErr(err)
173 is.NoErr(res.Diff(`
174 HTTP/1.1 302 Found
175 Location: /posts/10/comments
176 `))
177 is.Equal(res.Body().Len(), 0)
178 is.NoErr(app.Close())
179}
180
181func TestNoContent(t *testing.T) {
182 is := is.New(t)

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
DiffHeadersMethod · 0.80
EqualMethod · 0.80
LenMethod · 0.80
BodyMethod · 0.80
DiffMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected