From ac9ea6898982a832a354ceb172a7e8df661e0245 Mon Sep 17 00:00:00 2001 From: Corin Lawson Date: Fri, 22 Mar 2024 20:43:24 +1100 Subject: [PATCH] test: introduce basic tests for i/cmd/vermockgen Prior to this change, there were no test files for the package: github.com/Versent/go-vermock/internal/cmd/vermockgen. This change introduces limited tests for SetFlags and Execute methods. --- internal/cmd/vermockgen/gen_test.go | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/cmd/vermockgen/gen_test.go diff --git a/internal/cmd/vermockgen/gen_test.go b/internal/cmd/vermockgen/gen_test.go new file mode 100644 index 0000000..4e00c93 --- /dev/null +++ b/internal/cmd/vermockgen/gen_test.go @@ -0,0 +1,36 @@ +package vermockgen_test + +import ( + "bytes" + "flag" + "log" + "testing" + + vermockgen "github.com/Versent/go-vermock/internal/cmd/vermockgen" +) + +func TestSetFlags(t *testing.T) { + f := flag.NewFlagSet("vermockgen", flag.ContinueOnError) + vermockgen.NewGenCmd(nil, f) + expected := []string{"header", "tags"} + f.VisitAll(func(f *flag.Flag) { + if len(expected) == 0 { + t.Errorf("unexpected flag %q", f.Name) + return + } + + var got, want string + got, want, expected = f.Name, expected[0], expected[1:] + if got != want { + t.Errorf("unexpected name, got %q, want %q", got, want) + } + }) +} + +func TestExecute(t *testing.T) { + var buf bytes.Buffer + l := log.New(&buf, "", 0) + f := flag.NewFlagSet("vermockgen", flag.ContinueOnError) + vermockgen.NewGenCmd(l, f) + +}