Skip to content

Commit a397f67

Browse files
committed
add delta but simplify overall
1 parent c9b071c commit a397f67

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

pkg/server/stream/v3/subscription_test.go

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,32 +184,56 @@ func TestSotwSubscriptionsWithDeactivatedLegacyWildcard(t *testing.T) {
184184
}
185185

186186
func TestSotwSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
187-
t.Run("deactivate for specific type", func(t *testing.T) {
187+
t.Run("deactivate for multiple types", func(t *testing.T) {
188188
opts := config.NewOpts()
189189
clusterType := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
190190
endpointType := "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
191+
routeType := "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
191192

192-
deactivateOpt := config.DeactivateLegacyWildcardForTypes([]string{clusterType})
193+
deactivateOpt := config.DeactivateLegacyWildcardForTypes([]string{clusterType, endpointType})
193194
deactivateOpt(&opts)
194195

195-
// Create subscription for deactivated type
196+
// Both cluster and endpoint should have legacy wildcard deactivated
196197
subCluster := NewSotwSubscription([]string{}, opts, clusterType)
197-
// Should NOT be wildcard because legacy wildcard is deactivated for this type
198-
assert.False(t, subCluster.IsWildcard())
199-
200-
// Setting empty resources should remain non-wildcard
201198
subCluster.SetResourceSubscription([]string{})
202199
assert.False(t, subCluster.IsWildcard())
203200

204-
// Create subscription for non-deactivated type
205201
subEndpoint := NewSotwSubscription([]string{}, opts, endpointType)
206-
assert.True(t, subEndpoint.IsWildcard())
207-
208-
// Setting empty resources should maintain legacy wildcard for this type
209202
subEndpoint.SetResourceSubscription([]string{})
210-
assert.True(t, subEndpoint.IsWildcard())
203+
assert.False(t, subEndpoint.IsWildcard())
204+
205+
// Route should still have legacy wildcard enabled
206+
subRoute := NewSotwSubscription([]string{}, opts, routeType)
207+
subRoute.SetResourceSubscription([]string{})
208+
assert.True(t, subRoute.IsWildcard())
209+
})
210+
}
211+
212+
func TestDeltaSubscriptionsWithDeactivatedLegacyWildcard(t *testing.T) {
213+
t.Run("deactivate for all types", func(t *testing.T) {
214+
opts := config.NewOpts()
215+
deactivateOpt := config.DeactivateLegacyWildcard()
216+
deactivateOpt(&opts)
217+
218+
// Create subscription with empty resource list (would normally be legacy wildcard)
219+
sub := NewDeltaSubscription([]string{}, []string{}, map[string]string{"resource": "version"}, opts, "type.googleapis.com/envoy.config.cluster.v3.Cluster")
220+
221+
// With deactivated legacy wildcard, subscription should NOT be wildcard initially
222+
assert.False(t, sub.IsWildcard())
223+
assert.Empty(t, sub.SubscribedResources())
224+
225+
// New request with no additional subscription
226+
sub.UpdateResourceSubscriptions(nil, nil)
227+
assert.False(t, sub.IsWildcard())
228+
assert.Empty(t, sub.SubscribedResources())
229+
230+
// Can still explicitly subscribe to wildcard
231+
sub.UpdateResourceSubscriptions([]string{"*"}, nil)
232+
assert.True(t, sub.IsWildcard())
211233
})
234+
}
212235

236+
func TestDeltaSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
213237
t.Run("deactivate for multiple types", func(t *testing.T) {
214238
opts := config.NewOpts()
215239
clusterType := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
@@ -220,17 +244,17 @@ func TestSotwSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
220244
deactivateOpt(&opts)
221245

222246
// Both cluster and endpoint should have legacy wildcard deactivated
223-
subCluster := NewSotwSubscription([]string{}, opts, clusterType)
224-
subCluster.SetResourceSubscription([]string{})
247+
subCluster := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, clusterType)
248+
subCluster.UpdateResourceSubscriptions(nil, nil)
225249
assert.False(t, subCluster.IsWildcard())
226250

227-
subEndpoint := NewSotwSubscription([]string{}, opts, endpointType)
228-
subEndpoint.SetResourceSubscription([]string{})
251+
subEndpoint := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, endpointType)
252+
subEndpoint.UpdateResourceSubscriptions(nil, nil)
229253
assert.False(t, subEndpoint.IsWildcard())
230254

231255
// Route should still have legacy wildcard enabled
232-
subRoute := NewSotwSubscription([]string{}, opts, routeType)
233-
subRoute.SetResourceSubscription([]string{})
256+
subRoute := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, routeType)
257+
subRoute.UpdateResourceSubscriptions(nil, nil)
234258
assert.True(t, subRoute.IsWildcard())
235259
})
236260
}

0 commit comments

Comments
 (0)