MCPcopy Create free account
hub / github.com/cli/cli / Test_printError

Function Test_printError

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

Source from the content-addressed store, hash-verified

24)
25
26func Test_printError(t *testing.T) {
27 rootCmd := &cobra.Command{Use: "gh"}
28 cmd := &cobra.Command{
29 Use: "spend",
30 Short: "Spend money",
31 Example: heredoc.Doc(`
32 $ gh spend --amount 1
33 `),
34 }
35 cmd.Flags().Int("amount", 0, "How much to spend")
36 rootCmd.AddCommand(cmd)
37
38 type args struct {
39 err error
40 cmd *cobra.Command
41 debug bool
42 fullHelp bool
43 }
44 tests := []struct {
45 name string
46 args args
47 wantOut string
48 }{
49 {
50 name: "generic error",
51 args: args{
52 err: errors.New("the app exploded"),
53 cmd: nil,
54 debug: false,
55 },
56 wantOut: "the app exploded\n",
57 },
58 {
59 name: "DNS error",
60 args: args{
61 err: fmt.Errorf("DNS oopsie: %w", &net.DNSError{
62 Name: "api.github.com",
63 }),
64 cmd: nil,
65 debug: false,
66 },
67 wantOut: `error connecting to api.github.com
68check your internet connection or https://githubstatus.com
69`,
70 },
71 {
72 name: "Cobra flag error",
73 args: args{
74 err: cmdutil.FlagErrorf("unknown flag --foo"),
75 cmd: cmd,
76 debug: false,
77 },
78 wantOut: "unknown flag --foo\n\n" + cmd.UsageString() + "\n",
79 },
80 {
81 name: "unknown Cobra command error",
82 args: args{
83 err: errors.New("unknown command foo"),

Callers

nothing calls this directly

Calls 8

FlagErrorfFunction · 0.92
TestFunction · 0.92
ColorSchemeMethod · 0.80
EqualMethod · 0.80
printErrorFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected