| 127 | } |
| 128 | |
| 129 | func 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 | |
| 181 | func TestNoContent(t *testing.T) { |
| 182 | is := is.New(t) |