|
1 | 1 | package payload |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "fmt" |
5 | 6 | "os" |
6 | 7 | "path/filepath" |
@@ -308,47 +309,77 @@ data: |
308 | 309 | return yaml |
309 | 310 | } |
310 | 311 | func Test_cvoManifests(t *testing.T) { |
311 | | - installDir := filepath.Join("../../install") |
312 | | - files, err := os.ReadDir(installDir) |
313 | | - if err != nil { |
314 | | - t.Fatalf("failed to read directory: %v", err) |
| 312 | + config := manifestRenderConfig{ |
| 313 | + ReleaseImage: "quay.io/cvo/release:latest", |
| 314 | + ClusterProfile: "some-profile", |
315 | 315 | } |
316 | 316 |
|
317 | | - if len(files) == 0 { |
318 | | - t.Fatalf("no files found in %s", installDir) |
| 317 | + tests := []struct { |
| 318 | + name string |
| 319 | + dir string |
| 320 | + }{ |
| 321 | + { |
| 322 | + name: "install dir", |
| 323 | + dir: filepath.Join("../../install"), |
| 324 | + }, |
| 325 | + { |
| 326 | + name: "bootstrap dir", |
| 327 | + dir: filepath.Join("../../bootstrap"), |
| 328 | + }, |
319 | 329 | } |
| 330 | + for _, tt := range tests { |
| 331 | + t.Run(tt.name, func(t *testing.T) { |
| 332 | + files, err := os.ReadDir(tt.dir) |
| 333 | + if err != nil { |
| 334 | + t.Fatalf("failed to read directory: %v", err) |
| 335 | + } |
320 | 336 |
|
321 | | - var manifestsWithoutIncludeAnnotation []manifest.Manifest |
322 | | - const prefix = "include.release.openshift.io/" |
323 | | - for _, manifestFile := range files { |
324 | | - if manifestFile.IsDir() { |
325 | | - continue |
326 | | - } |
327 | | - filePath := filepath.Join(installDir, manifestFile.Name()) |
328 | | - manifests, err := manifest.ManifestsFromFiles([]string{filePath}) |
329 | | - if err != nil { |
330 | | - t.Fatalf("failed to load manifests: %v", err) |
331 | | - } |
| 337 | + if len(files) == 0 { |
| 338 | + t.Fatalf("no files found in %s", tt.dir) |
| 339 | + } |
332 | 340 |
|
333 | | - for _, m := range manifests { |
334 | | - var found bool |
335 | | - for k := range m.Obj.GetAnnotations() { |
336 | | - if strings.HasPrefix(k, prefix) { |
337 | | - found = true |
338 | | - break |
| 341 | + var manifestsWithoutIncludeAnnotation []manifest.Manifest |
| 342 | + const prefix = "include.release.openshift.io/" |
| 343 | + for _, manifestFile := range files { |
| 344 | + if manifestFile.IsDir() { |
| 345 | + continue |
| 346 | + } |
| 347 | + filePath := filepath.Join(tt.dir, manifestFile.Name()) |
| 348 | + data, err := os.ReadFile(filePath) |
| 349 | + if err != nil { |
| 350 | + t.Fatalf("failed to read manifest file: %v", err) |
| 351 | + } |
| 352 | + data, err = renderManifest(config, data) |
| 353 | + if err != nil { |
| 354 | + t.Fatalf("failed to render manifest: %v", err) |
| 355 | + } |
| 356 | + manifests, err := manifest.ParseManifests(bytes.NewReader(data)) |
| 357 | + if err != nil { |
| 358 | + t.Fatalf("failed to load manifests: %v", err) |
| 359 | + } |
| 360 | + |
| 361 | + for _, m := range manifests { |
| 362 | + m.OriginalFilename = filePath |
| 363 | + var found bool |
| 364 | + for k := range m.Obj.GetAnnotations() { |
| 365 | + if strings.HasPrefix(k, prefix) { |
| 366 | + found = true |
| 367 | + break |
| 368 | + } |
| 369 | + } |
| 370 | + if !found { |
| 371 | + manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m) |
| 372 | + } |
339 | 373 | } |
340 | 374 | } |
341 | | - if !found { |
342 | | - manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m) |
343 | | - } |
344 | | - } |
345 | | - } |
346 | 375 |
|
347 | | - if len(manifestsWithoutIncludeAnnotation) > 0 { |
348 | | - var messages []string |
349 | | - for _, m := range manifestsWithoutIncludeAnnotation { |
350 | | - messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace())) |
351 | | - } |
352 | | - t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '")) |
| 376 | + if len(manifestsWithoutIncludeAnnotation) > 0 { |
| 377 | + var messages []string |
| 378 | + for _, m := range manifestsWithoutIncludeAnnotation { |
| 379 | + messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace())) |
| 380 | + } |
| 381 | + t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '")) |
| 382 | + } |
| 383 | + }) |
353 | 384 | } |
354 | 385 | } |
0 commit comments