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

Function TestUpdateBodyAndSignatureAndRoute

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

Source from the content-addressed store, hash-verified

2977}
2978
2979func TestUpdateBodyAndSignatureAndRoute(t *testing.T) {
2980 is := is.New(t)
2981 ctx := context.Background()
2982 dir := t.TempDir()
2983 td := testdir.New(dir)
2984 td.Files["controller/controller.go"] = `
2985 package controller
2986 type Controller struct {}
2987 func (c *Controller) Index() string {
2988 return "Hello Users!"
2989 }
2990 `
2991 is.NoErr(td.Write(ctx))
2992 cli := testcli.New(dir)
2993 app, err := cli.Start(ctx, "run")
2994 is.NoErr(err)
2995 defer app.Close()
2996 // Test initial route
2997 res, err := app.Get("/")
2998 is.NoErr(err)
2999 is.NoErr(err)
3000 is.NoErr(res.DiffHeaders(`
3001 HTTP/1.1 200 OK
3002 Content-Type: text/html
3003 `))
3004 is.In(res.Body().String(), `Hello Users!`)
3005 // Update controller body
3006 is.NoErr(os.WriteFile(filepath.Join(dir, "controller", "controller.go"), []byte(`
3007 package controller
3008 type Controller struct {}
3009 func (c *Controller) Index() string {
3010 return "Hello Humans!"
3011 }
3012 `), 0644))
3013 // Wait for the app to be ready again
3014 readyCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
3015 is.NoErr(app.Ready(readyCtx))
3016 cancel()
3017 // Retry
3018 res, err = app.Get("/")
3019 is.NoErr(err)
3020 is.NoErr(res.DiffHeaders(`
3021 HTTP/1.1 200 OK
3022 Content-Type: text/html
3023 `))
3024 is.In(res.Body().String(), `Hello Humans!`)
3025 // Update controller signature
3026 is.NoErr(os.WriteFile(filepath.Join(dir, "controller", "controller.go"), []byte(`
3027 package controller
3028 type Controller struct {}
3029 func (c *Controller) Index(name string) (string, error) {
3030 return "Hello " + name + "!", nil
3031 }
3032 `), 0644))
3033 // Wait for the app to be ready again
3034 readyCtx, cancel = context.WithTimeout(ctx, 15*time.Second)
3035 is.NoErr(app.Ready(readyCtx))
3036 cancel()

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
DiffHeadersMethod · 0.80
InMethod · 0.80
BodyMethod · 0.80
ReadyMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected