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

Function TestHandlerFuncs

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

Source from the content-addressed store, hash-verified

1821}
1822
1823func 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
1867func TestEnvSupport(t *testing.T) {
1868 is := is.New(t)

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
HeadersMethod · 0.80
EqualMethod · 0.80
BodyMethod · 0.80
GetJSONMethod · 0.80
DumpMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected