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

Function TestPrintUnchanged

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

Source from the content-addressed store, hash-verified

121}
122
123func TestPrintUnchanged(t *testing.T) {
124 tests := []struct {
125 name string
126 tty bool
127 color bool
128 result Result
129 message string
130 reason string
131 wantStdout string
132 wantStderr string
133 }{
134 {
135 name: "in a terminal, the warning goes to stderr, and stdout stays empty",
136 tty: true,
137 result: Result{Number: 2, Name: "OAuth callback plan"},
138 message: "Artifact 2 (OAuth callback plan) on monalisa/monas-cafe#142 already matches version 12",
139 reason: "already matches version 12",
140 wantStderr: "! Artifact 2 (OAuth callback plan) on monalisa/monas-cafe#142 already matches version 12\n",
141 },
142 {
143 name: "colors in a terminal",
144 tty: true,
145 color: true,
146 result: Result{Number: 2, Name: "OAuth callback plan"},
147 message: "Artifact 2 (OAuth callback plan) on monalisa/monas-cafe#142 already matches version 12",
148 reason: "already matches version 12",
149 wantStderr: "\x1b[0;33m!\x1b[0m Artifact 2 (OAuth callback plan) on monalisa/monas-cafe#142 already matches version 12\n",
150 },
151 {
152 name: "piped, a skipped line with the reason goes to stdout",
153 result: Result{Number: 2, Name: "OAuth callback plan"},
154 message: "Artifact 2 (OAuth callback plan) on monalisa/monas-cafe#142 already matches version 12",
155 reason: "already matches version 12",
156 wantStdout: "skipped\t2\tOAuth callback plan\t\talready matches version 12\n",
157 },
158 }
159
160 for _, tt := range tests {
161 t.Run(tt.name, func(t *testing.T) {
162 ios, _, stdout, stderr := iostreams.Test()
163 ios.SetStdinTTY(tt.tty)
164 ios.SetStdoutTTY(tt.tty)
165 ios.SetStderrTTY(tt.tty)
166 ios.SetColorEnabled(tt.color)
167
168 PrintUnchanged(ios, tt.result, tt.message, tt.reason)
169
170 assert.Equal(t, tt.wantStdout, stdout.String())
171 assert.Equal(t, tt.wantStderr, stderr.String())
172 })
173 }
174}
175
176func TestPrintFailure(t *testing.T) {
177 artifactURL := func(number string) *url.URL {

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected