@@ -3,10 +3,11 @@ package convert_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/operator-framework/operator-controller/internal/rukpak/convert "
6
+ "io/fs "
7
7
"os"
8
8
"strings"
9
9
"testing"
10
+ "testing/fstest"
10
11
11
12
"github.com/stretchr/testify/require"
12
13
appsv1 "k8s.io/api/apps/v1"
@@ -21,12 +22,17 @@ import (
21
22
22
23
"github.com/operator-framework/api/pkg/operators/v1alpha1"
23
24
"github.com/operator-framework/operator-registry/alpha/property"
25
+
26
+ "github.com/operator-framework/operator-controller/internal/rukpak/convert"
24
27
)
25
28
26
29
const (
27
30
olmNamespaces = "olm.targetNamespaces"
28
31
olmProperties = "olm.properties"
29
32
installNamespace = "testInstallNamespace"
33
+
34
+ bundlePathAnnotations = "metadata/annotations.yaml"
35
+ bundlePathCSV = "manifests/csv.yaml"
30
36
)
31
37
32
38
func getCsvAndService () (v1alpha1.ClusterServiceVersion , corev1.Service ) {
@@ -466,6 +472,48 @@ func TestRegistryV1SuiteReadBundleFileSystem(t *testing.T) {
466
472
require .JSONEq (t , `[{"type":"from-csv-annotations-key","value":"from-csv-annotations-value"},{"type":"from-file-key","value":"from-file-value"}]` , chrt .Metadata .Annotations [olmProperties ])
467
473
}
468
474
475
+ func TestParseFSFails (t * testing.T ) {
476
+ for _ , tt := range []struct {
477
+ name string
478
+ FS fs.FS
479
+ }{
480
+ {
481
+ name : "bundle missing ClusterServiceVersion manifest" ,
482
+ FS : removePaths (newBundleFS (), bundlePathCSV ),
483
+ }, {
484
+ name : "bundle missing metadata/annotations.yaml" ,
485
+ FS : removePaths (newBundleFS (), bundlePathAnnotations ),
486
+ }, {
487
+ name : "bundle missing metadata/ directory" ,
488
+ FS : removePaths (newBundleFS (), "metadata/" ),
489
+ }, {
490
+ name : "bundle missing manifests/ directory" ,
491
+ FS : removePaths (newBundleFS (), "manifests/" ),
492
+ },
493
+ } {
494
+ t .Run (tt .name , func (t * testing.T ) {
495
+ _ , err := convert .ParseFS (context .Background (), tt .FS )
496
+ require .Error (t , err )
497
+ })
498
+ }
499
+ }
500
+
501
+ func TestRegistryV1SuiteReadBundleFileSystemFailsOnNoCSV (t * testing.T ) {
502
+ t .Log ("convert.RegistryV1 Suite Convert" )
503
+ t .Log ("It should generate objects successfully based on target namespaces" )
504
+
505
+ t .Log ("It should read the registry+v1 bundle filesystem correctly" )
506
+ t .Log ("It should include metadata/properties.yaml and csv.metadata.annotations['olm.properties'] in chart metadata" )
507
+ fsys := os .DirFS ("testdata/combine-properties-bundle" )
508
+
509
+ chrt , err := convert .RegistryV1ToHelmChart (context .Background (), fsys , "" , nil )
510
+ require .NoError (t , err )
511
+ require .NotNil (t , chrt )
512
+ require .NotNil (t , chrt .Metadata )
513
+ require .Contains (t , chrt .Metadata .Annotations , olmProperties )
514
+ require .JSONEq (t , `[{"type":"from-csv-annotations-key","value":"from-csv-annotations-value"},{"type":"from-file-key","value":"from-file-value"}]` , chrt .Metadata .Annotations [olmProperties ])
515
+ }
516
+
469
517
func TestRegistryV1SuiteGenerateNoWebhooks (t * testing.T ) {
470
518
t .Log ("convert.RegistryV1 Suite Convert" )
471
519
t .Log ("It should generate objects successfully based on target namespaces" )
@@ -543,3 +591,40 @@ func findObjectByName(name string, result []client.Object) client.Object {
543
591
}
544
592
return nil
545
593
}
594
+
595
+ func newBundleFS () fstest.MapFS {
596
+ annotationsYml := `
597
+ annotations:
598
+ operators.operatorframework.io.bundle.mediatype.v1: registry+v1
599
+ operators.operatorframework.io.bundle.package.v1: test
600
+ `
601
+
602
+ csvYml := `
603
+ apiVersion: operators.operatorframework.io/v1alpha1
604
+ kind: ClusterServiceVersion
605
+ metadata:
606
+ name: test.v1.0.0
607
+ annotations:
608
+ olm.properties: '[{"type":"from-csv-annotations-key", "value":"from-csv-annotations-value"}]'
609
+ spec:
610
+ installModes:
611
+ - type: AllNamespaces
612
+ supported: true
613
+ `
614
+
615
+ return fstest.MapFS {
616
+ bundlePathAnnotations : & fstest.MapFile {Data : []byte (strings .Trim (annotationsYml , "\n " ))},
617
+ bundlePathCSV : & fstest.MapFile {Data : []byte (strings .Trim (csvYml , "\n " ))},
618
+ }
619
+ }
620
+
621
+ func removePaths (mapFs fstest.MapFS , paths ... string ) fstest.MapFS {
622
+ for k := range mapFs {
623
+ for _ , path := range paths {
624
+ if strings .HasPrefix (k , path ) {
625
+ delete (mapFs , k )
626
+ }
627
+ }
628
+ }
629
+ return mapFs
630
+ }
0 commit comments