From a19a9feb5202f4724c2c6527e2351d2e8440cfc7 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Wed, 16 Aug 2023 22:29:36 +0800 Subject: [PATCH] Chore: added a new test CI to run unit test and build test for Pull Requests (#2883) --- .github/workflows/release.yml | 4 --- .github/workflows/test.yaml | 60 +++++++++++++++++++++++++++++++++++ Makefile | 4 +-- rule/parser_test.go | 12 ++++--- 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2144c5..9dfab87 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,10 +23,6 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Get dependencies, run test - run: | - go test ./... - - name: Build if: startsWith(github.ref, 'refs/tags/') env: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..4e10e0b --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,60 @@ +name: Test + +on: [push, pull_request] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v4 + with: + check-latest: true + go-version: '1.21' + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Cache go module + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Get dependencies, run test + run: | + go test ./... + + build-test: + name: Build Test + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v4 + with: + check-latest: true + go-version: '1.21' + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Cache go module + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Build + env: + NAME: clash + BINDIR: bin + run: make -j $(go run ./test/main.go) all diff --git a/Makefile b/Makefile index 104f6c9..f81155d 100644 --- a/Makefile +++ b/Makefile @@ -88,10 +88,10 @@ linux-mips64le: GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ linux-riscv64: - GOARCH=riscv64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + GOARCH=riscv64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ linux-loong64: - GOARCH=loong64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + GOARCH=loong64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ freebsd-386: GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ diff --git a/rule/parser_test.go b/rule/parser_test.go index f14ead0..bccd0a1 100644 --- a/rule/parser_test.go +++ b/rule/parser_test.go @@ -116,16 +116,18 @@ func TestParseRule(t *testing.T) { expectedRule: lo.Must(NewProcess("/opt/example/example", policy, false)), }, { - tp: C.RuleConfigIPSet, - payload: "example", - target: policy, - expectedRule: lo.Must(NewIPSet("example", policy, true)), + tp: C.RuleConfigIPSet, + payload: "example", + target: policy, + // unit test runs on Linux machine and NewIPSet(...) won't be available + expectedError: errors.New("operation not permitted"), }, { tp: C.RuleConfigIPSet, payload: "example", target: policy, params: []string{noResolve}, - expectedRule: lo.Must(NewIPSet("example", policy, false)), + // unit test runs on Linux machine and NewIPSet(...) won't be available + expectedError: errors.New("operation not permitted"), }, { tp: C.RuleConfigMatch,