Skip to content

Commit

Permalink
cmd, dumpling: enable golangci-lint check (#31732)
Browse files Browse the repository at this point in the history
close #31737
  • Loading branch information
tangenta authored Jan 20, 2022
1 parent 06a4dfa commit 409f091
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ goword:tools/bin/goword
tools/bin/goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

check-static: tools/bin/golangci-lint
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES_TIDB_TESTS)) --config .golangci.yml
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES)) --config .golangci.yml

unconvert:tools/bin/unconvert
@echo "unconvert check(skip check the genenrated or copied code in lightning)"
Expand All @@ -64,7 +64,7 @@ lint:tools/bin/revive

vet:
@echo "vet"
$(GO) vet -all $(PACKAGES_TIDB_TESTS_WITHOUT_BR) 2>&1 | $(FAIL_ON_STDOUT)
$(GO) vet -all $(PACKAGES_TIDB_TESTS) 2>&1 | $(FAIL_ON_STDOUT)

tidy:
@echo "go mod tidy"
Expand Down Expand Up @@ -122,7 +122,7 @@ devgotest: failpoint-enable
# - 'ok ' to ignore passed directories
@echo "Running in native mode."
@export log_level=info; export TZ='Asia/Shanghai'; \
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -cover $(PACKAGES_TIDB_TESTS_WITHOUT_BR) -check.p true > gotest.log || { $(FAILPOINT_DISABLE); grep -v '^\([[]20\|PASS:\|ok \)' 'gotest.log'; exit 1; }
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -cover $(PACKAGES_TIDB_TESTS) -check.p true > gotest.log || { $(FAILPOINT_DISABLE); grep -v '^\([[]20\|PASS:\|ok \)' 'gotest.log'; exit 1; }
@$(FAILPOINT_DISABLE)

ut: failpoint-enable tools/bin/ut
Expand All @@ -132,7 +132,7 @@ ut: failpoint-enable tools/bin/ut
gotest: failpoint-enable
@echo "Running in native mode."
@export log_level=info; export TZ='Asia/Shanghai'; \
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -timeout 20m -cover $(PACKAGES_TIDB_TESTS_WITHOUT_BR) -coverprofile=coverage.txt -check.p true > gotest.log || { $(FAILPOINT_DISABLE); cat 'gotest.log'; exit 1; }
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -timeout 20m -cover $(PACKAGES_TIDB_TESTS) -coverprofile=coverage.txt -check.p true > gotest.log || { $(FAILPOINT_DISABLE); cat 'gotest.log'; exit 1; }
@$(FAILPOINT_DISABLE)

