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

Function TestCustomActions

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

Source from the content-addressed store, hash-verified

1782}
1783
1784func TestCustomActions(t *testing.T) {
1785 is := is.New(t)
1786 ctx := context.Background()
1787 dir := t.TempDir()
1788 td := testdir.New(dir)
1789 td.Files["controller/controller.go"] = `
1790 package controller
1791 type Controller struct {}
1792 func (c *Controller) About() string { return "about" }
1793 `
1794 td.Files["controller/users/users.go"] = `
1795 package users
1796 type Controller struct {}
1797 func (c *Controller) Deactivate() string { return "deactivate" }
1798 `
1799 is.NoErr(td.Write(ctx))
1800 cli := testcli.New(dir)
1801 app, err := cli.Start(ctx, "run")
1802 is.NoErr(err)
1803 defer app.Close()
1804 res, err := app.Get("/about")
1805 is.NoErr(err)
1806 // HTML response
1807 is.NoErr(res.DiffHeaders(`
1808 HTTP/1.1 200 OK
1809 Content-Type: text/html
1810 `))
1811 is.In(res.Body().String(), `about`)
1812 res, err = app.Get("/users/deactivate")
1813 is.NoErr(err)
1814 // HTML response
1815 is.NoErr(res.DiffHeaders(`
1816 HTTP/1.1 200 OK
1817 Content-Type: text/html
1818 `))
1819 is.In(res.Body().String(), `deactivate`)
1820 is.NoErr(app.Close())
1821}
1822
1823func TestHandlerFuncs(t *testing.T) {
1824 is := is.New(t)

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
DiffHeadersMethod · 0.80
InMethod · 0.80
BodyMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
WriteMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected