@@ -4,11 +4,13 @@ import (
44 "testing"
55
66 "github.com/stretchr/testify/assert"
7+
8+ "github.com/envoyproxy/go-control-plane/pkg/server/config"
79)
810
911func TestSotwSubscriptions (t * testing.T ) {
1012 t .Run ("legacy mode properly handled" , func (t * testing.T ) {
11- sub := NewSotwSubscription ([]string {})
13+ sub := NewSotwSubscription ([]string {}, config . NewOpts (), "" )
1214 assert .True (t , sub .IsWildcard ())
1315
1416 // Requests always set empty in legacy mode
@@ -35,7 +37,7 @@ func TestSotwSubscriptions(t *testing.T) {
3537
3638 t .Run ("new wildcard mode from start" , func (t * testing.T ) {
3739 // A resource is provided so the subscription was created in wildcard
38- sub := NewSotwSubscription ([]string {"*" })
40+ sub := NewSotwSubscription ([]string {"*" }, config . NewOpts (), "" )
3941 assert .True (t , sub .IsWildcard ())
4042 assert .Empty (t , sub .SubscribedResources ())
4143
@@ -73,7 +75,7 @@ func TestSotwSubscriptions(t *testing.T) {
7375
7476func TestDeltaSubscriptions (t * testing.T ) {
7577 t .Run ("legacy mode properly handled" , func (t * testing.T ) {
76- sub := NewDeltaSubscription ([]string {}, []string {}, map [string ]string {"resource" : "version" })
78+ sub := NewDeltaSubscription ([]string {}, []string {}, map [string ]string {"resource" : "version" }, config . NewOpts (), "" )
7779 assert .True (t , sub .IsWildcard ())
7880 assert .Empty (t , sub .SubscribedResources ())
7981 assert .Equal (t , map [string ]string {"resource" : "version" }, sub .ReturnedResources ())
@@ -102,7 +104,7 @@ func TestDeltaSubscriptions(t *testing.T) {
102104
103105 t .Run ("new wildcard mode" , func (t * testing.T ) {
104106 // A resource is provided so the subscription was created in wildcard
105- sub := NewDeltaSubscription ([]string {"*" }, []string {}, map [string ]string {"resource" : "version" })
107+ sub := NewDeltaSubscription ([]string {"*" }, []string {}, map [string ]string {"resource" : "version" }, config . NewOpts (), "" )
106108 assert .True (t , sub .IsWildcard ())
107109 assert .Empty (t , sub .SubscribedResources ())
108110
@@ -157,3 +159,78 @@ func TestDeltaSubscriptions(t *testing.T) {
157159 assert .Equal (t , map [string ]struct {}{"resource" : {}}, sub .SubscribedResources ())
158160 })
159161}
162+
163+ func TestSotwSubscriptionsWithDeactivatedLegacyWildcard (t * testing.T ) {
164+ t .Run ("deactivate for all types" , func (t * testing.T ) {
165+ opts := config .NewOpts ()
166+ deactivateOpt := config .DeactivateLegacyWildcard ()
167+ deactivateOpt (& opts )
168+
169+ // Create subscription with empty resource list (would normally be legacy wildcard)
170+ sub := NewSotwSubscription ([]string {}, opts , "type.googleapis.com/envoy.config.cluster.v3.Cluster" )
171+
172+ // With deactivated legacy wildcard, subscription should NOT be wildcard initially
173+ // because allowLegacyWildcard=false means empty list doesn't trigger legacy behavior
174+ assert .False (t , sub .IsWildcard ())
175+
176+ // Set empty resources - should remain non-wildcard
177+ sub .SetResourceSubscription ([]string {})
178+ assert .False (t , sub .IsWildcard ())
179+
180+ // Can still explicitly subscribe to wildcard
181+ sub .SetResourceSubscription ([]string {"*" })
182+ assert .True (t , sub .IsWildcard ())
183+ })
184+ }
185+
186+ func TestSotwSubscriptionsWithDeactivatedLegacyWildcardForTypes (t * testing.T ) {
187+ t .Run ("deactivate for specific type" , func (t * testing.T ) {
188+ opts := config .NewOpts ()
189+ clusterType := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
190+ endpointType := "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
191+
192+ deactivateOpt := config .DeactivateLegacyWildcardForTypes ([]string {clusterType })
193+ deactivateOpt (& opts )
194+
195+ // Create subscription for deactivated type
196+ 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
201+ subCluster .SetResourceSubscription ([]string {})
202+ assert .False (t , subCluster .IsWildcard ())
203+
204+ // Create subscription for non-deactivated type
205+ subEndpoint := NewSotwSubscription ([]string {}, opts , endpointType )
206+ assert .True (t , subEndpoint .IsWildcard ())
207+
208+ // Setting empty resources should maintain legacy wildcard for this type
209+ subEndpoint .SetResourceSubscription ([]string {})
210+ assert .True (t , subEndpoint .IsWildcard ())
211+ })
212+
213+ t .Run ("deactivate for multiple types" , func (t * testing.T ) {
214+ opts := config .NewOpts ()
215+ clusterType := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
216+ endpointType := "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
217+ routeType := "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
218+
219+ deactivateOpt := config .DeactivateLegacyWildcardForTypes ([]string {clusterType , endpointType })
220+ deactivateOpt (& opts )
221+
222+ // Both cluster and endpoint should have legacy wildcard deactivated
223+ subCluster := NewSotwSubscription ([]string {}, opts , clusterType )
224+ subCluster .SetResourceSubscription ([]string {})
225+ assert .False (t , subCluster .IsWildcard ())
226+
227+ subEndpoint := NewSotwSubscription ([]string {}, opts , endpointType )
228+ subEndpoint .SetResourceSubscription ([]string {})
229+ assert .False (t , subEndpoint .IsWildcard ())
230+
231+ // Route should still have legacy wildcard enabled
232+ subRoute := NewSotwSubscription ([]string {}, opts , routeType )
233+ subRoute .SetResourceSubscription ([]string {})
234+ assert .True (t , subRoute .IsWildcard ())
235+ })
236+ }
0 commit comments