Skip to content

Commit

Permalink
Fix test scripts because -race and -skip don't coexist when running g…
Browse files Browse the repository at this point in the history
…o test
  • Loading branch information
taobig committed Jun 8, 2024
1 parent 4e7b5d5 commit 299d87c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ jobs:
# html格式查看cover信息: https://blog.golang.org/cover
# go test -covermode=count -coverprofile=count.out ./... && go tool cover -html=count.out
#
# 从go1.20开始test子命令才支持-skip参数
# 从go1.20开始test子命令才支持-skip参数,但是test的-skip和-race不能同时使用
run: |
nproc --all || sysctl -n hw.ncpu || grep -c ^processor /proc/cpuinfo || date
go vet ./...
nproc --all || sysctl -n hw.ncpu || grep -c ^processor /proc/cpuinfo || date
if [[ "${{ matrix.go }}" < "1.20" ]]; then
time go test -cover -v ./... && echo done
time go test -race -cover -v ./... && echo done
time SKIP_TEST_SEND_MAIL=1 go test -cover -v ./... && echo done
else
time go test -skip "^TestSendMail$" -cover -v ./... && echo done
time go test -race -skip "^TestSendMail$" -skip "^TestDataRaceError$" -cover -v ./... && echo done
fi
go vet ./...
time SKIP_TEST_SEND_MAIL=1 go test -race -cover -v ./... && echo done
# golangci-lint run #golangci-lint run --enable-all 如果手动执行,需要提前下载golangci-lint
# CI是通过golangci-lint.yml配置文件启用的

Expand Down
2 changes: 1 addition & 1 deletion lockedmap/lockedmap_race_bad_practice_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build go1.20
//go:build !race

package lockedmap

Expand Down
4 changes: 4 additions & 0 deletions mailx/mail_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package mailx

import (
"os"
"testing"
)

func TestSendMail(t *testing.T) {
if os.Getenv("SKIP_TEST_SEND_MAIL") != "" {
t.Skip("skip test send mail")
}
mail := NewSMTPMail("[email protected]", "password", "smtp.qq.com", 587)
receivers := []string{"[email protected]"}
body := `
Expand Down

0 comments on commit 299d87c

Please sign in to comment.