|
| 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