MCPcopy Index your code
hub / github.com/livebud/bud / TestControllerChange

Function TestControllerChange

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

Source from the content-addressed store, hash-verified

1996}
1997
1998func TestControllerChange(t *testing.T) {
1999 is := is.New(t)
2000 ctx := context.Background()
2001 dir := t.TempDir()
2002 td := testdir.New(dir)
2003 td.Files["controller/controller.go"] = `
2004 package controller
2005 type Controller struct {}
2006 func (c *Controller) Index() (string, error) { return "/", nil }
2007 `
2008 is.NoErr(td.Write(ctx))
2009 cli := testcli.New(dir)
2010 app, err := cli.Start(ctx, "run")
2011 is.NoErr(err)
2012 defer app.Close()
2013 res, err := app.GetJSON("/")
2014 is.NoErr(err)
2015 res.Diff(`
2016 HTTP/1.1 200 OK
2017 Content-Type: application/json
2018
2019 "/"
2020 `)
2021 // Update controller
2022 controllerFile := filepath.Join(dir, "controller", "controller.go")
2023 is.NoErr(os.MkdirAll(filepath.Dir(controllerFile), 0755))
2024 is.NoErr(os.WriteFile(controllerFile, []byte(dedent.Dedent(`
2025 package controller
2026 type Controller struct {}
2027 func (c *Controller) Index() string { return "/" }
2028 `)), 0644))
2029 // Wait for the app to be ready again
2030 readyCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
2031 is.NoErr(app.Ready(readyCtx))
2032 cancel()
2033 // Try again with the new file
2034 res, err = app.GetJSON("/")
2035 is.NoErr(err)
2036 is.NoErr(res.Diff(`
2037 HTTP/1.1 200 OK
2038 Content-Type: application/json
2039
2040 "/"
2041 `))
2042 is.NoErr(app.Close())
2043}
2044
2045func TestRequestMap(t *testing.T) {
2046 is := is.New(t)

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
GetJSONMethod · 0.80
DiffMethod · 0.80
DirMethod · 0.80
ReadyMethod · 0.80
CloseMethod · 0.65
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected