Skip to content

Commit c5dccbf

Browse files
committedApr 9, 2021
add/modify e2e and unit tests
* convert add bundle unit test to e2e test * add registry bundle conversion unit test Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent c7cec80 commit c5dccbf

File tree

7 files changed

+274
-200
lines changed

7 files changed

+274
-200
lines changed
 

‎pkg/action/add_bundle_test.go

-98
This file was deleted.

‎pkg/action/bundle_extractor.go

-14
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,3 @@ func (i imageBundleExtractor) ExtractBundle(ctx context.Context) (*registry.Bund
6868
}
6969
return img.Bundle, nil
7070
}
71-
72-
type DirBundleExtractor string
73-
74-
func NewDirBundleExtractor(path string) DirBundleExtractor {
75-
return DirBundleExtractor(path)
76-
}
77-
func (d DirBundleExtractor) ExtractBundle(ctx context.Context) (*registry.Bundle, error) {
78-
79-
img, err := registry.NewImageInput(image.SimpleReference(""), string(d))
80-
if err != nil {
81-
return nil, fmt.Errorf("error creating registry bundle from %q: %v", d, err)
82-
}
83-
return img.Bundle, nil
84-
}

‎pkg/action/test-configs/etcd/etcd.json

-83
This file was deleted.

‎pkg/registry/registry_to_model.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ func convertRegistryBundleToModelProperties(b *Bundle) ([]property.Property, err
125125
k := property.GVK{Group: v.Group, Kind: v.Kind, Version: v.Version}
126126
providedGVKs[k] = struct{}{}
127127
case property.TypePackage:
128-
foundPackageProperty = true
129-
out = append(out, property.Property{
130-
Type: property.TypePackage,
131-
Value: json.RawMessage(p.Value),
132-
})
128+
var v property.Package
129+
if err := json.Unmarshal(json.RawMessage(p.Value), &v); err != nil {
130+
return nil, property.ParseError{Idx: i, Typ: p.Type, Err: err}
131+
}
132+
out = append(out, property.MustBuildPackageRequired(v.PackageName, v.Version))
133133
default:
134134
out = append(out, property.Property{
135135
Type: p.Type,
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package registry
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/operator-framework/operator-registry/internal/model"
10+
"github.com/operator-framework/operator-registry/internal/property"
11+
"github.com/operator-framework/operator-registry/pkg/image"
12+
)
13+
14+
func TestConvertRegistryBundleToModelBundle(t *testing.T) {
15+
registryBundle, err := testRegistryBundle()
16+
assert.NoError(t, err)
17+
expected := testModelBundle()
18+
19+
actual, err := registryBundleToModelBundle(registryBundle)
20+
require.NoError(t, err)
21+
assertEqualsModelBundle(t, expected, *actual)
22+
23+
registryBundles, err := ConvertRegistryBundleToModelBundles(registryBundle)
24+
assert.Equal(t, len(registryBundles), 2)
25+
}
26+
27+
func testModelBundle() model.Bundle {
28+
b := model.Bundle{
29+
Name: "etcdoperator.v0.9.2",
30+
Image: "quay.io/operatorhubio/etcd:v0.9.2",
31+
Replaces: "etcdoperator.v0.9.0",
32+
Skips: []string{"etcdoperator.v0.9.1"},
33+
Properties: []property.Property{
34+
property.MustBuildChannel("alpha", "etcdoperator.v0.9.0"),
35+
property.MustBuildChannel("stable", "etcdoperator.v0.9.0"),
36+
property.MustBuildPackage("etcd", "0.9.2"),
37+
property.MustBuildSkips("etcdoperator.v0.9.1"),
38+
//TODO(anik120): check if etcdclusters. is supposed to be prefixed
39+
property.MustBuildGVKRequired("etcd.database.coreos.com", "v1beta2", "EtcdCluster"),
40+
property.MustBuildGVKRequired("testapi.coreos.com", "v1", "testapi"),
41+
//TODO(anik120): check if etcdclusters. is supposed to be prefixed
42+
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdCluster"),
43+
//TODO(anik120): check if etcdbackups. is supposed to be prefixed
44+
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdBackup"),
45+
//TODO(anik120): check if etcdrestores. is supposed to be prefixed
46+
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdRestore"),
47+
},
48+
}
49+
return b
50+
}
51+
52+
func testRegistryBundle() (*Bundle, error) {
53+
input, err := NewImageInput(image.SimpleReference("quay.io/operatorhubio/etcd:v0.9.2"), "../../bundles/etcd.0.9.2")
54+
if err != nil {
55+
return nil, err
56+
}
57+
return input.Bundle, nil
58+
}
59+
60+
func assertEqualsModelBundle(t *testing.T, a, b model.Bundle) bool {
61+
assert.ElementsMatch(t, a.Properties, b.Properties)
62+
assert.ElementsMatch(t, a.Skips, b.Skips)
63+
assert.ElementsMatch(t, a.RelatedImages, b.RelatedImages)
64+
65+
a.Properties, b.Properties = nil, nil
66+
a.Objects, b.Objects = nil, nil
67+
a.Skips, b.Skips = nil, nil
68+
a.RelatedImages, b.RelatedImages = nil, nil
69+
70+
return assert.Equal(t, a, b)
71+
}

0 commit comments

Comments
 (0)