Merge pull request #127649 from mmorel-35/testifylint/formatter@k8s.io/kubernetes

fix: enable formatter rule from testifylint in module `k8s.io/kubernetes`
This commit is contained in:
Kubernetes Prow Robot 2024-09-28 02:52:09 +01:00 committed by GitHub
commit 26399fa7be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 18 additions and 20 deletions

View File

@ -23726,7 +23726,7 @@ func TestValidateAppArmorProfileFormat(t *testing.T) {
if test.expectValid {
assert.NoError(t, err, "Profile %s should be valid", test.profile)
} else {
assert.Error(t, err, fmt.Sprintf("Profile %s should not be valid", test.profile))
assert.Errorf(t, err, "Profile %s should not be valid", test.profile)
}
}
}

View File

@ -786,7 +786,7 @@ func TestFallbackResourcesUsage(t *testing.T) {
},
} {
t.Run(test.description, func(t *testing.T) {
assert.NotEqual(t, 0, test.usageFunc(), fmt.Sprintf("%s: unexpected fallback value", test.usageFuncName))
assert.NotEqualf(t, 0, test.usageFunc(), "%s: unexpected fallback value", test.usageFuncName)
})
}
}

View File

@ -2704,8 +2704,7 @@ func TestValidateNodeIPParam(t *testing.T) {
}
addrs, err := net.InterfaceAddrs()
if err != nil {
assert.Error(t, err, fmt.Sprintf(
"Unable to obtain a list of the node's unicast interface addresses."))
assert.Errorf(t, err, "Unable to obtain a list of the node's unicast interface addresses.")
}
for _, addr := range addrs {
var ip net.IP
@ -2728,9 +2727,9 @@ func TestValidateNodeIPParam(t *testing.T) {
for _, test := range tests {
err := validateNodeIP(netutils.ParseIPSloppy(test.nodeIP))
if test.success {
assert.NoError(t, err, "test %s", test.testName)
assert.NoErrorf(t, err, "test %s", test.testName)
} else {
assert.Error(t, err, fmt.Sprintf("test %s", test.testName))
assert.Errorf(t, err, "test %s", test.testName)
}
}
}

View File

@ -1316,21 +1316,21 @@ func TestValidateContainerLogStatus(t *testing.T) {
podStatus := &v1.PodStatus{ContainerStatuses: tc.statuses}
_, err := kubelet.validateContainerLogStatus("podName", podStatus, containerName, previous)
if !tc.success {
assert.Error(t, err, fmt.Sprintf("[case %d] error", i))
assert.Errorf(t, err, "[case %d] error", i)
} else {
assert.NoError(t, err, "[case %d] error", i)
assert.NoErrorf(t, err, "[case %d] error", i)
}
// Access the log of the previous, terminated container
previous = true
_, err = kubelet.validateContainerLogStatus("podName", podStatus, containerName, previous)
if !tc.pSuccess {
assert.Error(t, err, fmt.Sprintf("[case %d] error", i))
assert.Errorf(t, err, "[case %d] error", i)
} else {
assert.NoError(t, err, "[case %d] error", i)
assert.NoErrorf(t, err, "[case %d] error", i)
}
// Access the log of a container that's not in the pod
_, err = kubelet.validateContainerLogStatus("podName", podStatus, "blah", false)
assert.Error(t, err, fmt.Sprintf("[case %d] invalid container name should cause an error", i))
assert.Errorf(t, err, "[case %d] invalid container name should cause an error", i)
}
}
@ -3267,10 +3267,10 @@ func TestSyncPodSpans(t *testing.T) {
assert.NotEmpty(t, runtimeServiceSpans, "syncPod trace should have runtime service spans")
for _, span := range imageServiceSpans {
assert.Equal(t, span.Parent.SpanID(), rootSpan.SpanContext.SpanID(), fmt.Sprintf("image service span %s %s should be child of root span", span.Name, span.Parent.SpanID()))
assert.Equalf(t, span.Parent.SpanID(), rootSpan.SpanContext.SpanID(), "image service span %s %s should be child of root span", span.Name, span.Parent.SpanID())
}
for _, span := range runtimeServiceSpans {
assert.Equal(t, span.Parent.SpanID(), rootSpan.SpanContext.SpanID(), fmt.Sprintf("runtime service span %s %s should be child of root span", span.Name, span.Parent.SpanID()))
assert.Equalf(t, span.Parent.SpanID(), rootSpan.SpanContext.SpanID(), "runtime service span %s %s should be child of root span", span.Name, span.Parent.SpanID())
}
}

View File

@ -1525,6 +1525,6 @@ func TestTrimURLPath(t *testing.T) {
}
for _, test := range tests {
assert.Equal(t, test.expected, getURLRootPath(test.path), fmt.Sprintf("path is: %s", test.path))
assert.Equalf(t, test.expected, getURLRootPath(test.path), "path is: %s", test.path)
}
}

View File

@ -4811,7 +4811,7 @@ func TestTestInternalTrafficPolicyE2E(t *testing.T) {
realServers1, rsErr1 := ipvs.GetRealServers(virtualServers1[0])
assert.NoError(t, rsErr1, "Expected no error getting real servers")
assert.Len(t, realServers1, tc.expectLocalRealServerNum, fmt.Sprintf("Expected %d real servers", tc.expectLocalRealServerNum))
assert.Lenf(t, realServers1, tc.expectLocalRealServerNum, "Expected %d real servers", tc.expectLocalRealServerNum)
for i := 0; i < tc.expectLocalRealServerNum; i++ {
assert.Equal(t, realServers1[i].String(), tc.expectLocalRealServers[i])
}

View File

@ -18,7 +18,6 @@ package apparmor
import (
"errors"
"fmt"
"testing"
v1 "k8s.io/api/core/v1"
@ -45,9 +44,9 @@ func TestValidateBadHost(t *testing.T) {
for _, test := range tests {
err := v.Validate(getPodWithProfile(test.profile))
if test.expectValid {
assert.NoError(t, err, "Pod with profile %q should be valid", test.profile)
assert.NoErrorf(t, err, "Pod with profile %q should be valid", test.profile)
} else {
assert.Equal(t, hostErr, err, "Pod with profile %q should trigger a host validation error", test.profile)
assert.Equalf(t, hostErr, err, "Pod with profile %q should trigger a host validation error", test.profile)
}
}
}
@ -71,9 +70,9 @@ func TestValidateValidHost(t *testing.T) {
for _, test := range tests {
err := v.Validate(getPodWithProfile(test.profile))
if test.expectValid {
assert.NoError(t, err, "Pod with profile %q should be valid", test.profile)
assert.NoErrorf(t, err, "Pod with profile %q should be valid", test.profile)
} else {
assert.Error(t, err, fmt.Sprintf("Pod with profile %q should trigger a validation error", test.profile))
assert.Errorf(t, err, "Pod with profile %q should trigger a validation error", test.profile)
}
}