gotest_in_verify_ci: failpoint-enable tools/bin/gotestsum
Expand All @@ -141,7 +141,7 @@ gotest_in_verify_ci: failpoint-enable tools/bin/gotestsum
@export TZ='Asia/Shanghai'; \
CGO_ENABLED=1 tools/bin/gotestsum --junitfile "$(TEST_COVERAGE_DIR)/tidb-junit-report.xml" -- -v -p $(P) \
-ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -coverprofile="$(TEST_COVERAGE_DIR)/tidb_cov.unit_test.out" \
$(PACKAGES_TIDB_TESTS_WITHOUT_BR) -check.p true || { $(FAILPOINT_DISABLE); exit 1; }
$(PACKAGES_TIDB_TESTS) -check.p true || { $(FAILPOINT_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)

race: failpoint-enable
Expand Down
6 changes: 2 additions & 4 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ LINUX := "Linux"
MAC := "Darwin"

PACKAGE_LIST := go list ./...
PACKAGE_LIST_TIDB_TESTS := go list ./... | grep -vE "github.com\/pingcap\/tidb\/cmd|github.com\/pingcap\/tidb\/dumpling"
PACKAGE_LIST_TIDB_TESTS := go list ./... | grep -vE "github.com\/pingcap\/tidb\/br|github.com\/pingcap\/tidb\/cmd|github.com\/pingcap\/tidb\/dumpling"
PACKAGES ?= $$($(PACKAGE_LIST))
PACKAGES_TIDB_TESTS ?= $$($(PACKAGE_LIST_TIDB_TESTS))
PACKAGES_TIDB_TESTS_WITHOUT_BR ?= $$($(PACKAGE_LIST_TIDB_TESTS) | grep -v "br")
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
PACKAGE_DIRECTORIES_TIDB_TESTS := $(PACKAGE_LIST_TIDB_TESTS) | sed 's|github.com/pingcap/$(PROJECT)/||'
PACKAGE_DIRECTORIES_TIDB_TESTS_WITHOUT_BR := $(PACKAGE_LIST_TIDB_TESTS) | sed 's|github.com/pingcap/$(PROJECT)/||' | grep -v "br"
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
FILES_TIDB_TESTS := $$(find $$($(PACKAGE_DIRECTORIES_TIDB_TESTS_WITHOUT_BR)) -name "*.go")
FILES_TIDB_TESTS := $$(find $$($(PACKAGE_DIRECTORIES_TIDB_TESTS)) -name "*.go")

UNCONVERT_PACKAGES_LIST := go list ./...| grep -vE "lightning\/checkpoints|lightning\/manual|lightning\/common"
UNCONVERT_PACKAGES := $$($(UNCONVERT_PACKAGES_LIST))
Expand Down
2 changes: 1 addition & 1 deletion cmd/importer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func genRowDatas(table *table, count int) ([]string, error) {
}

func genRowData(table *table) (string, error) {
var values []byte
var values []byte // nolint: prealloc
for _, column := range table.columns {
data, err := genColumnData(table, column)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/importer/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func randDate(col *column) string {
log.Warn("parse min date failed", zap.Error(err))
}
if max == "" {
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour)
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour) // nolint: durationcheck
return fmt.Sprintf("%04d-%02d-%02d", t.Year(), t.Month(), t.Day())
}

Expand All @@ -96,7 +96,7 @@ func randDate(col *column) string {
log.Warn("parse max date failed", zap.Error(err))
}
days := int(maxTime.Sub(minTime).Hours() / 24)
t := minTime.Add(time.Duration(randInt(0, days)) * 24 * time.Hour)
t := minTime.Add(time.Duration(randInt(0, days)) * 24 * time.Hour) // nolint: durationcheck
return fmt.Sprintf("%04d-%02d-%02d", t.Year(), t.Month(), t.Day())
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func randTimestamp(col *column) string {
log.Warn("parse min timestamp failed", zap.Error(err))
}
if max == "" {
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour)
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour) // nolint: durationcheck
return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
}

Expand Down
5 changes: 2 additions & 3 deletions dumpling/export/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
package export

import (
"github.com/pingcap/tidb/br/pkg/version"
"testing"

"github.com/stretchr/testify/require"

"github.com/pingcap/tidb/br/pkg/version"
tcontext "github.com/pingcap/tidb/dumpling/context"
"github.com/stretchr/testify/require"
)

func TestCreateExternalStorage(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions dumpling/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,5 +1438,8 @@ func GetCharsetAndDefaultCollation(ctx context.Context, db *sql.Conn) (map[strin
if err = rows.Close(); err != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
}
if rows.Err() != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
}
return charsetAndDefaultCollation, err
}
13 changes: 1 addition & 12 deletions dumpling/export/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/go-sql-driver/mysql"

"github.com/DATA-DOG/go-sqlmock"
"github.com/coreos/go-semver/semver"
"github.com/pingcap/errors"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -375,7 +374,7 @@ func TestListPolicyNames(t *testing.T) {
expectedErr := &mysql.MySQLError{Number: ErrNoSuchTable, Message: "Table 'information_schema.placement_policies' doesn't exist"}
mock.ExpectExec("select distinct policy_name from information_schema.placement_policies where policy_name is not null;").
WillReturnError(expectedErr)
policies, err = ListAllPlacementPolicyNames(conn)
_, err = ListAllPlacementPolicyNames(conn)
if mysqlErr, ok := err.(*mysql.MySQLError); ok {
require.Equal(t, mysqlErr.Number, ErrNoSuchTable)
}
Expand Down Expand Up @@ -1760,13 +1759,3 @@ func TestGetCharsetAndDefaultCollation(t *testing.T) {
require.Equal(t, "utf8mb4_0900_ai_ci", charsetAndDefaultCollation["utf8mb4"])
require.Equal(t, "latin1_swedish_ci", charsetAndDefaultCollation["latin1"])
}

func makeVersion(major, minor, patch int64, preRelease string) *semver.Version {
return &semver.Version{
Major: major,
Minor: minor,
Patch: patch,
PreRelease: semver.PreRelease(preRelease),
Metadata: "",
}
}

0 comments on commit 409f091

Please sign in to comment.