|
3 | 3 | package pipeline |
4 | 4 |
|
5 | 5 | import ( |
6 | | - "io" |
7 | 6 | "reflect" |
8 | 7 | "testing" |
9 | 8 |
|
10 | | - "github.com/sirupsen/logrus" |
11 | | - |
12 | 9 | "github.com/go-vela/server/compiler/types/pipeline" |
13 | 10 | ) |
14 | 11 |
|
@@ -91,6 +88,55 @@ func TestCollectMissingSecrets(t *testing.T) { |
91 | 88 | }, |
92 | 89 | want: map[string]string{"[stage: stage1][step: step1]": "STAGE_SECRET"}, |
93 | 90 | }, |
| 91 | + { |
| 92 | + name: "secret plugin - supplied", |
| 93 | + pipeline: &pipeline.Build{ |
| 94 | + Steps: []*pipeline.Container{ |
| 95 | + { |
| 96 | + Name: "step1", |
| 97 | + }, |
| 98 | + }, |
| 99 | + Secrets: []*pipeline.Secret{ |
| 100 | + { |
| 101 | + Origin: &pipeline.Container{ |
| 102 | + Name: "secret from elsewhere", |
| 103 | + Secrets: pipeline.StepSecretSlice{ |
| 104 | + { |
| 105 | + Source: "source", |
| 106 | + Target: "SECRET_FOR_SECRET", |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + envVars: map[string]string{"SECRET_FOR_SECRET": "value"}, |
| 114 | + want: map[string]string{}, |
| 115 | + }, |
| 116 | + { |
| 117 | + name: "secret plugin - missing", |
| 118 | + pipeline: &pipeline.Build{ |
| 119 | + Steps: []*pipeline.Container{ |
| 120 | + { |
| 121 | + Name: "step1", |
| 122 | + }, |
| 123 | + }, |
| 124 | + Secrets: []*pipeline.Secret{ |
| 125 | + { |
| 126 | + Origin: &pipeline.Container{ |
| 127 | + Name: "secret from elsewhere", |
| 128 | + Secrets: pipeline.StepSecretSlice{ |
| 129 | + { |
| 130 | + Source: "source", |
| 131 | + Target: "SECRET_FOR_SECRET", |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, |
| 137 | + }, |
| 138 | + want: map[string]string{"[secret: secret from elsewhere]": "SECRET_FOR_SECRET"}, |
| 139 | + }, |
94 | 140 | { |
95 | 141 | name: "provided step secret but value empty", |
96 | 142 | pipeline: &pipeline.Build{ |
@@ -133,6 +179,53 @@ func TestCollectMissingSecrets(t *testing.T) { |
133 | 179 | } |
134 | 180 | } |
135 | 181 |
|
| 182 | +func TestFormatStepIdentifier(t *testing.T) { |
| 183 | + tests := []struct { |
| 184 | + name string |
| 185 | + stageName string |
| 186 | + stepName string |
| 187 | + isSecret bool |
| 188 | + want string |
| 189 | + }{ |
| 190 | + { |
| 191 | + name: "basic format", |
| 192 | + stageName: "build", |
| 193 | + stepName: "test", |
| 194 | + isSecret: false, |
| 195 | + want: "[stage: build][step: test]", |
| 196 | + }, |
| 197 | + { |
| 198 | + name: "empty stage name", |
| 199 | + stageName: "", |
| 200 | + stepName: "test", |
| 201 | + isSecret: false, |
| 202 | + want: "[step: test]", |
| 203 | + }, |
| 204 | + { |
| 205 | + name: "secret format", |
| 206 | + stageName: "", |
| 207 | + stepName: "test", |
| 208 | + isSecret: true, |
| 209 | + want: "[secret: test]", |
| 210 | + }, |
| 211 | + { |
| 212 | + name: "empty stage and step name", |
| 213 | + stageName: "", |
| 214 | + stepName: "", |
| 215 | + isSecret: false, |
| 216 | + want: "", |
| 217 | + }, |
| 218 | + } |
| 219 | + |
| 220 | + for _, tt := range tests { |
| 221 | + t.Run(tt.name, func(t *testing.T) { |
| 222 | + if got := formatStepIdentifier(tt.stageName, tt.stepName, tt.isSecret); got != tt.want { |
| 223 | + t.Errorf("formatStepIdentifier() = %v, want %v", got, tt.want) |
| 224 | + } |
| 225 | + }) |
| 226 | + } |
| 227 | +} |
| 228 | + |
136 | 229 | func TestSkipSteps(t *testing.T) { |
137 | 230 | tests := []struct { |
138 | 231 | name string |
@@ -267,44 +360,3 @@ func TestSkipSteps(t *testing.T) { |
267 | 360 | }) |
268 | 361 | } |
269 | 362 | } |
270 | | - |
271 | | -func TestFormatStepIdentifier(t *testing.T) { |
272 | | - tests := []struct { |
273 | | - name string |
274 | | - stageName string |
275 | | - stepName string |
276 | | - want string |
277 | | - }{ |
278 | | - { |
279 | | - name: "basic format", |
280 | | - stageName: "build", |
281 | | - stepName: "test", |
282 | | - want: "[stage: build][step: test]", |
283 | | - }, |
284 | | - { |
285 | | - name: "empty stage name", |
286 | | - stageName: "", |
287 | | - stepName: "test", |
288 | | - want: "[step: test]", |
289 | | - }, |
290 | | - { |
291 | | - name: "empty stage and step name", |
292 | | - stageName: "", |
293 | | - stepName: "", |
294 | | - want: "", |
295 | | - }, |
296 | | - } |
297 | | - |
298 | | - for _, tt := range tests { |
299 | | - t.Run(tt.name, func(t *testing.T) { |
300 | | - if got := formatStepIdentifier(tt.stageName, tt.stepName); got != tt.want { |
301 | | - t.Errorf("formatStepIdentifier() = %v, want %v", got, tt.want) |
302 | | - } |
303 | | - }) |
304 | | - } |
305 | | -} |
306 | | - |
307 | | -func init() { |
308 | | - // discard logs for tests |
309 | | - logrus.SetOutput(io.Discard) |
310 | | -} |
|
0 commit comments