Skip to content

Commit

Permalink
Merge branch 'master' into kv-testify
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jun 7, 2022
2 parents 27c9a5b + 4133b9f commit 88472d2
Show file tree
Hide file tree
Showing 59 changed files with 797 additions and 478 deletions.
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ install-tools:

#### Static checks ####

check: install-tools static tidy check-plugin errdoc check-testing-t
check: install-tools static tidy generate-errdoc check-plugin check-test

static: install-tools
@ echo "gofmt ..."
Expand All @@ -160,21 +160,22 @@ tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

@ for mod in $(SUBMODULES); do cd $$mod && $(MAKE) tidy && cd - > /dev/null; done

generate-errdoc: install-tools
@echo "generating errors.toml..."
./scripts/generate-errdoc.sh

check-plugin:
@echo "checking plugin"
@echo "checking plugin..."
cd ./plugin/scheduler_example && $(MAKE) evictLeaderPlugin.so && rm evictLeaderPlugin.so

errdoc: install-tools
@echo "generator errors.toml"
./scripts/check-errdoc.sh

check-testing-t:
./scripts/check-testing-t.sh
check-test:
@echo "checking test..."
./scripts/check-test.sh

.PHONY: check static tidy check-plugin errdoc docker-build-test check-testing-t
.PHONY: check static tidy generate-errdoc check-plugin check-test

#### Test utils ####

Expand Down
2 changes: 2 additions & 0 deletions pkg/apiutil/apiutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

