-
Notifications
You must be signed in to change notification settings - Fork 48
/
variable_source_test.go
139 lines (128 loc) · 4.46 KB
/
variable_source_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package controllers_test
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/constraint"
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/property"
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/controllers"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
testutil "github.com/operator-framework/operator-controller/test/util"
)
func TestVariableSource(t *testing.T) {
sch := runtime.NewScheme()
utilruntime.Must(operatorsv1alpha1.AddToScheme(sch))
utilruntime.Must(rukpakv1alpha1.AddToScheme(sch))
stableChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
Name: "stable",
Entries: []declcfg.ChannelEntry{
{
Name: "packageA.v2.0.0",
},
},
}}
bundleSet := map[string]*catalogmetadata.Bundle{
"packageA.v2.0.0": {
Bundle: declcfg.Bundle{
Name: "packageA.v2.0.0",
Package: "packageA",
Image: "foo.io/packageA/packageA:v2.0.0",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"packageA","version":"2.0.0"}`)},
},
},
CatalogName: "fake-catalog",
InChannels: []*catalogmetadata.Channel{&stableChannel},
},
}
allBundles := make([]*catalogmetadata.Bundle, 0, len(bundleSet))
for _, bundle := range bundleSet {
allBundles = append(allBundles, bundle)
}
pkgName := "packageA"
opName := fmt.Sprintf("operator-test-%s", rand.String(8))
operator := &operatorsv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{Name: opName},
Spec: operatorsv1alpha1.OperatorSpec{
PackageName: pkgName,
Channel: "stable",
Version: "2.0.0",
},
}
bd := &rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: opName,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: operatorsv1alpha1.GroupVersion.String(),
Kind: "Operator",
Name: operator.Name,
UID: operator.UID,
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
},
},
},
Spec: rukpakv1alpha1.BundleDeploymentSpec{
ProvisionerClassName: "core-rukpak-io-plain",
Template: &rukpakv1alpha1.BundleTemplate{
Spec: rukpakv1alpha1.BundleSpec{
ProvisionerClassName: "core-rukpak-io-registry",
Source: rukpakv1alpha1.BundleSource{
Type: rukpakv1alpha1.SourceTypeImage,
Image: &rukpakv1alpha1.ImageSource{
Ref: "foo.io/packageA/packageA:v2.0.0",
},
},
},
},
},
}
fakeClient := fake.NewClientBuilder().WithScheme(sch).WithObjects(operator, bd).Build()
fakeCatalogClient := testutil.NewFakeCatalogClient(allBundles)
vs := controllers.NewVariableSource(fakeClient, &fakeCatalogClient)
vars, err := vs.GetVariables(context.Background())
require.NoError(t, err)
expectedVars := []deppy.Variable{
olmvariables.NewRequiredPackageVariable("packageA", []*catalogmetadata.Bundle{
bundleSet["packageA.v2.0.0"],
}),
olmvariables.NewInstalledPackageVariable("packageA", []*catalogmetadata.Bundle{
bundleSet["packageA.v2.0.0"],
}),
olmvariables.NewBundleVariable(bundleSet["packageA.v2.0.0"], nil),
olmvariables.NewBundleUniquenessVariable(
"packageA package uniqueness",
deppy.Identifier("fake-catalog-packageA-packageA.v2.0.0"),
),
}
gocmpopts := []cmp.Option{
cmpopts.IgnoreUnexported(catalogmetadata.Bundle{}),
cmp.AllowUnexported(
olmvariables.RequiredPackageVariable{},
olmvariables.InstalledPackageVariable{},
olmvariables.BundleVariable{},
olmvariables.BundleUniquenessVariable{},
input.SimpleVariable{},
constraint.DependencyConstraint{},
constraint.AtMostConstraint{},
),
}
require.Empty(t, cmp.Diff(vars, expectedVars, gocmpopts...))
}