MCPcopy
hub / github.com/cli/cli / Test_printError

Function Test_printError

internal/ghcmd/cmd_test.go:21–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func 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
53check 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{}

Callers

nothing calls this directly

Calls 5

FlagErrorfFunction · 0.92
printErrorFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected