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

Function TestPrintSuccess

pkg/cmd/issue/artifact/shared/results_test.go:16–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestPrintSuccess(t *testing.T) {
17 tests := []struct {
18 name string
19 tty bool
20 status string
21 result Result
22 message string
23 wantStdout string
24 }{
25 {
26 name: "in a terminal, the icon and message go to stdout",
27 tty: true,
28 status: "deleted",
29 result: Result{Number: 2, Name: "OAuth callback plan"},
30 message: "Deleted artifact 2 (OAuth callback plan) from monalisa/monas-cafe#142",
31 wantStdout: "✓ Deleted artifact 2 (OAuth callback plan) from monalisa/monas-cafe#142\n",
32 },
33 {
34 name: "piped, every column is printed, with an empty source and reason",
35 status: "deleted",
36 result: Result{Number: 2, Name: "OAuth callback plan"},
37 message: "Deleted artifact 2 (OAuth callback plan) from monalisa/monas-cafe#142",
38 wantStdout: "deleted\t2\tOAuth callback plan\t\t\n",
39 },
40 {
41 name: "piped, with a source",
42 status: "created",
43 result: Result{Number: 6, Name: "signin-plan.md", Source: "docs/signin-plan.md"},
44 message: "Created artifact 6 (signin-plan.md) on monalisa/monas-cafe#142",
45 wantStdout: "created\t6\tsignin-plan.md\tdocs/signin-plan.md\t\n",
46 },
47 {
48 name: "piped, the name is printed as given, since a path can hold any spaces",
49 status: "written",
50 result: Result{Number: 2, Name: "cafe notes/2-OAuth-callback-plan.md"},
51 message: "cafe notes/2-OAuth-callback-plan.md",
52 wantStdout: "written\t2\tcafe notes/2-OAuth-callback-plan.md\t\t\n",
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 ios, _, stdout, stderr := iostreams.Test()
59 ios.SetStdinTTY(tt.tty)
60 ios.SetStdoutTTY(tt.tty)
61 ios.SetStderrTTY(tt.tty)
62
63 PrintSuccess(ios, tt.status, tt.result, "✓", tt.message)
64
65 assert.Equal(t, tt.wantStdout, stdout.String())
66 assert.Equal(t, "", stderr.String())
67 })
68 }
69}
70
71func TestPrintSkip(t *testing.T) {
72 tests := []struct {

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
PrintSuccessFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected