(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func 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 | |
| 176 | func TestPrintFailure(t *testing.T) { |
| 177 | artifactURL := func(number string) *url.URL { |
nothing calls this directly
no test coverage detected