Skip to content

Commit fbf5083

Browse files
committed
Add test case to ensure clusterHostSuffix isn't erased on config update
Signed-off-by: Angel Misevski <[email protected]>
1 parent 976b78f commit fbf5083

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pkg/config/sync_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func TestDetectsOpenShiftRouteSuffix(t *testing.T) {
140140
}
141141

142142
func TestSyncConfigFromIgnoresOtherConfigInOtherNamespaces(t *testing.T) {
143+
setupForTest(t)
143144
internalConfig = DefaultConfig.DeepCopy()
144145
config := buildConfig(&v1alpha1.OperatorConfiguration{
145146
Workspace: &v1alpha1.WorkspaceConfig{
@@ -152,6 +153,7 @@ func TestSyncConfigFromIgnoresOtherConfigInOtherNamespaces(t *testing.T) {
152153
}
153154

154155
func TestSyncConfigFromIgnoresOtherConfigWithOtherName(t *testing.T) {
156+
setupForTest(t)
155157
internalConfig = DefaultConfig.DeepCopy()
156158
config := buildConfig(&v1alpha1.OperatorConfiguration{
157159
Workspace: &v1alpha1.WorkspaceConfig{
@@ -164,6 +166,7 @@ func TestSyncConfigFromIgnoresOtherConfigWithOtherName(t *testing.T) {
164166
}
165167

166168
func TestSyncConfigDoesNotChangeDefaults(t *testing.T) {
169+
setupForTest(t)
167170
oldDefaultConfig := DefaultConfig.DeepCopy()
168171
internalConfig = DefaultConfig.DeepCopy()
169172
config := buildConfig(&v1alpha1.OperatorConfiguration{
@@ -181,6 +184,38 @@ func TestSyncConfigDoesNotChangeDefaults(t *testing.T) {
181184
assert.Equal(t, DefaultConfig, oldDefaultConfig)
182185
}
183186

187+
func TestSyncConfigDoesNotEraseClusterRoutingSuffix(t *testing.T) {
188+
setupForTest(t)
189+
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
190+
testRoute := &routev1.Route{
191+
ObjectMeta: metav1.ObjectMeta{
192+
Name: openShiftTestRouteName,
193+
Namespace: testNamespace,
194+
},
195+
Spec: routev1.RouteSpec{
196+
Host: fmt.Sprintf("%s-%s.test-host", openShiftTestRouteName, testNamespace),
197+
},
198+
}
199+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(testRoute).Build()
200+
err := SetupControllerConfig(client)
201+
if !assert.NoError(t, err, "Should not return error") {
202+
return
203+
}
204+
assert.Equal(t, "test-host", Routing.ClusterHostSuffix, "Should get clusterHostSuffix from route on OpenShift")
205+
syncConfigFrom(buildConfig(&v1alpha1.OperatorConfiguration{
206+
Routing: &v1alpha1.RoutingConfig{
207+
DefaultRoutingClass: "test-routingClass",
208+
},
209+
Workspace: &v1alpha1.WorkspaceConfig{
210+
ImagePullPolicy: "IfNotPresent",
211+
},
212+
}))
213+
if !assert.NoError(t, err, "Should not return error") {
214+
return
215+
}
216+
assert.Equal(t, "test-host", Routing.ClusterHostSuffix, "clusterHostSuffix should persist after an update")
217+
}
218+
184219
func TestMergeConfigLooksAtAllFields(t *testing.T) {
185220
f := fuzz.New().NilChance(0)
186221
expectedConfig := &v1alpha1.OperatorConfiguration{}

0 commit comments

Comments
 (0)