Skip to content

Commit a19a9fe

Browse files
authored
Chore: added a new test CI to run unit test and build test for Pull Requests (#2883)
1 parent 218c3b4 commit a19a9fe

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ jobs:
2323
restore-keys: |
2424
${{ runner.os }}-go-
2525
26-
- name: Get dependencies, run test
27-
run: |
28-
go test ./...
29-
3026
- name: Build
3127
if: startsWith(github.ref, 'refs/tags/')
3228
env:

.github/workflows/test.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
name: Test
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Setup Go
11+
uses: actions/setup-go@v4
12+
with:
13+
check-latest: true
14+
go-version: '1.21'
15+
16+
- name: Check out code into the Go module directory
17+
uses: actions/checkout@v3
18+
19+
- name: Cache go module
20+
uses: actions/cache@v3
21+
with:
22+
path: |
23+
~/go/pkg/mod
24+
~/.cache/go-build
25+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
26+
restore-keys: |
27+
${{ runner.os }}-go-
28+
29+
- name: Get dependencies, run test
30+
run: |
31+
go test ./...
32+
33+
build-test:
34+
name: Build Test
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Setup Go
38+
uses: actions/setup-go@v4
39+
with:
40+
check-latest: true
41+
go-version: '1.21'
42+
43+
- name: Check out code into the Go module directory
44+
uses: actions/checkout@v3
45+
46+
- name: Cache go module
47+
uses: actions/cache@v3
48+
with:
49+
path: |
50+
~/go/pkg/mod
51+
~/.cache/go-build
52+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
53+
restore-keys: |
54+
${{ runner.os }}-go-
55+
56+
- name: Build
57+
env:
58+
NAME: clash
59+
BINDIR: bin
60+
run: make -j $(go run ./test/main.go) all

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ linux-mips64le:
8888
GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
8989

9090
linux-riscv64:
91-
GOARCH=riscv64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
91+
GOARCH=riscv64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
9292

9393
linux-loong64:
94-
GOARCH=loong64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
94+
GOARCH=loong64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
9595

9696
freebsd-386:
9797
GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

rule/parser_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ func TestParseRule(t *testing.T) {
116116
expectedRule: lo.Must(NewProcess("/opt/example/example", policy, false)),
117117
},
118118
{
119-
tp: C.RuleConfigIPSet,
120-
payload: "example",
121-
target: policy,
122-
expectedRule: lo.Must(NewIPSet("example", policy, true)),
119+
tp: C.RuleConfigIPSet,
120+
payload: "example",
121+
target: policy,
122+
// unit test runs on Linux machine and NewIPSet(...) won't be available
123+
expectedError: errors.New("operation not permitted"),
123124
},
124125
{
125126
tp: C.RuleConfigIPSet,
126127
payload: "example",
127128
target: policy, params: []string{noResolve},
128-
expectedRule: lo.Must(NewIPSet("example", policy, false)),
129+
// unit test runs on Linux machine and NewIPSet(...) won't be available
130+
expectedError: errors.New("operation not permitted"),
129131
},
130132
{
131133
tp: C.RuleConfigMatch,

0 commit comments

Comments
 (0)