(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestVersionFlag(t *testing.T) { |
| 88 | versionOutput := fmt.Sprintf(versionTmpl, version, buildDate, commitHash, |
| 89 | runtime.Version(), runtime.Compiler, runtime.GOOS, runtime.GOARCH) |
| 90 | |
| 91 | var b bytes.Buffer |
| 92 | rootCmd.ResetFlags() |
| 93 | rootCmd.SetOutput(&b) |
| 94 | initRootCmd() |
| 95 | |
| 96 | if err := rootCmd.ParseFlags([]string{"-v"}); err != nil { |
| 97 | t.Fatalf("exepected nil; got %v", err) |
| 98 | } |
| 99 | if got, exp := showVersion, true; got != exp { |
| 100 | t.Fatalf("expected %v; got %v", exp, got) |
| 101 | } |
| 102 | if err := rootCmd.Execute(); err != nil { |
| 103 | t.Fatalf("exepected nil; got %v", err) |
| 104 | } |
| 105 | if got, exp := b.String(), versionOutput; got != exp { |
| 106 | t.Fatalf("expected %q; got %q", exp, got) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func TestUsage(t *testing.T) { |
| 111 | var b bytes.Buffer |
nothing calls this directly
no test coverage detected