@@ -113,6 +113,7 @@ func TestDeltaRemoveResources(t *testing.T) {
113
113
watches := make (map [string ]chan cache.DeltaResponse )
114
114
streams := make (map [string ]* stream.StreamState )
115
115
116
+ // At this stage the cache is empty, so a watch is opened
116
117
for _ , typ := range testTypes {
117
118
watches [typ ] = make (chan cache.DeltaResponse , 1 )
118
119
state := stream .NewStreamState (true , make (map [string ]string ))
@@ -127,7 +128,12 @@ func TestDeltaRemoveResources(t *testing.T) {
127
128
}, * streams [typ ], watches [typ ])
128
129
}
129
130
130
- require .NoError (t , c .SetSnapshot (context .Background (), key , fixture .snapshot ()))
131
+ snapshot := fixture .snapshot ()
132
+ snapshot .Resources [types .Endpoint ] = cache .NewResources (fixture .version , []types.Resource {
133
+ testEndpoint ,
134
+ resource .MakeEndpoint ("otherCluster" , 8080 ),
135
+ })
136
+ require .NoError (t , c .SetSnapshot (context .Background (), key , snapshot ))
131
137
132
138
snapshot := fixture .snapshot ()
133
139
for _ , typ := range testTypes {
@@ -158,19 +164,19 @@ func TestDeltaRemoveResources(t *testing.T) {
158
164
159
165
assert .Equal (t , len (testTypes ), c .GetStatusInfo (key ).GetNumDeltaWatches (), "watches should be created for the latest version" )
160
166
161
- // set a partially versioned snapshot with no endpoints
167
+ // set a partially versioned snapshot with only one endpoint
162
168
snapshot2 := fixture .snapshot ()
163
- snapshot2 .Resources [types .Endpoint ] = cache .NewResources (fixture .version2 , []types.Resource {})
169
+ snapshot2 .Resources [types .Endpoint ] = cache .NewResources (fixture .version2 , []types.Resource {
170
+ testEndpoint , // this cluster is not changed, we do not expect it back in "resources"
171
+ })
164
172
require .NoError (t , c .SetSnapshot (context .Background (), key , snapshot2 ))
165
173
166
174
// validate response for endpoints
167
175
select {
168
176
case out := <- watches [testTypes [0 ]]:
169
- snapshot2 := fixture .snapshot ()
170
- snapshot2 .Resources [types .Endpoint ] = cache .NewResources (fixture .version2 , []types.Resource {})
171
- assertResourceMapEqual (t , cache .IndexRawResourcesByName (out .(* cache.RawDeltaResponse ).Resources ), snapshot2 .GetResources (rsrc .EndpointType ))
177
+ assert .Empty (t , out .(* cache.RawDeltaResponse ).Resources )
178
+ assert .Equal (t , []string {"otherCluster" }, out .(* cache.RawDeltaResponse ).RemovedResources )
172
179
nextVersionMap := out .GetNextVersionMap ()
173
-
174
180
// make sure the version maps are different since we no longer are tracking any endpoint resources
175
181
assert .NotEqual (t , nextVersionMap , streams [testTypes [0 ]].GetKnownResources (), "versionMap for the endpoint resource type did not change" )
176
182
case <- time .After (time .Second ):
0 commit comments