|
1 | 1 | package payload |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "fmt" |
5 | 6 | "os" |
6 | 7 | "path/filepath" |
@@ -64,47 +65,77 @@ func TestRenderManifest(t *testing.T) { |
64 | 65 | } |
65 | 66 |
|
66 | 67 | func Test_cvoManifests(t *testing.T) { |
67 | | - installDir := filepath.Join("../../install") |
68 | | - files, err := os.ReadDir(installDir) |
69 | | - if err != nil { |
70 | | - t.Fatalf("failed to read directory: %v", err) |
| 68 | + config := manifestRenderConfig{ |
| 69 | + ReleaseImage: "quay.io/cvo/release:latest", |
| 70 | + ClusterProfile: "some-profile", |
71 | 71 | } |
72 | 72 |
|
73 | | - if len(files) == 0 { |
74 | | - t.Fatalf("no files found in %s", installDir) |
| 73 | + tests := []struct { |
| 74 | + name string |
| 75 | + dir string |
| 76 | + }{ |
| 77 | + { |
| 78 | + name: "install dir", |
| 79 | + dir: filepath.Join("../../install"), |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "bootstrap dir", |
| 83 | + dir: filepath.Join("../../bootstrap"), |
| 84 | + }, |
75 | 85 | } |
| 86 | + for _, tt := range tests { |
| 87 | + t.Run(tt.name, func(t *testing.T) { |
| 88 | + files, err := os.ReadDir(tt.dir) |
| 89 | + if err != nil { |
| 90 | + t.Fatalf("failed to read directory: %v", err) |
| 91 | + } |
76 | 92 |
|
77 | | - var manifestsWithoutIncludeAnnotation []manifest.Manifest |
78 | | - const prefix = "include.release.openshift.io/" |
79 | | - for _, manifestFile := range files { |
80 | | - if manifestFile.IsDir() { |
81 | | - continue |
82 | | - } |
83 | | - filePath := filepath.Join(installDir, manifestFile.Name()) |
84 | | - manifests, err := manifest.ManifestsFromFiles([]string{filePath}) |
85 | | - if err != nil { |
86 | | - t.Fatalf("failed to load manifests: %v", err) |
87 | | - } |
| 93 | + if len(files) == 0 { |
| 94 | + t.Fatalf("no files found in %s", tt.dir) |
| 95 | + } |
88 | 96 |
|
89 | | - for _, m := range manifests { |
90 | | - var found bool |
91 | | - for k := range m.Obj.GetAnnotations() { |
92 | | - if strings.HasPrefix(k, prefix) { |
93 | | - found = true |
94 | | - break |
| 97 | + var manifestsWithoutIncludeAnnotation []manifest.Manifest |
| 98 | + const prefix = "include.release.openshift.io/" |
| 99 | + for _, manifestFile := range files { |
| 100 | + if manifestFile.IsDir() { |
| 101 | + continue |
| 102 | + } |
| 103 | + filePath := filepath.Join(tt.dir, manifestFile.Name()) |
| 104 | + data, err := os.ReadFile(filePath) |
| 105 | + if err != nil { |
| 106 | + t.Fatalf("failed to read manifest file: %v", err) |
| 107 | + } |
| 108 | + data, err = renderManifest(config, data) |
| 109 | + if err != nil { |
| 110 | + t.Fatalf("failed to render manifest: %v", err) |
| 111 | + } |
| 112 | + manifests, err := manifest.ParseManifests(bytes.NewReader(data)) |
| 113 | + if err != nil { |
| 114 | + t.Fatalf("failed to load manifests: %v", err) |
| 115 | + } |
| 116 | + |
| 117 | + for _, m := range manifests { |
| 118 | + m.OriginalFilename = filePath |
| 119 | + var found bool |
| 120 | + for k := range m.Obj.GetAnnotations() { |
| 121 | + if strings.HasPrefix(k, prefix) { |
| 122 | + found = true |
| 123 | + break |
| 124 | + } |
| 125 | + } |
| 126 | + if !found { |
| 127 | + manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m) |
| 128 | + } |
95 | 129 | } |
96 | 130 | } |
97 | | - if !found { |
98 | | - manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m) |
99 | | - } |
100 | | - } |
101 | | - } |
102 | 131 |
|
103 | | - if len(manifestsWithoutIncludeAnnotation) > 0 { |
104 | | - var messages []string |
105 | | - for _, m := range manifestsWithoutIncludeAnnotation { |
106 | | - messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace())) |
107 | | - } |
108 | | - t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '")) |
| 132 | + if len(manifestsWithoutIncludeAnnotation) > 0 { |
| 133 | + var messages []string |
| 134 | + for _, m := range manifestsWithoutIncludeAnnotation { |
| 135 | + messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace())) |
| 136 | + } |
| 137 | + t.Fatalf("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s", prefix, strings.Join(messages, "', '")) |
| 138 | + } |
| 139 | + }) |
109 | 140 | } |
110 | 141 | } |
0 commit comments