func TestJsonRespondErrorOk(t *testing.T) {
t.Parallel()
re := require.New(t)
rd := render.New(render.Options{
IndentJSON: true,
Expand All @@ -43,6 +44,7 @@ func TestJsonRespondErrorOk(t *testing.T) {
}

func TestJsonRespondErrorBadInput(t *testing.T) {
t.Parallel()
re := require.New(t)
rd := render.New(render.Options{
IndentJSON: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/assertutil/assertutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

func TestNilFail(t *testing.T) {
t.Parallel()
re := require.New(t)
var failErr error
checker := NewChecker(func() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

func TestLabelMatcher(t *testing.T) {
t.Parallel()
re := require.New(t)
matcher := &LabelMatcher{"testSuccess"}
labels1 := &BackendLabels{Labels: []string{"testFail", "testSuccess"}}
Expand All @@ -41,6 +42,7 @@ func TestLabelMatcher(t *testing.T) {
}

func TestPrometheusHistogramBackend(t *testing.T) {
t.Parallel()
re := require.New(t)
serviceAuditHistogramTest := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Expand Down Expand Up @@ -87,6 +89,7 @@ func TestPrometheusHistogramBackend(t *testing.T) {
}

func TestLocalLogBackendUsingFile(t *testing.T) {
t.Parallel()
re := require.New(t)
backend := NewLocalLogBackend(true)
fname := initLog()
Expand Down
5 changes: 5 additions & 0 deletions pkg/autoscaling/calculation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestGetScaledTiKVGroups(t *testing.T) {
t.Parallel()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -213,6 +214,7 @@ func (q *mockQuerier) Query(options *QueryOptions) (QueryResult, error) {
}

func TestGetTotalCPUUseTime(t *testing.T) {
t.Parallel()
re := require.New(t)
querier := &mockQuerier{}
instances := []instance{
Expand All @@ -235,6 +237,7 @@ func TestGetTotalCPUUseTime(t *testing.T) {
}

func TestGetTotalCPUQuota(t *testing.T) {
t.Parallel()
re := require.New(t)
querier := &mockQuerier{}
instances := []instance{
Expand All @@ -257,6 +260,7 @@ func TestGetTotalCPUQuota(t *testing.T) {
}

func TestScaleOutGroupLabel(t *testing.T) {
t.Parallel()
re := require.New(t)
var jsonStr = []byte(`
{
Expand Down Expand Up @@ -299,6 +303,7 @@ func TestScaleOutGroupLabel(t *testing.T) {
}

func TestStrategyChangeCount(t *testing.T) {
t.Parallel()
re := require.New(t)
var count uint64 = 2
strategy := &Strategy{
Expand Down
6 changes: 6 additions & 0 deletions pkg/autoscaling/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (c *normalClient) Do(_ context.Context, req *http.Request) (response *http.
}

func TestRetrieveCPUMetrics(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &normalClient{
mockData: make(map[string]*response),
Expand Down Expand Up @@ -225,6 +226,7 @@ func (c *emptyResponseClient) Do(_ context.Context, req *http.Request) (r *http.
}

func TestEmptyResponse(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &emptyResponseClient{}
querier := NewPrometheusQuerier(client)
Expand Down Expand Up @@ -252,6 +254,7 @@ func (c *errorHTTPStatusClient) Do(_ context.Context, req *http.Request) (r *htt
}

func TestErrorHTTPStatus(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &errorHTTPStatusClient{}
querier := NewPrometheusQuerier(client)
Expand All @@ -277,6 +280,7 @@ func (c *errorPrometheusStatusClient) Do(_ context.Context, req *http.Request) (
}

func TestErrorPrometheusStatus(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &errorPrometheusStatusClient{}
querier := NewPrometheusQuerier(client)
Expand All @@ -287,6 +291,7 @@ func TestErrorPrometheusStatus(t *testing.T) {
}

func TestGetInstanceNameFromAddress(t *testing.T) {
t.Parallel()
re := require.New(t)
testCases := []struct {
address string
Expand Down Expand Up @@ -324,6 +329,7 @@ func TestGetInstanceNameFromAddress(t *testing.T) {
}

func TestGetDurationExpression(t *testing.T) {
t.Parallel()
re := require.New(t)
testCases := []struct {
duration time.Duration
Expand Down
5 changes: 5 additions & 0 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestExpireRegionCache(t *testing.T) {
t.Parallel()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -115,6 +116,7 @@ func sortIDs(ids []uint64) []uint64 {
}

func TestLRUCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := newLRU(3)

Expand Down Expand Up @@ -192,6 +194,7 @@ func TestLRUCache(t *testing.T) {
}

func TestFifoCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := NewFIFO(3)
cache.Put(1, "1")
Expand Down Expand Up @@ -219,6 +222,7 @@ func TestFifoCache(t *testing.T) {
}

func TestTwoQueueCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := newTwoQueue(3)
cache.Put(1, "1")
Expand Down Expand Up @@ -303,6 +307,7 @@ func (pq PriorityQueueItemTest) ID() uint64 {
}

func TestPriorityQueue(t *testing.T) {
t.Parallel()
re := require.New(t)
testData := []PriorityQueueItemTest{0, 1, 2, 3, 4, 5}
pq := NewPriorityQueue(0)
Expand Down
2 changes: 2 additions & 0 deletions pkg/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

func TestDecodeBytes(t *testing.T) {
t.Parallel()
re := require.New(t)
key := "abcdefghijklmnopqrstuvwxyz"
for i := 0; i < len(key); i++ {
Expand All @@ -31,6 +32,7 @@ func TestDecodeBytes(t *testing.T) {
}

func TestTableID(t *testing.T) {
t.Parallel()
re := require.New(t)
key := EncodeBytes([]byte("t\x80\x00\x00\x00\x00\x00\x00\xff"))
re.Equal(int64(0xff), key.TableID())
Expand Down
4 changes: 4 additions & 0 deletions pkg/encryption/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

func TestAdjustDefaultValue(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{}
err := config.Adjust()
Expand All @@ -34,18 +35,21 @@ func TestAdjustDefaultValue(t *testing.T) {
}

func TestAdjustInvalidDataEncryptionMethod(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{DataEncryptionMethod: "unknown"}
re.NotNil(config.Adjust())
}

func TestAdjustNegativeRotationDuration(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{DataKeyRotationPeriod: typeutil.NewDuration(time.Duration(int64(-1)))}
re.NotNil(config.Adjust())
}

func TestAdjustInvalidMasterKeyType(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{MasterKey: MasterKeyConfig{Type: "unknown"}}
re.NotNil(config.Adjust())
Expand Down
5 changes: 5 additions & 0 deletions pkg/encryption/crypter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestEncryptionMethodSupported(t *testing.T) {
t.Parallel()
re := require.New(t)
re.NotNil(CheckEncryptionMethodSupported(encryptionpb.EncryptionMethod_PLAINTEXT))
re.NotNil(CheckEncryptionMethodSupported(encryptionpb.EncryptionMethod_UNKNOWN))
Expand All @@ -33,6 +34,7 @@ func TestEncryptionMethodSupported(t *testing.T) {
}

func TestKeyLength(t *testing.T) {
t.Parallel()
re := require.New(t)
_, err := KeyLength(encryptionpb.EncryptionMethod_PLAINTEXT)
re.NotNil(err)
Expand All @@ -50,6 +52,7 @@ func TestKeyLength(t *testing.T) {
}

func TestNewIv(t *testing.T) {
t.Parallel()
re := require.New(t)
ivCtr, err := NewIvCTR()
re.NoError(err)
Expand All @@ -60,6 +63,7 @@ func TestNewIv(t *testing.T) {
}

func TestNewDataKey(t *testing.T) {
t.Parallel()
re := require.New(t)
for _, method := range []encryptionpb.EncryptionMethod{
encryptionpb.EncryptionMethod_AES128_CTR,
Expand All @@ -78,6 +82,7 @@ func TestNewDataKey(t *testing.T) {
}

func TestAesGcmCrypter(t *testing.T) {
t.Parallel()
re := require.New(t)
key, err := hex.DecodeString("ed568fbd8c8018ed2d042a4e5d38d6341486922d401d2022fb81e47c900d3f07")
re.NoError(err)
Expand Down
8 changes: 8 additions & 0 deletions pkg/encryption/master_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestPlaintextMasterKey(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &encryptionpb.MasterKey{
Backend: &encryptionpb.MasterKey_Plaintext{
Expand All @@ -49,6 +50,7 @@ func TestPlaintextMasterKey(t *testing.T) {
}

func TestEncrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
key, err := hex.DecodeString(keyHex)
Expand All @@ -64,6 +66,7 @@ func TestEncrypt(t *testing.T) {
}

func TestDecrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
key, err := hex.DecodeString(keyHex)
Expand All @@ -80,6 +83,7 @@ func TestDecrypt(t *testing.T) {
}

func TestNewFileMasterKeyMissingPath(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &encryptionpb.MasterKey{
Backend: &encryptionpb.MasterKey_File{
Expand All @@ -93,6 +97,7 @@ func TestNewFileMasterKeyMissingPath(t *testing.T) {
}

func TestNewFileMasterKeyMissingFile(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -109,6 +114,7 @@ func TestNewFileMasterKeyMissingFile(t *testing.T) {
}

func TestNewFileMasterKeyNotHexString(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -126,6 +132,7 @@ func TestNewFileMasterKeyNotHexString(t *testing.T) {
}

func TestNewFileMasterKeyLengthMismatch(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -143,6 +150,7 @@ func TestNewFileMasterKeyLengthMismatch(t *testing.T) {
}

func TestNewFileMasterKey(t *testing.T) {
t.Parallel()
re := require.New(t)
key := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
dir, err := os.MkdirTemp("", "test_key_files")
Expand Down
Loading

0 comments on commit 88472d2

Please sign in to comment.