package main import ( "context" "slices" "testing" "git.golem15.com/golem15/summercms/modules/bonfire" ) // captureAppRunner replaces appRunner for the test and returns a pointer to // the argv of the last call. func captureAppRunner(t *testing.T) *[]string { t.Helper() got := new([]string) prev := appRunner appRunner = func(ctx context.Context, argv []string, out bonfire.Output) error { *got = append([]string(nil), argv...) return nil } t.Cleanup(func() { appRunner = prev }) return got } func TestDelegatedServePassesFlags(t *testing.T) { for _, tc := range []struct { args []string want []string }{ {[]string{"serve", "--addr", ":8123"}, []string{"serve", "--addr", ":8123"}}, {[]string{"serve", "--help"}, []string{"serve", "--help"}}, {[]string{"serve", "-h"}, []string{"serve", "-h"}}, {[]string{"serve", "--addr=:8123"}, []string{"serve", "--addr=:8123"}}, {[]string{"serve", "--", "--addr", ":8123"}, []string{"serve", "--addr", ":8123"}}, } { got := captureAppRunner(t) if out, err := runSummer(t, tc.args...); err != nil { t.Fatalf("%q: %v\n%s", tc.args, err, out) } if !slices.Equal(*got, tc.want) { t.Fatalf("%q: argv = %q, want %q", tc.args, *got, tc.want) } } }