11package payload
22
33import (
4+ "bytes"
5+ "fmt"
6+ "io/fs"
47 "os"
8+ "path/filepath"
59 "strings"
610 "testing"
711
@@ -12,6 +16,7 @@ import (
1216 "k8s.io/utils/ptr"
1317
1418 configv1 "github.com/openshift/api/config/v1"
19+ "github.com/openshift/library-go/pkg/manifest"
1520)
1621
1722func TestRenderManifest (t * testing.T ) {
@@ -304,3 +309,85 @@ data:
304309
305310 return yaml
306311}
312+ func Test_cvoManifests (t * testing.T ) {
313+ config := manifestRenderConfig {
314+ ReleaseImage : "quay.io/cvo/release:latest" ,
315+ ClusterProfile : "some-profile" ,
316+ }
317+
318+ tests := []struct {
319+ name string
320+ dir string
321+ }{
322+ {
323+ name : "install dir" ,
324+ dir : filepath .Join ("../../install" ),
325+ },
326+ {
327+ name : "bootstrap dir" ,
328+ dir : filepath .Join ("../../bootstrap" ),
329+ },
330+ }
331+ const prefix = "include.release.openshift.io/"
332+ for _ , tt := range tests {
333+ t .Run (tt .name , func (t * testing.T ) {
334+ var count int
335+ err := filepath .WalkDir (tt .dir , func (path string , d fs.DirEntry , err error ) error {
336+ if err != nil {
337+ return err
338+ }
339+
340+ if d .IsDir () {
341+ return nil
342+ }
343+
344+ var manifestsWithoutIncludeAnnotation []manifest.Manifest
345+ data , err := os .ReadFile (path )
346+ if err != nil {
347+ t .Fatalf ("failed to read manifest file: %v" , err )
348+ }
349+ data , err = renderManifest (config , data )
350+ if err != nil {
351+ t .Fatalf ("failed to render manifest: %v" , err )
352+ }
353+ manifests , err := manifest .ParseManifests (bytes .NewReader (data ))
354+ if err != nil {
355+ t .Fatalf ("failed to load manifests: %v" , err )
356+ }
357+
358+ for _ , m := range manifests {
359+ m .OriginalFilename = path
360+ var found bool
361+ for k := range m .Obj .GetAnnotations () {
362+ if strings .HasPrefix (k , prefix ) {
363+ found = true
364+ break
365+ }
366+ }
367+ if ! found {
368+ manifestsWithoutIncludeAnnotation = append (manifestsWithoutIncludeAnnotation , m )
369+ }
370+ }
371+
372+ if len (manifestsWithoutIncludeAnnotation ) > 0 {
373+ var messages []string
374+ for _ , m := range manifestsWithoutIncludeAnnotation {
375+ messages = append (messages , fmt .Sprintf ("%s/%s/%s/%s" , m .OriginalFilename , m .GVK , m .Obj .GetName (), m .Obj .GetNamespace ()))
376+ }
377+ t .Errorf ("Those manifests have no annotation with prefix %q and will not be installed by CVO: %s" , prefix , strings .Join (messages , ", " ))
378+ }
379+ count ++
380+ return nil
381+ })
382+
383+ if err != nil {
384+ t .Fatalf ("failed to walk directory: %v" , err )
385+ }
386+
387+ if count == 0 {
388+ t .Errorf ("no files found in %s" , tt .dir )
389+ }
390+
391+ })
392+ }
393+ }
0 commit comments