| 1821 | } |
| 1822 | |
| 1823 | func TestHandlerFuncs(t *testing.T) { |
| 1824 | is := is.New(t) |
| 1825 | ctx := context.Background() |
| 1826 | dir := t.TempDir() |
| 1827 | td := testdir.New(dir) |
| 1828 | td.Files["controller/foos/bars/controller.go"] = ` |
| 1829 | package controller |
| 1830 | import "io" |
| 1831 | import "net/http" |
| 1832 | type Controller struct {} |
| 1833 | func (c *Controller) Index() string { |
| 1834 | return "hello" |
| 1835 | } |
| 1836 | func (c *Controller) Create(w http.ResponseWriter, r *http.Request) { |
| 1837 | w.WriteHeader(http.StatusCreated) |
| 1838 | w.Write([]byte(r.URL.Query().Get("foo_id"))) |
| 1839 | io.Copy(w, r.Body) |
| 1840 | } |
| 1841 | ` |
| 1842 | is.NoErr(td.Write(ctx)) |
| 1843 | cli := testcli.New(dir) |
| 1844 | app, err := cli.Start(ctx, "run") |
| 1845 | is.NoErr(err) |
| 1846 | defer app.Close() |
| 1847 | // Test POST |
| 1848 | res, err := app.Post("/foos/some/bars", bytes.NewBufferString("body")) |
| 1849 | is.NoErr(err) |
| 1850 | diff.TestHTTP(t, res.Headers().String(), ` |
| 1851 | HTTP/1.1 201 Created |
| 1852 | Content-Type: text/plain; charset=utf-8 |
| 1853 | `) |
| 1854 | is.Equal(res.Body().String(), `somebody`) |
| 1855 | // Test that regular actions continue to work |
| 1856 | res, err = app.GetJSON("/foos/some/bars") |
| 1857 | is.NoErr(err) |
| 1858 | diff.TestHTTP(t, res.Dump().String(), ` |
| 1859 | HTTP/1.1 200 OK |
| 1860 | Content-Type: application/json |
| 1861 | |
| 1862 | "hello" |
| 1863 | `) |
| 1864 | is.NoErr(app.Close()) |
| 1865 | } |
| 1866 | |
| 1867 | func TestEnvSupport(t *testing.T) { |
| 1868 | is := is.New(t) |