Skip to content

Commit af7a06d

Browse files
Fix unittest update wrongly inverted an assert
Signed-off-by: Valerian Roche <[email protected]>
1 parent a36df79 commit af7a06d

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

pkg/cache/v3/delta_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestDeltaRemoveResources(t *testing.T) {
113113
watches := make(map[string]chan cache.DeltaResponse)
114114
streams := make(map[string]*stream.StreamState)
115115

116+
// At this stage the cache is empty, so a watch is opened
116117
for _, typ := range testTypes {
117118
watches[typ] = make(chan cache.DeltaResponse, 1)
118119
state := stream.NewStreamState(true, make(map[string]string))
@@ -127,13 +128,17 @@ func TestDeltaRemoveResources(t *testing.T) {
127128
}, streams[typ], watches[typ])
128129
}
129130

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))
131137

132138
for _, typ := range testTypes {
133139
t.Run(typ, func(t *testing.T) {
134140
select {
135141
case out := <-watches[typ]:
136-
snapshot := fixture.snapshot()
137142
assertResourceMapEqual(t, cache.IndexRawResourcesByName(out.(*cache.RawDeltaResponse).Resources), snapshot.GetResources(typ))
138143
nextVersionMap := out.GetNextVersionMap()
139144
streams[typ].SetResourceVersions(nextVersionMap)
@@ -158,21 +163,21 @@ func TestDeltaRemoveResources(t *testing.T) {
158163

159164
assert.Equal(t, len(testTypes), c.GetStatusInfo(key).GetNumDeltaWatches(), "watches should be created for the latest version")
160165

161-
// set a partially versioned snapshot with no endpoints
166+
// set a partially versioned snapshot with only one endpoint
162167
snapshot2 := fixture.snapshot()
163-
snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{})
168+
snapshot2.Resources[types.Endpoint] = cache.NewResources(fixture.version2, []types.Resource{
169+
testEndpoint, // this cluster is not changed, we do not expect it back in "resources"
170+
})
164171
require.NoError(t, c.SetSnapshot(context.Background(), key, snapshot2))
165172

166173
// validate response for endpoints
167174
select {
168175
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))
176+
assert.Empty(t, out.(*cache.RawDeltaResponse).Resources)
177+
assert.Equal(t, []string{"otherCluster"}, out.(*cache.RawDeltaResponse).RemovedResources)
172178
nextVersionMap := out.GetNextVersionMap()
173-
174179
// make sure the version maps are different since we no longer are tracking any endpoint resources
175-
require.Equal(t, nextVersionMap, streams[testTypes[0]].GetKnownResources(), "versionMap for the endpoint resource type did not change")
180+
assert.NotEqual(t, nextVersionMap, streams[testTypes[0]].GetKnownResources(), "versionMap for the endpoint resource type did not change")
176181
case <-time.After(time.Second):
177182
assert.Fail(t, "failed to receive snapshot response")
178183
}

pkg/cache/v3/simple_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,22 @@ type logger struct {
9191
t *testing.T
9292
}
9393

94-
func (log logger) Debugf(format string, args ...interface{}) { log.t.Logf(format, args...) }
95-
func (log logger) Infof(format string, args ...interface{}) { log.t.Logf(format, args...) }
96-
func (log logger) Warnf(format string, args ...interface{}) { log.t.Logf(format, args...) }
97-
func (log logger) Errorf(format string, args ...interface{}) { log.t.Logf(format, args...) }
94+
func (log logger) Debugf(format string, args ...interface{}) {
95+
log.t.Helper()
96+
log.t.Logf(format, args...)
97+
}
98+
func (log logger) Infof(format string, args ...interface{}) {
99+
log.t.Helper()
100+
log.t.Logf(format, args...)
101+
}
102+
func (log logger) Warnf(format string, args ...interface{}) {
103+
log.t.Helper()
104+
log.t.Logf(format, args...)
105+
}
106+
func (log logger) Errorf(format string, args ...interface{}) {
107+
log.t.Helper()
108+
log.t.Logf(format, args...)
109+
}
98110

99111
func TestSnapshotCacheWithTTL(t *testing.T) {
100112
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)