From 5156501a61da09ea8513c8fc1513635ba770c0c8 Mon Sep 17 00:00:00 2001 From: disksing Date: Mon, 10 May 2021 16:10:44 +0800 Subject: [PATCH] scripts: check duplicated `TestingT` (#3662) * scripts: check duplicated TestingT Signed-off-by: disksing * minor fix Signed-off-by: disksing * minor fix Signed-off-by: disksing * minor fix Signed-off-by: disksing * minor fix Signed-off-by: disksing --- Makefile | 6 +++--- pkg/autoscaling/prometheus_test.go | 5 ----- pkg/encryption/config_test.go | 5 ----- pkg/encryption/crypter_test.go | 2 +- pkg/encryption/master_key_test.go | 5 ----- pkg/encryption/region_crypter_test.go | 5 ----- pkg/typeutil/comparison_test.go | 2 +- pkg/typeutil/conversion_test.go | 6 ------ pkg/typeutil/size_test.go | 5 ----- scripts/{check-missing-tests.sh => check-testing-t.sh} | 10 ++++++++++ tools/pd-analysis/analysis/parse_log_test.go | 2 +- tools/pd-analysis/analysis/transfer_counter_test.go | 6 ------ 12 files changed, 16 insertions(+), 43 deletions(-) rename scripts/{check-missing-tests.sh => check-testing-t.sh} (63%) diff --git a/Makefile b/Makefile index 5d114e5d7ed..be6cf1a752d 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,7 @@ test-with-cover: install-go-tools dashboard-ui done @$(FAILPOINT_DISABLE) -check: install-go-tools check-all check-plugin errdoc check-missing-tests docker-build-test +check: install-go-tools check-all check-plugin errdoc check-testing-t docker-build-test check-all: static lint tidy @echo "checking" @@ -200,8 +200,8 @@ docker-build-test: fi docker build --no-cache -t tikv/pd . -check-missing-tests: - ./scripts/check-missing-tests.sh +check-testing-t: + ./scripts/check-testing-t.sh simulator: export GO111MODULE=on simulator: diff --git a/pkg/autoscaling/prometheus_test.go b/pkg/autoscaling/prometheus_test.go index 61ec5b274fd..0ad47398a5a 100644 --- a/pkg/autoscaling/prometheus_test.go +++ b/pkg/autoscaling/prometheus_test.go @@ -23,7 +23,6 @@ import ( "net/http" "net/url" "strings" - "testing" "time" . "github.com/pingcap/check" @@ -41,10 +40,6 @@ const ( instanceCount = 3 ) -func TestPrometheus(t *testing.T) { - TestingT(t) -} - var _ = Suite(&testPrometheusQuerierSuite{}) var podNameTemplate = map[ComponentType]string{ diff --git a/pkg/encryption/config_test.go b/pkg/encryption/config_test.go index 79253c23144..3d3f9498bd7 100644 --- a/pkg/encryption/config_test.go +++ b/pkg/encryption/config_test.go @@ -14,17 +14,12 @@ package encryption import ( - "testing" "time" . "github.com/pingcap/check" "github.com/tikv/pd/pkg/typeutil" ) -func TestConfig(t *testing.T) { - TestingT(t) -} - type testConfigSuite struct{} var _ = Suite(&testConfigSuite{}) diff --git a/pkg/encryption/crypter_test.go b/pkg/encryption/crypter_test.go index 5b5d3bbd987..823b5055727 100644 --- a/pkg/encryption/crypter_test.go +++ b/pkg/encryption/crypter_test.go @@ -22,7 +22,7 @@ import ( "github.com/pingcap/kvproto/pkg/encryptionpb" ) -func TestCrypter(t *testing.T) { +func Test(t *testing.T) { TestingT(t) } diff --git a/pkg/encryption/master_key_test.go b/pkg/encryption/master_key_test.go index 908308791b6..c71504113af 100644 --- a/pkg/encryption/master_key_test.go +++ b/pkg/encryption/master_key_test.go @@ -16,16 +16,11 @@ package encryption import ( "encoding/hex" "io/ioutil" - "testing" . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/encryptionpb" ) -func TestMasterKey(t *testing.T) { - TestingT(t) -} - type testMasterKeySuite struct{} var _ = Suite(&testMasterKeySuite{}) diff --git a/pkg/encryption/region_crypter_test.go b/pkg/encryption/region_crypter_test.go index 9778ae02981..d92288e3446 100644 --- a/pkg/encryption/region_crypter_test.go +++ b/pkg/encryption/region_crypter_test.go @@ -16,7 +16,6 @@ package encryption import ( "crypto/aes" "crypto/cipher" - "testing" . "github.com/pingcap/check" "github.com/pingcap/errors" @@ -24,10 +23,6 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" ) -func TestRegionCrypter(t *testing.T) { - TestingT(t) -} - type testRegionCrypterSuite struct{} var _ = Suite(&testRegionCrypterSuite{}) diff --git a/pkg/typeutil/comparison_test.go b/pkg/typeutil/comparison_test.go index 47a89a07426..8fae8a46c51 100644 --- a/pkg/typeutil/comparison_test.go +++ b/pkg/typeutil/comparison_test.go @@ -20,7 +20,7 @@ import ( . "github.com/pingcap/check" ) -func TestComparison(t *testing.T) { +func TestTypeUtil(t *testing.T) { TestingT(t) } diff --git a/pkg/typeutil/conversion_test.go b/pkg/typeutil/conversion_test.go index 0156430108d..0f311b65ba2 100644 --- a/pkg/typeutil/conversion_test.go +++ b/pkg/typeutil/conversion_test.go @@ -14,15 +14,9 @@ package typeutil import ( - "testing" - . "github.com/pingcap/check" ) -func TestConversion(t *testing.T) { - TestingT(t) -} - var _ = Suite(&testUint64BytesSuite{}) type testUint64BytesSuite struct{} diff --git a/pkg/typeutil/size_test.go b/pkg/typeutil/size_test.go index 9ab19265e1a..c817b4217b2 100644 --- a/pkg/typeutil/size_test.go +++ b/pkg/typeutil/size_test.go @@ -15,15 +15,10 @@ package typeutil import ( "encoding/json" - "testing" . "github.com/pingcap/check" ) -func TestSize(t *testing.T) { - TestingT(t) -} - var _ = Suite(&testSizeSuite{}) type testSizeSuite struct { diff --git a/scripts/check-missing-tests.sh b/scripts/check-testing-t.sh similarity index 63% rename from scripts/check-missing-tests.sh rename to scripts/check-testing-t.sh index e84b11b03fd..0697a007480 100755 --- a/scripts/check-missing-tests.sh +++ b/scripts/check-testing-t.sh @@ -11,4 +11,14 @@ if [ "$res" ]; then exit 1 fi +# Check if there are duplicated `TestingT` in package. + +res=$(grep -r --include=\*_test.go "TestingT(" . | cut -f1 | xargs -L 1 dirname | sort | uniq -d) + +if [ "$res" ]; then + echo "following packages may have duplicated TestingT:" + echo "$res" + exit 1 +fi + exit 0 diff --git a/tools/pd-analysis/analysis/parse_log_test.go b/tools/pd-analysis/analysis/parse_log_test.go index f3d36c717af..7dd989122fb 100644 --- a/tools/pd-analysis/analysis/parse_log_test.go +++ b/tools/pd-analysis/analysis/parse_log_test.go @@ -20,7 +20,7 @@ import ( . "github.com/pingcap/check" ) -func TestParser(t *testing.T) { +func Test(t *testing.T) { TestingT(t) } diff --git a/tools/pd-analysis/analysis/transfer_counter_test.go b/tools/pd-analysis/analysis/transfer_counter_test.go index da8d2036c8a..38d24244714 100644 --- a/tools/pd-analysis/analysis/transfer_counter_test.go +++ b/tools/pd-analysis/analysis/transfer_counter_test.go @@ -14,15 +14,9 @@ package analysis import ( - "testing" - . "github.com/pingcap/check" ) -func TestCounter(t *testing.T) { - TestingT(t) -} - var _ = Suite(&testTransferRegionCounter{}) type testTransferRegionCounter struct{}