From 9e6e6ebe757e2f79086eb262ca2a23df021e60ed Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 27 Dec 2024 12:17:21 +0800 Subject: [PATCH] fix lint issue Signed-off-by: Ryan Leung --- pkg/cgroup/cgroup_cpu_test.go | 5 ++--- pkg/core/region_test.go | 4 ++-- pkg/mcs/resourcemanager/server/metrics_test.go | 5 ++--- pkg/mcs/resourcemanager/server/token_buckets_test.go | 7 +++---- pkg/tso/keyspace_group_manager_test.go | 6 +++--- pkg/window/policy_test.go | 9 ++++----- tests/integrations/realcluster/cluster.go | 3 +-- tests/server/api/api_test.go | 4 ++-- tools/pd-ctl/tests/scheduler/scheduler_test.go | 12 ++++++------ 9 files changed, 25 insertions(+), 30 deletions(-) diff --git a/pkg/cgroup/cgroup_cpu_test.go b/pkg/cgroup/cgroup_cpu_test.go index 441c2192e79..6d4d8f39f49 100644 --- a/pkg/cgroup/cgroup_cpu_test.go +++ b/pkg/cgroup/cgroup_cpu_test.go @@ -17,7 +17,6 @@ package cgroup import ( - "fmt" "regexp" "runtime" "strconv" @@ -45,10 +44,10 @@ func checkKernelVersionNewerThan(re *require.Assertions, t *testing.T, major, mi t.Log("kernel release string:", releaseStr) versionInfoRE := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`) kernelVersion := versionInfoRE.FindAllString(releaseStr, 1) - re.Len(kernelVersion, 1, fmt.Sprintf("release str is %s", releaseStr)) + re.Lenf(kernelVersion, 1, "release str is %s", releaseStr) kernelVersionPartRE := regexp.MustCompile(`[0-9]+`) kernelVersionParts := kernelVersionPartRE.FindAllString(kernelVersion[0], -1) - re.Len(kernelVersionParts, 3, fmt.Sprintf("kernel version str is %s", kernelVersion[0])) + re.Lenf(kernelVersionParts, 3, "kernel version str is %s", kernelVersion[0]) t.Logf("parsed kernel version parts: major %s, minor %s, patch %s", kernelVersionParts[0], kernelVersionParts[1], kernelVersionParts[2]) mustConvInt := func(s string) int { diff --git a/pkg/core/region_test.go b/pkg/core/region_test.go index 51ba5fe96dc..473421b0e52 100644 --- a/pkg/core/region_test.go +++ b/pkg/core/region_test.go @@ -985,10 +985,10 @@ func TestUpdateRegionEquivalence(t *testing.T) { checkRegions(re, regionsNew) for _, r := range regionsOld.GetRegions() { - re.Equal(int32(2), r.GetRef(), fmt.Sprintf("inconsistent region %d", r.GetID())) + re.Equalf(int32(2), r.GetRef(), "inconsistent region %d", r.GetID()) } for _, r := range regionsNew.GetRegions() { - re.Equal(int32(2), r.GetRef(), fmt.Sprintf("inconsistent region %d", r.GetID())) + re.Equalf(int32(2), r.GetRef(), "inconsistent region %d", r.GetID()) } for i := 1; i <= storeNums; i++ { diff --git a/pkg/mcs/resourcemanager/server/metrics_test.go b/pkg/mcs/resourcemanager/server/metrics_test.go index 4c3ec7ce5ef..97b21bf5ce3 100644 --- a/pkg/mcs/resourcemanager/server/metrics_test.go +++ b/pkg/mcs/resourcemanager/server/metrics_test.go @@ -15,7 +15,6 @@ package server import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -43,8 +42,8 @@ func TestMaxPerSecCostTracker(t *testing.T) { // Check the max values at the end of each flushPeriod if (i+1)%20 == 0 { period := i / 20 - re.Equal(tracker.maxPerSecRRU, expectedMaxRU[period], fmt.Sprintf("maxPerSecRRU in period %d is incorrect", period+1)) - re.Equal(tracker.maxPerSecWRU, expectedMaxRU[period], fmt.Sprintf("maxPerSecWRU in period %d is incorrect", period+1)) + re.Equalf(tracker.maxPerSecRRU, expectedMaxRU[period], "maxPerSecRRU in period %d is incorrect", period+1) + re.Equalf(tracker.maxPerSecWRU, expectedMaxRU[period], "maxPerSecWRU in period %d is incorrect", period+1) re.Equal(tracker.rruSum, expectedSum[period]) re.Equal(tracker.rruSum, expectedSum[period]) } diff --git a/pkg/mcs/resourcemanager/server/token_buckets_test.go b/pkg/mcs/resourcemanager/server/token_buckets_test.go index b56ccb6ab96..676b1127f35 100644 --- a/pkg/mcs/resourcemanager/server/token_buckets_test.go +++ b/pkg/mcs/resourcemanager/server/token_buckets_test.go @@ -15,7 +15,6 @@ package server import ( - "fmt" "math" "testing" "time" @@ -182,9 +181,9 @@ func TestGroupTokenBucketRequestLoop(t *testing.T) { currentTime := initialTime for i, tc := range testCases { tb, trickle := gtb.request(currentTime, tc.requestTokens, uint64(targetPeriod)/uint64(time.Millisecond), clientUniqueID) - re.Equal(tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens, fmt.Sprintf("Test case %d failed: expected bucket tokens %f, got %f", i, tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens)) - re.LessOrEqual(math.Abs(tb.Tokens-tc.assignedTokens), 1e-7, fmt.Sprintf("Test case %d failed: expected tokens %f, got %f", i, tc.assignedTokens, tb.Tokens)) - re.Equal(tc.expectedTrickleMs, trickle, fmt.Sprintf("Test case %d failed: expected trickle %d, got %d", i, tc.expectedTrickleMs, trickle)) + re.Equalf(tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens, "Test case %d failed: expected bucket tokens %f, got %f", i, tc.globalBucketTokensAfterAssign, gtb.GetTokenBucket().Tokens) + re.LessOrEqualf(math.Abs(tb.Tokens-tc.assignedTokens), 1e-7, "Test case %d failed: expected tokens %f, got %f", i, tc.assignedTokens, tb.Tokens) + re.Equalf(tc.expectedTrickleMs, trickle, "Test case %d failed: expected trickle %d, got %d", i, tc.expectedTrickleMs, trickle) currentTime = currentTime.Add(timeIncrement) } } diff --git a/pkg/tso/keyspace_group_manager_test.go b/pkg/tso/keyspace_group_manager_test.go index b4393a23471..c54bbcc1b33 100644 --- a/pkg/tso/keyspace_group_manager_test.go +++ b/pkg/tso/keyspace_group_manager_test.go @@ -886,7 +886,7 @@ func collectAssignedKeyspaceGroupIDs(re *require.Assertions, kgm *KeyspaceGroupM for i := range kgm.kgs { kg := kgm.kgs[i] if kg == nil { - re.Nil(kgm.ams[i], fmt.Sprintf("ksg is nil but am is not nil for id %d", i)) + re.Nilf(kgm.ams[i], "ksg is nil but am is not nil for id %d", i) } else { am := kgm.ams[i] if am != nil { @@ -976,8 +976,8 @@ func (suite *keyspaceGroupManagerTestSuite) TestUpdateKeyspaceGroupMembership() func verifyLocalKeyspaceLookupTable( re *require.Assertions, keyspaceLookupTable map[uint32]struct{}, newKeyspaces []uint32, ) { - re.Equal(len(newKeyspaces), len(keyspaceLookupTable), - fmt.Sprintf("%v %v", newKeyspaces, keyspaceLookupTable)) + re.Equalf(len(newKeyspaces), len(keyspaceLookupTable), + "%v %v", newKeyspaces, keyspaceLookupTable) for _, keyspace := range newKeyspaces { _, ok := keyspaceLookupTable[keyspace] re.True(ok) diff --git a/pkg/window/policy_test.go b/pkg/window/policy_test.go index 936360ccb2b..b5a04c03e4b 100644 --- a/pkg/window/policy_test.go +++ b/pkg/window/policy_test.go @@ -18,7 +18,6 @@ package window import ( - "fmt" "math" "testing" "time" @@ -79,11 +78,11 @@ func TestRollingPolicy_Add(t *testing.T) { asExpected = false } if asExpected { - re.Less(math.Abs(point-policy.window.buckets[offset].Points[0]), 1e-6, - fmt.Sprintf("error, time since last append: %vms, last offset: %v", totalTS, lastOffset)) + re.Lessf(math.Abs(point-policy.window.buckets[offset].Points[0]), 1e-6, + "error, time since last append: %vms, last offset: %v", totalTS, lastOffset) } - re.Less(math.Abs(points[i]-policy.window.buckets[offset].Points[0]), 1e-6, - fmt.Sprintf("error, time since last append: %vms, last offset: %v", totalTS, lastOffset)) + re.Lessf(math.Abs(points[i]-policy.window.buckets[offset].Points[0]), 1e-6, + "error, time since last append: %vms, last offset: %v", totalTS, lastOffset) lastOffset = offset } }) diff --git a/tests/integrations/realcluster/cluster.go b/tests/integrations/realcluster/cluster.go index cc4f6b54713..fc5d1bc4441 100644 --- a/tests/integrations/realcluster/cluster.go +++ b/tests/integrations/realcluster/cluster.go @@ -185,6 +185,5 @@ func waitTiupReady(t *testing.T, tag string) { zap.String("tag", tag), zap.Error(err)) time.Sleep(time.Duration(interval) * time.Second) } - // this check can trigger the cleanup function - require.NotZero(t, 1, "TiUP is not ready", "tag: %s", tag) + require.FailNowf(t, "TiUP is not ready after retry: %s", tag) } diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index 00c43d11309..faa22ce08f4 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -173,8 +173,8 @@ func (suite *middlewareTestSuite) TestRequestInfoMiddleware() { re.Equal(http.StatusOK, resp.StatusCode) re.Equal("Profile", resp.Header.Get("service-label")) - re.Equal("{\"seconds\":[\"1\"]}", resp.Header.Get("url-param")) - re.Equal("{\"testkey\":\"testvalue\"}", resp.Header.Get("body-param")) + re.JSONEq("{\"seconds\":[\"1\"]}", resp.Header.Get("url-param")) + re.JSONEq("{\"testkey\":\"testvalue\"}", resp.Header.Get("body-param")) re.Equal("HTTP/1.1/POST:/pd/api/v1/debug/pprof/profile", resp.Header.Get("method")) re.Equal("anonymous", resp.Header.Get("caller-id")) re.Equal("127.0.0.1", resp.Header.Get("ip")) diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 787bdaa4521..f3a81845921 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -186,18 +186,18 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { case "grant-leader-scheduler": return "paused", !storeInfo.AllowLeaderTransferOut() default: - re.Fail(fmt.Sprintf("unknown scheduler %s", schedulerName)) + re.Failf("unknown scheduler %s", schedulerName) return "", false } }() if slice.AnyOf(changedStores, func(i int) bool { return store.GetId() == changedStores[i] }) { - re.True(isStorePaused, - fmt.Sprintf("store %d should be %s with %s", store.GetId(), status, schedulerName)) + re.Truef(isStorePaused, + "store %d should be %s with %s", store.GetId(), status, schedulerName) } else { - re.False(isStorePaused, - fmt.Sprintf("store %d should not be %s with %s", store.GetId(), status, schedulerName)) + re.Falsef(isStorePaused, + "store %d should not be %s with %s", store.GetId(), status, schedulerName) } if sche := cluster.GetSchedulingPrimaryServer(); sche != nil { switch schedulerName { @@ -206,7 +206,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { case "grant-leader-scheduler": re.Equal(isStorePaused, !sche.GetCluster().GetStore(store.GetId()).AllowLeaderTransferOut()) default: - re.Fail(fmt.Sprintf("unknown scheduler %s", schedulerName)) + re.Failf("unknown scheduler %s", schedulerName) } } }