Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 95c00d2

Browse files
authored
tool: add revive (#164)
* lint Signed-off-by: mahjonp <[email protected]> * fix tidy Signed-off-by: mahjonp <[email protected]>
1 parent d76d6cf commit 95c00d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+532
-460
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ jobs:
1111
script:
1212
- make tidy
1313
- make fmt
14+
- make lint
1415
- make test
1516
- make build

Makefile

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ GOBUILD=$(GO) build -ldflags '$(LDFLAGS)'
1313

1414
DOCKER_REGISTRY_PREFIX := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)
1515

16-
default: build
16+
default: tidy fmt lint build
1717

18-
all: build
19-
20-
chaos: tidb
21-
22-
build: fmt tidb pocket tpcc ledger txn-rand-pessimistic on-dup sqllogic block-writer \
18+
build: tidb pocket tpcc ledger txn-rand-pessimistic on-dup sqllogic block-writer \
2319
region-available deadlock-detector crud bank bank2 abtest cdc-pocket tiflash-pocket
2420

2521
tidb:
@@ -90,6 +86,13 @@ tidy:
9086
GO111MODULE=on go mod tidy
9187
@git diff --exit-code -- go.mod
9288

89+
lint: revive
90+
@echo "linting"
91+
revive -formatter friendly -config revive.toml $$($(PACKAGES))
92+
93+
revive:
94+
$(GO) get github.com/mgechev/[email protected]
95+
9396
groupimports: install-goimports
9497
goimports -w -l -local github.com/pingcap/tipocket $$($(PACKAGE_DIRECTORIES))
9598

