Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ build_for_integration_test:
) || (make failpoint-disable && exit 1)
@make failpoint-disable

test: export ARGS=$$($(PACKAGES))
test:
$(PREPARE_MOD)
@make failpoint-enable
$(GOTEST) $(RACEFLAG) -tags leak $$($(PACKAGES)) || ( make failpoint-disable && exit 1 )
$(GOTEST) $(RACEFLAG) -tags br_test,leak $(ARGS) || ( make failpoint-disable && exit 1 )
@make failpoint-disable

testcover: tools
mkdir -p "$(TEST_DIR)"
$(PREPARE_MOD)
@make failpoint-enable
$(GOTEST) -cover -covermode=count -coverprofile="$(TEST_DIR)/cov.unit.out" \
$(GOTEST) -tags br_test -cover -covermode=count -coverprofile="$(TEST_DIR)/cov.unit.out" \
$$($(COVERED_PACKAGES)) || ( make failpoint-disable && exit 1 )
@make failpoint-disable

Expand Down Expand Up @@ -188,7 +189,7 @@ static: prepare tools
@# exhaustivestruct - Protobuf structs have hidden fields, like "XXX_NoUnkeyedLiteral"
@# exhaustive - no need to check exhaustiveness of enum switch statements
@# gosec - too many false positive
CGO_ENABLED=0 tools/bin/golangci-lint run --enable-all --deadline 120s \
CGO_ENABLED=0 tools/bin/golangci-lint run --enable-all --build-tags br_test --deadline 120s \
--disable gochecknoglobals \
--disable goimports \
--disable gofmt \
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/mock/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0.

// This file avoids mock being an empty package when `-tags br_test` is not provided.

package mock
6 changes: 4 additions & 2 deletions pkg/mock/glue.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/glue_checkpoint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/importer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/mock_cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

//+build br_test

package mock

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/mock_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

//+build br_test

package mock_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/s3iface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
This folder contains all tests which relies on external processes such as TiDB.
# Unit tests

Unit tests (the `*_test.go` files inside the source directory) should *never* rely on external
programs.

Run `make test` to execute all unit tests.

To run a specific test, pass `ARGS` into `make test` like

```sh
make test ARGS='github.com/pingcap/br/pkg/cdclog --test.v --check.v --check.f TestColumn'
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# which package to test more extra test flags
```

You can also run unit tests directly via `go test` like:

```sh
make failpoint-enable

go test -tags br_test github.com/pingcap/br/pkg/cdclog --test.v --check.v --check.f TestColumn
# ^~~~~~~~~~~~~

make failpoint-disable
```

but note that:

* the build-tag `br_test` must be enabled (this workarounds the lack of test-dependencies in go.mod)
* failpoints must be toggled manually

# Integration tests

This folder contains all tests which relies on external processes such as TiDB.

## Preparations

1. The following 9 executables must be copied or linked into these locations:
Expand Down Expand Up @@ -39,7 +69,6 @@ If you have docker installed, you can skip step 1 and step 2 by running

## Running

Run `make test` to execute the unit tests.
Run `make integration_test` to execute the integration tests. This command will

1. Build `br`
Expand Down