(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func Test_printError(t *testing.T) { |
| 22 | cmd := &cobra.Command{} |
| 23 | |
| 24 | type args struct { |
| 25 | err error |
| 26 | cmd *cobra.Command |
| 27 | debug bool |
| 28 | } |
| 29 | tests := []struct { |
| 30 | name string |
| 31 | args args |
| 32 | wantOut string |
| 33 | }{ |
| 34 | { |
| 35 | name: "generic error", |
| 36 | args: args{ |
| 37 | err: errors.New("the app exploded"), |
| 38 | cmd: nil, |
| 39 | debug: false, |
| 40 | }, |
| 41 | wantOut: "the app exploded\n", |
| 42 | }, |
| 43 | { |
| 44 | name: "DNS error", |
| 45 | args: args{ |
| 46 | err: fmt.Errorf("DNS oopsie: %w", &net.DNSError{ |
| 47 | Name: "api.github.com", |
| 48 | }), |
| 49 | cmd: nil, |
| 50 | debug: false, |
| 51 | }, |
| 52 | wantOut: `error connecting to api.github.com |
| 53 | check your internet connection or https://githubstatus.com |
| 54 | `, |
| 55 | }, |
| 56 | { |
| 57 | name: "Cobra flag error", |
| 58 | args: args{ |
| 59 | err: cmdutil.FlagErrorf("unknown flag --foo"), |
| 60 | cmd: cmd, |
| 61 | debug: false, |
| 62 | }, |
| 63 | wantOut: "unknown flag --foo\n\nUsage:\n\n", |
| 64 | }, |
| 65 | { |
| 66 | name: "unknown Cobra command error", |
| 67 | args: args{ |
| 68 | err: errors.New("unknown command foo"), |
| 69 | cmd: cmd, |
| 70 | debug: false, |
| 71 | }, |
| 72 | wantOut: "unknown command foo\n\nUsage:\n\n", |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | for _, tt := range tests { |
| 77 | t.Run(tt.name, func(t *testing.T) { |
| 78 | out := &bytes.Buffer{} |
nothing calls this directly
no test coverage detected