|
1 | 1 | package payload |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "os" |
| 6 | + "path/filepath" |
5 | 7 | "strings" |
6 | 8 | "testing" |
7 | 9 |
|
8 | 10 | "github.com/google/go-cmp/cmp" |
| 11 | + |
| 12 | + "github.com/openshift/library-go/pkg/manifest" |
9 | 13 | ) |
10 | 14 |
|
11 | 15 | func TestRenderManifest(t *testing.T) { |
@@ -58,3 +62,49 @@ func TestRenderManifest(t *testing.T) { |
58 | 62 | }) |
59 | 63 | } |
60 | 64 | } |
| 65 | + |
| 66 | +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) |
| 71 | + } |
| 72 | + |
| 73 | + if len(files) == 0 { |
| 74 | + t.Fatalf("no files found in %s", installDir) |
| 75 | + } |
| 76 | + |
| 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 | + } |
| 88 | + |
| 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 |
| 95 | + } |
| 96 | + } |
| 97 | + if !found { |
| 98 | + manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m) |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 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, "', '")) |
| 109 | + } |
| 110 | +} |
0 commit comments