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

Function TestCreateRouteAndControllerAndView

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

Source from the content-addressed store, hash-verified

2749}
2750
2751func TestCreateRouteAndControllerAndView(t *testing.T) {
2752 is := is.New(t)
2753 ctx := context.Background()
2754 dir := t.TempDir()
2755 td := testdir.New(dir)
2756 td.NodeModules["svelte"] = versions.Svelte
2757 td.Files["controller/controller.go"] = `
2758 package controller
2759 type Controller struct{}
2760 func (c *Controller) Index() string {
2761 return "/"
2762 }
2763 `
2764 is.NoErr(td.Write(ctx))
2765 // Start
2766 cli := testcli.New(dir)
2767 app, err := cli.Start(ctx, "run")
2768 is.NoErr(err)
2769 defer app.Close()
2770 // Test index
2771 res, err := app.GetJSON("/")
2772 is.NoErr(err)
2773 is.NoErr(res.Diff(`
2774 HTTP/1.1 200 OK
2775 Content-Type: application/json
2776
2777 "/"
2778 `))
2779 // Create a new route
2780 is.NoErr(os.WriteFile(filepath.Join(dir, "controller", "controller.go"), []byte(`
2781 package controller
2782 type Controller struct{}
2783 func (c *Controller) Index() string {
2784 return "/"
2785 }
2786 func (c *Controller) Show(id string) string {
2787 return "/" + id
2788 }
2789 `), 0644))
2790 // Wait for the app to be ready again
2791 readyCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
2792 is.NoErr(app.Ready(readyCtx))
2793 cancel()
2794 res, err = app.GetJSON("/10")
2795 is.NoErr(err)
2796 is.NoErr(res.Diff(`
2797 HTTP/1.1 200 OK
2798 Content-Type: application/json
2799
2800 "/10"
2801 `))
2802 // Create a new controller
2803 is.NoErr(os.MkdirAll(filepath.Join(dir, "controller", "posts"), 0755))
2804 is.NoErr(os.WriteFile(filepath.Join(dir, "controller", "posts", "controller.go"), []byte(`
2805 package posts
2806 type Controller struct{}
2807 func (c *Controller) Index() string {
2808 return "/posts"

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
GetJSONMethod · 0.80
DiffMethod · 0.80
ReadyMethod · 0.80
DiffHeadersMethod · 0.80
QueryMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected