@@ -31,6 +31,7 @@ import (
31
31
32
32
"github.com/kcp-dev/logicalcluster/v3"
33
33
34
+ kcpfeatures "github.com/kcp-dev/kcp/pkg/features"
34
35
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
35
36
apisv1alpha2 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha2"
36
37
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
@@ -39,6 +40,9 @@ import (
39
40
)
40
41
41
42
func TestReconcile (t * testing.T ) {
43
+ // Save original feature gate value
44
+ originalFeatureGate := kcpfeatures .DefaultFeatureGate .Enabled (kcpfeatures .EnableDeprecatedAPIExportVirtualWorkspacesUrls )
45
+
42
46
tests := map [string ]struct {
43
47
secretRefSet bool
44
48
secretExists bool
@@ -63,6 +67,7 @@ func TestReconcile(t *testing.T) {
63
67
wantVerifyFailure bool
64
68
wantIdentityValid bool
65
69
wantCreateAPIExportEndpointSlice bool
70
+ wantVirtualWorkspaceURLs bool
66
71
}{
67
72
"create secret when ref is nil and secret doesn't exist" : {
68
73
secretExists : false ,
@@ -144,10 +149,32 @@ func TestReconcile(t *testing.T) {
144
149
wantIdentityValid : true ,
145
150
skipEndpointSliceAnnotation : true ,
146
151
},
152
+ "virtual workspace URLs when feature gate enabled" : {
153
+ secretRefSet : true ,
154
+ secretExists : true ,
155
+
156
+ wantStatusHashSet : true ,
157
+ wantIdentityValid : true ,
158
+ wantVirtualWorkspaceURLs : true ,
159
+ },
160
+ "error listing shards with feature gate enabled" : {
161
+ secretRefSet : true ,
162
+ secretExists : true ,
163
+
164
+ wantStatusHashSet : true ,
165
+ wantIdentityValid : true ,
166
+ wantVirtualWorkspaceURLs : false ,
167
+ listShardsError : errors .New ("foo" ),
168
+ },
147
169
}
148
170
149
171
for name , tc := range tests {
150
172
t .Run (name , func (t * testing.T ) {
173
+ // Skip virtual workspace URL tests if feature gate is not enabled
174
+ if tc .wantVirtualWorkspaceURLs && ! originalFeatureGate {
175
+ t .Skip ("Skipping test that requires EnableDeprecatedAPIExportVirtualWorkspacesUrls feature gate" )
176
+ }
177
+
151
178
createSecretCalled := false
152
179
createEndpointSliceCalled := false
153
180
@@ -311,6 +338,15 @@ func TestReconcile(t *testing.T) {
311
338
}
312
339
313
340
require .Equal (t , tc .wantCreateAPIExportEndpointSlice , createEndpointSliceCalled , "expected createEndpointSliceCalled to be %v" , tc .wantCreateAPIExportEndpointSlice )
341
+
342
+ if tc .wantVirtualWorkspaceURLs {
343
+ require .NotNil (t , apiExport .Status .VirtualWorkspaces , "expected virtual workspace URLs to be set" )
344
+ require .Len (t , apiExport .Status .VirtualWorkspaces , 2 , "expected 2 virtual workspace URLs" )
345
+ require .True (t , conditions .IsTrue (apiExport , apisv1alpha2 .APIExportVirtualWorkspaceURLsReady ), "expected virtual workspace URLs to be ready" )
346
+ } else {
347
+ require .Nil (t , apiExport .Status .VirtualWorkspaces , "expected virtual workspace URLs to be nil" )
348
+ require .False (t , conditions .Has (apiExport , apisv1alpha2 .APIExportVirtualWorkspaceURLsReady ), "expected virtual workspace URLs condition to not exist" )
349
+ }
314
350
})
315
351
}
316
352
}
0 commit comments