(t *testing.T)
| 125 | } |
| 126 | |
| 127 | func TestShowErrorOnly(t *testing.T) { |
| 128 | expErr := errors.New("error") |
| 129 | cmd := &cobra.Command{ |
| 130 | Use: "test-only", |
| 131 | RunE: func(cmd *cobra.Command, args []string) error { |
| 132 | return expErr |
| 133 | }, |
| 134 | } |
| 135 | var b bytes.Buffer |
| 136 | rootCmd.ResetFlags() |
| 137 | rootCmd.SetOutput(&b) |
| 138 | rootCmd.AddCommand(cmd) |
| 139 | initRootCmd() |
| 140 | rootCmd.SetArgs([]string{"test-only"}) |
| 141 | if err := rootCmd.Execute(); err != expErr { |
| 142 | t.Fatalf("exepected %v; got %v", expErr, err) |
| 143 | } |
| 144 | if got, exp := b.String(), "Error: error\n"; got != exp { |
| 145 | t.Fatalf("expected %#v; got %q", exp, got) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | type unauthedError struct{} |
| 150 |
nothing calls this directly
no test coverage detected