Merge pull request #127689 from mmorel-35/testifylint/expected-actual@k8s.io/client-go

fix: enable expected-actual rule from testifylint in module `k8s.io/client-go`

Kubernetes-commit: 93f82d25a5b10577116e4a72f77fb5e635e65490
This commit is contained in:
Kubernetes Publisher 2024-09-29 09:10:09 +01:00
commit 46093399c4
8 changed files with 22 additions and 22 deletions

View File

@ -57,35 +57,35 @@ func TestCachedDiscoveryClient_Fresh(t *testing.T) {
cdc.ServerGroups()
assert.True(cdc.Fresh(), "should be fresh after groups call without cache")
assert.Equal(c.groupCalls, 1)
assert.Equal(1, c.groupCalls)
cdc.ServerGroups()
assert.True(cdc.Fresh(), "should be fresh after another groups call")
assert.Equal(c.groupCalls, 1)
assert.Equal(1, c.groupCalls)
cdc.ServerGroupsAndResources()
assert.True(cdc.Fresh(), "should be fresh after resources call")
assert.Equal(c.resourceCalls, 1)
assert.Equal(1, c.resourceCalls)
cdc.ServerGroupsAndResources()
assert.True(cdc.Fresh(), "should be fresh after another resources call")
assert.Equal(c.resourceCalls, 1)
assert.Equal(1, c.resourceCalls)
cdc = newCachedDiscoveryClient(&c, d, 60*time.Second)
cdc.ServerGroups()
assert.False(cdc.Fresh(), "should NOT be fresh after recreation with existing groups cache")
assert.Equal(c.groupCalls, 1)
assert.Equal(1, c.groupCalls)
cdc.ServerGroupsAndResources()
assert.False(cdc.Fresh(), "should NOT be fresh after recreation with existing resources cache")
assert.Equal(c.resourceCalls, 1)
assert.Equal(1, c.resourceCalls)
cdc.Invalidate()
assert.True(cdc.Fresh(), "should be fresh after cache invalidation")
cdc.ServerGroupsAndResources()
assert.True(cdc.Fresh(), "should ignore existing resources cache after invalidation")
assert.Equal(c.resourceCalls, 2)
assert.Equal(2, c.resourceCalls)
}
func TestNewCachedDiscoveryClient_TTL(t *testing.T) {
@ -98,12 +98,12 @@ func TestNewCachedDiscoveryClient_TTL(t *testing.T) {
c := fakeDiscoveryClient{}
cdc := newCachedDiscoveryClient(&c, d, 1*time.Nanosecond)
cdc.ServerGroups()
assert.Equal(c.groupCalls, 1)
assert.Equal(1, c.groupCalls)
time.Sleep(1 * time.Second)
cdc.ServerGroups()
assert.Equal(c.groupCalls, 2)
assert.Equal(2, c.groupCalls)
}
func TestNewCachedDiscoveryClient_PathPerm(t *testing.T) {

View File

@ -148,7 +148,7 @@ func TestEnvVarFeatureGates(t *testing.T) {
}
for expectedFeature, expectedValue := range scenario.expectedFeaturesState {
actualValue := target.Enabled(expectedFeature)
require.Equal(t, actualValue, expectedValue, "expected feature=%v, to be=%v, not=%v", expectedFeature, expectedValue, actualValue)
require.Equal(t, expectedValue, actualValue, "expected feature=%v, to be=%v, not=%v", expectedFeature, expectedValue, actualValue)
}
enabledViaEnvVarInternalMap := target.enabledViaEnvVar.Load().(map[Feature]bool)

2
go.mod
View File

@ -27,7 +27,7 @@ require (
google.golang.org/protobuf v1.34.2
gopkg.in/evanphx/json-patch.v4 v4.12.0
k8s.io/api v0.0.0-20240920202009-71385f038c10
k8s.io/apimachinery v0.0.0-20240926041705-dc03077c038e
k8s.io/apimachinery v0.0.0-20240929035808-0db5dbf03048
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8

4
go.sum
View File

@ -157,8 +157,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20240920202009-71385f038c10 h1:shjQe98Co9zBlDzQkxb5IJEWtReSl7qunr56C4Jgc70=
k8s.io/api v0.0.0-20240920202009-71385f038c10/go.mod h1:KCEt6+W/Yn1Vc48pYXeLf0mGK52kJhvt+rcaUVsIaKQ=
k8s.io/apimachinery v0.0.0-20240926041705-dc03077c038e h1:/N2qUkIcQ8VaZbmy28grdhVBbNXO6KLZRdz6F2siNeY=
k8s.io/apimachinery v0.0.0-20240926041705-dc03077c038e/go.mod h1:5rKPDwwN9qm//xASFCZ83nyYEanHxxhc7pZ8AC4lukY=
k8s.io/apimachinery v0.0.0-20240929035808-0db5dbf03048 h1:EWQWppfphUSBwuhuNA4weJ9vJtfHhjVwizTYjZb8ikw=
k8s.io/apimachinery v0.0.0-20240929035808-0db5dbf03048/go.mod h1:5rKPDwwN9qm//xASFCZ83nyYEanHxxhc7pZ8AC4lukY=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2 h1:GKE9U8BH16uynoxQii0auTjmmmuZ3O0LFMN6S0lPPhI=

View File

@ -257,8 +257,8 @@ func TestDeferredDiscoveryRESTMapper_CacheMiss(t *testing.T) {
})
assert.NoError(err)
assert.True(cdc.fresh, "should be fresh after a cache-miss")
assert.Equal(cdc.invalidateCalls, 1, "should have called Invalidate() once")
assert.Equal(gvk.Kind, "Foo")
assert.Equal(1, cdc.invalidateCalls, "should have called Invalidate() once")
assert.Equal("Foo", gvk.Kind)
gvk, err = m.KindFor(schema.GroupVersionResource{
Group: "a",
@ -266,7 +266,7 @@ func TestDeferredDiscoveryRESTMapper_CacheMiss(t *testing.T) {
Resource: "foo",
})
assert.NoError(err)
assert.Equal(cdc.invalidateCalls, 1, "should NOT have called Invalidate() again")
assert.Equal(1, cdc.invalidateCalls, "should NOT have called Invalidate() again")
gvk, err = m.KindFor(schema.GroupVersionResource{
Group: "a",
@ -274,7 +274,7 @@ func TestDeferredDiscoveryRESTMapper_CacheMiss(t *testing.T) {
Resource: "bar",
})
assert.Error(err)
assert.Equal(cdc.invalidateCalls, 1, "should NOT have called Invalidate() again after another cache-miss, but with fresh==true")
assert.Equal(1, cdc.invalidateCalls, "should NOT have called Invalidate() again after another cache-miss, but with fresh==true")
cdc.fresh = false
gvk, err = m.KindFor(schema.GroupVersionResource{
@ -283,7 +283,7 @@ func TestDeferredDiscoveryRESTMapper_CacheMiss(t *testing.T) {
Resource: "bar",
})
assert.Error(err)
assert.Equal(cdc.invalidateCalls, 2, "should HAVE called Invalidate() again after another cache-miss, but with fresh==false")
assert.Equal(2, cdc.invalidateCalls, "should HAVE called Invalidate() again after another cache-miss, but with fresh==false")
}
func TestGetAPIGroupResources(t *testing.T) {

View File

@ -297,7 +297,7 @@ func TestApplyCreate(t *testing.T) {
t.Fatalf("Failed to create a resource with apply: %v", err)
}
cm := configMap.(*v1.ConfigMap)
assert.Equal(t, cm.Data, map[string]string{"k": "v"})
assert.Equal(t, map[string]string{"k": "v"}, cm.Data)
}
func TestApplyNoMeta(t *testing.T) {

View File

@ -221,8 +221,8 @@ func TestDataConsistencyChecker(t *testing.T) {
CheckDataConsistency(ctx, "", scenario.lastSyncedResourceVersion, fakeLister.List, scenario.requestOptions, retrievedItemsFunc)
}
require.Equal(t, fakeLister.counter, scenario.expectedListRequests)
require.Equal(t, fakeLister.requestOptions, scenario.expectedRequestOptions)
require.Equal(t, scenario.expectedListRequests, fakeLister.counter)
require.Equal(t, scenario.expectedRequestOptions, fakeLister.requestOptions)
})
}
}

View File

@ -133,7 +133,7 @@ func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath(t *testin
require.Equal(t, 1, fakeLister.counter)
require.Len(t, fakeLister.requestOptions, 1)
require.Equal(t, fakeLister.requestOptions[0], scenario.expectedRequestOptions)
require.Equal(t, scenario.expectedRequestOptions, fakeLister.requestOptions[0])
})
}
}