(t *testing.T)
| 1996 | } |
| 1997 | |
| 1998 | func 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 | |
| 2045 | func TestRequestMap(t *testing.T) { |
| 2046 | is := is.New(t) |
nothing calls this directly
no test coverage detected