@@ -43,6 +43,78 @@ func (l *fakeCatalogSourceLister) CatalogSources(namespace string) listersv1alph
43
43
return nil
44
44
}
45
45
46
+ func TestNewDefaultSatResolver_NoClusterRuntimeConstraints (t * testing.T ) {
47
+ // Ensure no runtime constraints are loaded if the runtime constraints env
48
+ // var is not set
49
+ sourceProvider := & fakeSourceProvider {}
50
+ catSrcLister := & fakeCatalogSourceLister {}
51
+ logger := logrus .New ()
52
+
53
+ // Unset the runtime constraints file path environment variable
54
+ // signaling that no runtime constraints should be considered by the resolver
55
+ require .Nil (t , os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ))
56
+ resolver := NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
57
+ require .Nil (t , resolver .runtimeConstraintsProvider )
58
+ }
59
+
60
+ func TestNewDefaultSatResolver_BadClusterRuntimeConstraintsEnvVar (t * testing.T ) {
61
+ // Ensure TestNewDefaultSatResolver panics if the runtime constraints
62
+ // environment variable does not point to an existing file or valid path
63
+ sourceProvider := & fakeSourceProvider {}
64
+ catSrcLister := & fakeCatalogSourceLister {}
65
+ logger := logrus .New ()
66
+ t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
67
+
68
+ // This test expects a panic to happen
69
+ defer func () {
70
+ if r := recover (); r == nil {
71
+ t .Errorf ("The code did not panic" )
72
+ }
73
+ }()
74
+
75
+ // Set the runtime constraints env var to something that isn't a valid filesystem path
76
+ require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , "%#$%#$ %$#%#$%" ))
77
+ _ = NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
78
+ }
79
+
80
+ func TestNewDefaultSatResolver_BadClusterRuntimeConstraintsFile (t * testing.T ) {
81
+ // Ensure TestNewDefaultSatResolver panics if the runtime constraints
82
+ // environment variable points to a poorly formatted runtime constraints file
83
+ sourceProvider := & fakeSourceProvider {}
84
+ catSrcLister := & fakeCatalogSourceLister {}
85
+ logger := logrus .New ()
86
+ t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
87
+
88
+ // This test expects a panic to happen
89
+ defer func () {
90
+ if r := recover (); r == nil {
91
+ t .Errorf ("The code did not panic" )
92
+ }
93
+ }()
94
+
95
+ runtimeConstraintsFilePath := "runtime_constraints/testdata/bad_runtime_constraints.json"
96
+ // set the runtime constraints env var to something that isn't a valid filesystem path
97
+ require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , runtimeConstraintsFilePath ))
98
+ _ = NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
99
+ }
100
+
101
+ func TestNewDefaultSatResolver_GoodClusterRuntimeConstraintsFile (t * testing.T ) {
102
+ // Ensure TestNewDefaultSatResolver loads the runtime constraints
103
+ // defined in a well formatted file point to by the runtime constraints env var
104
+ sourceProvider := & fakeSourceProvider {}
105
+ catSrcLister := & fakeCatalogSourceLister {}
106
+ logger := logrus .New ()
107
+ t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
108
+
109
+ runtimeConstraintsFilePath := "runtime_constraints/testdata/runtime_constraints.json"
110
+ // set the runtime constraints env var to something that isn't a valid filesystem path
111
+ require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , runtimeConstraintsFilePath ))
112
+ resolver := NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
113
+ runtimeConstraints := resolver .runtimeConstraintsProvider .Constraints ()
114
+ require .Len (t , runtimeConstraints , 1 )
115
+ require .Equal (t , "with package: etcd" , runtimeConstraints [0 ].String ())
116
+ }
117
+
46
118
func TestSolveOperators (t * testing.T ) {
47
119
APISet := cache.APISet {opregistry.APIKey {Group : "g" , Version : "v" , Kind : "k" , Plural : "ks" }: struct {}{}}
48
120
Provides := APISet
@@ -113,11 +185,16 @@ func TestRuntimeConstraints(t *testing.T) {
113
185
114
186
// packageA requires an API that can be provided by B or C
115
187
packageA := genOperator ("packageA.v1" , "0.0.1" , "" , "packageA" , "alpha" , catalog .Name , catalog .Namespace , APISet , nil , nil , "" , false )
188
+ packageA .Properties = append (packageA .Properties , newLabelProperty ("filterOut=yes" ), newLabelProperty ("theBest=yes" ))
189
+
116
190
packageB := genOperator ("packageB.v1" , "1.0.0" , "" , "packageB" , "alpha" , catalog .Name , catalog .Namespace , nil , APISet , nil , "" , false )
191
+ packageB .Properties = append (packageB .Properties , newLabelProperty ("filterOut=no" ), newLabelProperty ("theBest=no" ))
192
+
117
193
packageC := genOperator ("packageC.v1" , "1.0.0" , "" , "packageC" , "alpha" , catalog .Name , catalog .Namespace , nil , APISet , nil , "" , false )
118
- packageD := genOperator ( "packageD.v1" , "1.0.0" , "" , "packageD" , "alpha" , catalog . Name , catalog . Namespace , nil , nil , nil , "" , false )
194
+ packageC . Properties = append ( packageC . Properties , newLabelProperty ( "filterOut=no" ), newLabelProperty ( "theBest=yes" ) )
119
195
120
196
// Existing operators
197
+ packageD := genOperator ("packageD.v1" , "1.0.0" , "" , "packageD" , "alpha" , catalog .Name , catalog .Namespace , nil , nil , nil , "" , false )
121
198
existingPackageD := existingOperator (namespace , "packageD.v1" , "packageD" , "alpha" , "" , nil , nil , nil , nil )
122
199
existingPackageD .Annotations = map [string ]string {"operatorframework.io/properties" : `{"properties":[{"type":"olm.package","value":{"packageName":"packageD","version":"1.0.0"}}]}` }
123
200
@@ -143,7 +220,7 @@ func TestRuntimeConstraints(t *testing.T) {
143
220
title : "Runtime constraints only accept packages A and C" ,
144
221
snapshotEntries : []* cache.Entry {packageA , packageB , packageC , packageD },
145
222
runtimeConstraints : []cache.Predicate {
146
- cache .Or ( cache . PkgPredicate ( "packageA" ), cache . PkgPredicate ( "packageC" ) ),
223
+ cache .LabelPredicate ( "theBest=yes" ),
147
224
},
148
225
expectedOperators : cache.OperatorSet {"packageA.v1" : packageA , "packageC.v1" : packageC },
149
226
csvs : nil ,
@@ -154,7 +231,7 @@ func TestRuntimeConstraints(t *testing.T) {
154
231
title : "Existing packages are ignored" ,
155
232
snapshotEntries : []* cache.Entry {packageA , packageB , packageC , packageD },
156
233
runtimeConstraints : []cache.Predicate {
157
- cache .Or ( cache . PkgPredicate ( "packageA" ), cache . PkgPredicate ( "packageC" ) ),
234
+ cache .LabelPredicate ( "theBest=yes" ),
158
235
},
159
236
expectedOperators : cache.OperatorSet {"packageA.v1" : packageA , "packageC.v1" : packageC },
160
237
csvs : []* v1alpha1.ClusterServiceVersion {existingPackageD },
@@ -165,12 +242,12 @@ func TestRuntimeConstraints(t *testing.T) {
165
242
title : "Runtime constraints don't allow A" ,
166
243
snapshotEntries : []* cache.Entry {packageA , packageB , packageC , packageD },
167
244
runtimeConstraints : []cache.Predicate {
168
- cache .Not ( cache . PkgPredicate ( "packageA" ) ),
245
+ cache .LabelPredicate ( "filterOut=no" ),
169
246
},
170
247
expectedOperators : nil ,
171
248
csvs : nil ,
172
249
subs : []* v1alpha1.Subscription {packageASub },
173
- err : "test-catalog/test-namespace/alpha/packageA.v1 violates a cluster runtime constraint: not with package: packageA " ,
250
+ err : "test-catalog/test-namespace/alpha/packageA.v1 violates a cluster runtime constraint: with label: filterOut=no " ,
174
251
},
175
252
}
176
253
@@ -2182,74 +2259,9 @@ func TestNewOperatorFromCSV(t *testing.T) {
2182
2259
}
2183
2260
}
2184
2261
2185
- func TestNewDefaultSatResolver_NoClusterRuntimeConstraints (t * testing.T ) {
2186
- // Ensure no runtime constraints are loaded if the runtime constraints env
2187
- // var is not set
2188
- sourceProvider := & fakeSourceProvider {}
2189
- catSrcLister := & fakeCatalogSourceLister {}
2190
- logger := logrus .New ()
2191
-
2192
- // Unset the runtime constraints file path environment variable
2193
- // signaling that no runtime constraints should be considered by the resolver
2194
- require .Nil (t , os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ))
2195
- resolver := NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
2196
- require .Nil (t , resolver .runtimeConstraintsProvider )
2197
- }
2198
-
2199
- func TestNewDefaultSatResolver_BadClusterRuntimeConstraintsEnvVar (t * testing.T ) {
2200
- // Ensure TestNewDefaultSatResolver panics if the runtime constraints
2201
- // environment variable does not point to an existing file or valid path
2202
- sourceProvider := & fakeSourceProvider {}
2203
- catSrcLister := & fakeCatalogSourceLister {}
2204
- logger := logrus .New ()
2205
- t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
2206
-
2207
- // This test expects a panic to happen
2208
- defer func () {
2209
- if r := recover (); r == nil {
2210
- t .Errorf ("The code did not panic" )
2211
- }
2212
- }()
2213
-
2214
- // Set the runtime constraints env var to something that isn't a valid filesystem path
2215
- require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , "%#$%#$ %$#%#$%" ))
2216
- _ = NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
2217
- }
2218
-
2219
- func TestNewDefaultSatResolver_BadClusterRuntimeConstraintsFile (t * testing.T ) {
2220
- // Ensure TestNewDefaultSatResolver panics if the runtime constraints
2221
- // environment variable points to a poorly formatted runtime constraints file
2222
- sourceProvider := & fakeSourceProvider {}
2223
- catSrcLister := & fakeCatalogSourceLister {}
2224
- logger := logrus .New ()
2225
- t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
2226
-
2227
- // This test expects a panic to happen
2228
- defer func () {
2229
- if r := recover (); r == nil {
2230
- t .Errorf ("The code did not panic" )
2231
- }
2232
- }()
2233
-
2234
- runtimeConstraintsFilePath := "runtime_constraints/testdata/bad_runtime_constraints.json"
2235
- // set the runtime constraints env var to something that isn't a valid filesystem path
2236
- require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , runtimeConstraintsFilePath ))
2237
- _ = NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
2238
- }
2239
-
2240
- func TestNewDefaultSatResolver_GoodClusterRuntimeConstraintsFile (t * testing.T ) {
2241
- // Ensure TestNewDefaultSatResolver loads the runtime constraints
2242
- // defined in a well formatted file point to by the runtime constraints env var
2243
- sourceProvider := & fakeSourceProvider {}
2244
- catSrcLister := & fakeCatalogSourceLister {}
2245
- logger := logrus .New ()
2246
- t .Cleanup (func () { _ = os .Unsetenv (runtime_constraints .RuntimeConstraintEnvVarName ) })
2247
-
2248
- runtimeConstraintsFilePath := "runtime_constraints/testdata/runtime_constraints.json"
2249
- // set the runtime constraints env var to something that isn't a valid filesystem path
2250
- require .Nil (t , os .Setenv (runtime_constraints .RuntimeConstraintEnvVarName , runtimeConstraintsFilePath ))
2251
- resolver := NewDefaultSatResolver (sourceProvider , catSrcLister , logger )
2252
- runtimeConstraints := resolver .runtimeConstraintsProvider .Constraints ()
2253
- require .Len (t , runtimeConstraints , 1 )
2254
- require .Equal (t , "with package: etcd" , runtimeConstraints [0 ].String ())
2262
+ func newLabelProperty (label string ) * api.Property {
2263
+ return & api.Property {
2264
+ Type : opregistry .LabelType ,
2265
+ Value : fmt .Sprintf (`{"label": "%s"}` , label ),
2266
+ }
2255
2267
}
0 commit comments