cmd/bank/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func main() {
6565
suit := util.Suit{
6666
Config: &cfg,
6767
Provisioner: cluster.NewK8sProvisioner(),
68-
ClientCreator: bank.CaseCreator{Cfg: &bankConfig},
68+
ClientCreator: bank.ClientCreator{Cfg: &bankConfig},
6969
NemesisGens: util.ParseNemesisGenerators(fixture.Context.Nemesis),
7070
ClusterDefs: tidb.RecommendedTiDBCluster(fixture.Context.Namespace, fixture.Context.Namespace, fixture.Context.ImageVersion),
7171
}

cmd/bank2/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func main() {
5959
suit := util.Suit{
6060
Config: &cfg,
6161
Provisioner: cluster.NewK8sProvisioner(),
62-
ClientCreator: bank2.CaseCreator{Cfg: &bank2.Config{
62+
ClientCreator: bank2.ClientCreator{Cfg: &bank2.Config{
6363
NumAccounts: *accounts,
6464
Interval: *interval,
6565
TableNum: *tables,

cmd/block-writer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444
suit := util.Suit{
4545
Config: &cfg,
4646
Provisioner: cluster.NewK8sProvisioner(),
47-
ClientCreator: blockwriter.CaseCreator{TableNum: *tables, Concurrency: *concurrency},
47+
ClientCreator: blockwriter.ClientCreator{TableNum: *tables, Concurrency: *concurrency},
4848
NemesisGens: util.ParseNemesisGenerators(fixture.Context.Nemesis),
4949
ClusterDefs: tidb.RecommendedTiDBCluster(fixture.Context.Namespace, fixture.Context.Namespace, fixture.Context.ImageVersion),
5050
}

cmd/crud/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
suit := util.Suit{
3636
Config: &cfg,
3737
Provisioner: cluster.NewK8sProvisioner(),
38-
ClientCreator: crud.CaseCreator{Cfg: &crud.Config{
38+
ClientCreator: crud.ClientCreator{Cfg: &crud.Config{
3939
DBName: *dbName,
4040
UserCount: *userCount,
4141
PostCount: *postCount,

cmd/deadlock-detector/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
suit := util.Suit{
4848
Config: &cfg,
4949
Provisioner: cluster.NewK8sProvisioner(),
50-
ClientCreator: dlc.CaseCreator{Cfg: &dlc.Config{
50+
ClientCreator: dlc.ClientCreator{Cfg: &dlc.Config{
5151
DBName: *dbName,
5252
TableNum: *tableNum,
5353
DeadlockInterval: *deadlockInterval,

cmd/ledger/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func main() {
4848
suit := util.Suit{
4949
Config: &cfg,
5050
Provisioner: cluster.NewK8sProvisioner(),
51-
ClientCreator: ledger.CaseCreator{Cfg: &ledger.Config{
51+
ClientCreator: ledger.ClientCreator{Cfg: &ledger.Config{
5252
NumAccounts: *accounts,
5353
Concurrency: *concurrency,
5454
Interval: *interval,

cmd/on-dup/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
suit := util.Suit{
4646
Config: &cfg,
4747
Provisioner: cluster.NewK8sProvisioner(),
48-
ClientCreator: ondup.CaseCreator{Cfg: &ondup.Config{
48+
ClientCreator: ondup.ClientCreator{Cfg: &ondup.Config{
4949
DBName: *dbName,
5050
NumRows: *numRows,
5151
RetryLimit: *retryLimit,

cmd/region-available/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func main() {
3232
suit := util.Suit{
3333
Config: &cfg,
3434
Provisioner: cluster.NewK8sProvisioner(),
35-
ClientCreator: ra.CaseCreator{Cfg: &ra.Config{
35+
ClientCreator: ra.ClientCreator{Cfg: &ra.Config{
3636
DBName: *dbName,
3737
TotalRows: *totalRows,
3838
Concurrency: *concurrency,

cmd/sqllogic/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main() {
4646
suit := util.Suit{
4747
Config: &cfg,
4848
Provisioner: cluster.NewK8sProvisioner(),
49-
ClientCreator: &sqllogictest.CaseCreator{
49+
ClientCreator: &sqllogictest.ClientCreator{
5050
Config: &sqllogictest.Config{
5151
SkipError: *skipError,
5252
TaskCount: *taskCount,

cmd/txn-rand-pessimistic/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func main() {
7777
suit := util.Suit{
7878
Config: &cfg,
7979
Provisioner: cluster.NewK8sProvisioner(),
80-
ClientCreator: pessimistic.CaseCreator{Cfg: &pessimistic.Config{
81-
PessimisticCaseConfig: pessimistic.PessimisticCaseConfig{
80+
ClientCreator: pessimistic.ClientCreator{Cfg: &pessimistic.Config{
81+
PessimisticClientConfig: pessimistic.ClientConfig{
8282
DBName: *randTxnDBName,
8383
Concurrency: *randTxnConcurrency,
8484
TableNum: *tableNum,
@@ -90,7 +90,7 @@ func main() {
9090
IgnoreCodesP: ignoreCodesP,
9191
UsePrepareStmt: *prepareStmt,
9292
},
93-
HongbaoCaseConfig: hongbao.HongbaoCaseConfig{
93+
HongbaoClientConfig: hongbao.ClientConfig{
9494
DBName: *hongbaoDBName,
9595
Concurrency: *hongbaoConcurrency,
9696
UserNum: *userNum,

cmd/util/suit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (suit *Suit) Run(ctx context.Context) {
9898
suit.NemesisGens,
9999
suit.ClientRequestGen,
100100
suit.VerifySuit,
101-
loki.NewLokiClient(fixture.Context.LokiAddress,
101+
loki.NewClient(fixture.Context.LokiAddress,
102102
fixture.Context.LokiUsername, fixture.Context.LokiPassword),
103103
)
104104

db/tidb/tpcc.go

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type TPCCClientCreator struct {
105105
tpccClient []*tpccClient
106106
}
107107

108+
// Create ...
108109
func (t *TPCCClientCreator) Create(_ clusterTypes.ClientNode) core.Client {
109110
client := &tpccClient{
110111
Config: t.Config,
@@ -130,6 +131,7 @@ func (t tpccResponse) IsUnknown() bool {
130131
type tpccParser struct {
131132
}
132133

134+
// TPCCParser ...
133135
func TPCCParser() history.RecordParser {
134136
return tpccParser{}
135137
}
@@ -154,10 +156,12 @@ func (t tpccParser) OnState(state json.RawMessage) (interface{}, error) {
154156
return nil, nil
155157
}
156158

159+
// TPCCChecker ...
157160
type TPCCChecker struct {
158161
CreatorRef *TPCCClientCreator
159162
}
160163

164+
// Check ...
161165
func (t *TPCCChecker) Check(m core.Model, ops []core.Operation) (bool, error) {
162166
for _, client := range t.CreatorRef.tpccClient {
163167
if err := client.Check(); err != nil {
@@ -172,6 +176,7 @@ func (t *TPCCChecker) Check(m core.Model, ops []core.Operation) (bool, error) {
172176
return false, nil
173177
}
174178

179+
// Name ...
175180
func (t *TPCCChecker) Name() string {
176181
return "tpcc"
177182
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/google/uuid v1.1.1
1111
github.com/grafana/loki v1.3.1-0.20200316172301-1eb139c37c1c
1212
github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9
13+
github.com/mgechev/revive v1.0.2
1314
github.com/ngaut/log v0.0.0-20180314031856-b8e36e7ba5ac
1415
github.com/pingcap/advanced-statefulset v0.3.2
1516
github.com/pingcap/chaos-mesh v0.0.0-20200221071630-a3e79a893072

0 commit comments

Comments
 (0)