@@ -9,190 +9,16 @@ import (
9
9
"github.com/google/go-cmp/cmp/cmpopts"
10
10
"github.com/stretchr/testify/assert"
11
11
"github.com/stretchr/testify/require"
12
- featuregatetesting "k8s.io/component-base/featuregate/testing"
13
12
14
13
"github.com/operator-framework/operator-registry/alpha/declcfg"
15
14
"github.com/operator-framework/operator-registry/alpha/property"
16
15
17
16
ocv1 "github.com/operator-framework/operator-controller/api/v1"
18
17
"github.com/operator-framework/operator-controller/internal/bundleutil"
19
18
"github.com/operator-framework/operator-controller/internal/catalogmetadata/compare"
20
- "github.com/operator-framework/operator-controller/internal/features"
21
19
)
22
20
23
- func TestSuccessorsPredicateWithForceSemverUpgradeConstraintsEnabled (t * testing.T ) {
24
- featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )
25
-
26
- const testPackageName = "test-package"
27
- channelSet := map [string ]declcfg.Channel {
28
- testPackageName : {
29
- Package : testPackageName ,
30
- Name : "stable" ,
31
- },
32
- }
33
-
34
- bundleSet := map [string ]declcfg.Bundle {
35
- // Major version zero is for initial development and
36
- // has different update behaviour than versions >= 1.0.0:
37
- // - In versions 0.0.y updates are not allowed when using semver constraints
38
- // - In versions 0.x.y only patch updates are allowed (>= 0.x.y and < 0.x+1.0)
39
- // This means that we need in test data bundles that cover these three version ranges.
40
- "test-package.v0.0.1" : {
41
- Name : "test-package.v0.0.1" ,
42
- Package : testPackageName ,
43
- Image :
"registry.io/repo/[email protected] " ,
44
- Properties : []property.Property {
45
- property .MustBuildPackage (testPackageName , "0.0.1" ),
46
- },
47
- },
48
- "test-package.v0.0.2" : {
49
- Name : "test-package.v0.0.2" ,
50
- Package : testPackageName ,
51
- Image :
"registry.io/repo/[email protected] " ,
52
- Properties : []property.Property {
53
- property .MustBuildPackage (testPackageName , "0.0.2" ),
54
- },
55
- },
56
- "test-package.v0.1.0" : {
57
- Name : "test-package.v0.1.0" ,
58
- Package : testPackageName ,
59
- Image :
"registry.io/repo/[email protected] " ,
60
- Properties : []property.Property {
61
- property .MustBuildPackage (testPackageName , "0.1.0" ),
62
- },
63
- },
64
- "test-package.v0.1.1" : {
65
- Name : "test-package.v0.1.1" ,
66
- Package : testPackageName ,
67
- Image :
"registry.io/repo/[email protected] " ,
68
- Properties : []property.Property {
69
- property .MustBuildPackage (testPackageName , "0.1.1" ),
70
- },
71
- },
72
- "test-package.v0.1.2" : {
73
- Name : "test-package.v0.1.2" ,
74
- Package : testPackageName ,
75
- Image :
"registry.io/repo/[email protected] " ,
76
- Properties : []property.Property {
77
- property .MustBuildPackage (testPackageName , "0.1.2" ),
78
- },
79
- },
80
- "test-package.v0.2.0" : {
81
- Name : "test-package.v0.2.0" ,
82
- Package : testPackageName ,
83
- Image :
"registry.io/repo/[email protected] " ,
84
- Properties : []property.Property {
85
- property .MustBuildPackage (testPackageName , "0.2.0" ),
86
- },
87
- },
88
- "test-package.v2.0.0" : {
89
- Name : "test-package.v2.0.0" ,
90
- Package : testPackageName ,
91
- Image :
"registry.io/repo/[email protected] " ,
92
- Properties : []property.Property {
93
- property .MustBuildPackage (testPackageName , "2.0.0" ),
94
- },
95
- },
96
- "test-package.v2.1.0" : {
97
- Name : "test-package.v2.1.0" ,
98
- Package : testPackageName ,
99
- Image :
"registry.io/repo/[email protected] " ,
100
- Properties : []property.Property {
101
- property .MustBuildPackage (testPackageName , "2.1.0" ),
102
- },
103
- },
104
- "test-package.v2.2.0" : {
105
- Name : "test-package.v2.2.0" ,
106
- Package : testPackageName ,
107
- Image :
"registry.io/repo/[email protected] " ,
108
- Properties : []property.Property {
109
- property .MustBuildPackage (testPackageName , "2.2.0" ),
110
- },
111
- },
112
- // We need a bundle with a different major version to ensure
113
- // that we do not allow upgrades from one major version to another
114
- "test-package.v3.0.0" : {
115
- Name : "test-package.v3.0.0" ,
116
- Package : testPackageName ,
117
- Image :
"registry.io/repo/[email protected] " ,
118
- Properties : []property.Property {
119
- property .MustBuildPackage (testPackageName , "3.0.0" ),
120
- },
121
- },
122
- }
123
-
124
- for _ , b := range bundleSet {
125
- ch := channelSet [b .Package ]
126
- ch .Entries = append (ch .Entries , declcfg.ChannelEntry {Name : b .Name })
127
- channelSet [b .Package ] = ch
128
- }
129
-
130
- for _ , tt := range []struct {
131
- name string
132
- installedBundle ocv1.BundleMetadata
133
- expectedResult []declcfg.Bundle
134
- }{
135
- {
136
- name : "with non-zero major version" ,
137
- installedBundle : bundleutil .MetadataFor ("test-package.v2.0.0" , bsemver .MustParse ("2.0.0" )),
138
- expectedResult : []declcfg.Bundle {
139
- // Updates are allowed within the major version
140
- bundleSet ["test-package.v2.2.0" ],
141
- bundleSet ["test-package.v2.1.0" ],
142
- bundleSet ["test-package.v2.0.0" ],
143
- },
144
- },
145
- {
146
- name : "with zero major and zero minor version" ,
147
- installedBundle : bundleutil .MetadataFor ("test-package.v0.0.1" , bsemver .MustParse ("0.0.1" )),
148
- expectedResult : []declcfg.Bundle {
149
- // No updates are allowed in major version zero when minor version is also zero
150
- bundleSet ["test-package.v0.0.1" ],
151
- },
152
- },
153
- {
154
- name : "with zero major and non-zero minor version" ,
155
- installedBundle : bundleutil .MetadataFor ("test-package.v0.1.0" , bsemver .MustParse ("0.1.0" )),
156
- expectedResult : []declcfg.Bundle {
157
- // Patch version updates are allowed within the minor version
158
- bundleSet ["test-package.v0.1.2" ],
159
- bundleSet ["test-package.v0.1.1" ],
160
- bundleSet ["test-package.v0.1.0" ],
161
- },
162
- },
163
- {
164
- name : "installed bundle not found" ,
165
- installedBundle : ocv1.BundleMetadata {
166
- Name : "test-package.v9.0.0" ,
167
- Version : "9.0.0" ,
168
- },
169
- expectedResult : []declcfg.Bundle {},
170
- },
171
- } {
172
- t .Run (tt .name , func (t * testing.T ) {
173
- successors , err := SuccessorsOf (tt .installedBundle , channelSet [testPackageName ])
174
- require .NoError (t , err )
175
-
176
- allBundles := make ([]declcfg.Bundle , 0 , len (bundleSet ))
177
- for _ , bundle := range bundleSet {
178
- allBundles = append (allBundles , bundle )
179
- }
180
- result := Filter (allBundles , successors )
181
-
182
- // sort before comparison for stable order
183
- slices .SortFunc (result , compare .ByVersion )
184
-
185
- gocmpopts := []cmp.Option {
186
- cmpopts .IgnoreUnexported (declcfg.Bundle {}),
187
- }
188
- require .Empty (t , cmp .Diff (result , tt .expectedResult , gocmpopts ... ))
189
- })
190
- }
191
- }
192
-
193
- func TestSuccessorsPredicateWithForceSemverUpgradeConstraintsDisabled (t * testing.T ) {
194
- featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , false )
195
-
21
+ func TestSuccessorsPredicate (t * testing.T ) {
196
22
const testPackageName = "test-package"
197
23
channelSet := map [string ]declcfg.Channel {
198
24
testPackageName : {
0 commit comments