Skip to content

Commit 02dec8e

Browse files
authored
ci: add coverage and codecov (version-fox#138)
* ci: add coverage and codecov * ci: fix testcases * ci: test all cases * ci: fix testcase on ubuntu * ci: add macos and windows * ci: show err * ci: update ci * ci: fix testcase * ci: cancel previous run * ci: skip case on windows * ci: update workflow
1 parent be89b48 commit 02dec8e

File tree

5 files changed

+35
-45
lines changed

5 files changed

+35
-45
lines changed

.github/workflows/ci.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ name: VersionFox CI
22

33
on: [push]
44

5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
7+
cancel-in-progress: true
8+
59
jobs:
610
build:
7-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
812
strategy:
913
matrix:
14+
os: [macos-latest, ubuntu-latest, windows-latest]
1015
go-version: [ '1.21.x' ]
1116

1217
steps:
@@ -15,16 +20,14 @@ jobs:
1520
uses: actions/setup-go@v4
1621
with:
1722
go-version: ${{ matrix.go-version }}
18-
- name: Display Go version
19-
run: go version
2023
- name: Install dependencies
2124
run: |
2225
go get .
23-
- name: Build with the Go CLI
26+
- name: Build
2427
run: |
2528
go build .
26-
- name: Test with the Go CLI
27-
# we cannot use `go test ./...` currently, because many test cases are failed
29+
- name: Test and coverage
2830
run: |
29-
go test ./internal
30-
go test ./internal/luai
31+
go test ./... -coverprofile=coverage.out -covermode=atomic
32+
- name: Upload coverage to Codecov
33+
uses: codecov/codecov-action@v3

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.DS_Store
22
.idea
3-
/docs/node_modules/
3+
/docs/node_modules/
4+
5+
6+
coverage.out

internal/module/file/file_test.go

+2-30
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
package html
1818

1919
import (
20-
lua "github.com/yuin/gopher-lua"
2120
"testing"
21+
22+
lua "github.com/yuin/gopher-lua"
2223
)
2324

2425
func TestRequire(t *testing.T) {
@@ -30,35 +31,6 @@ func TestRequire(t *testing.T) {
3031
evalLua(str, t)
3132
}
3233

33-
func TestFind(t *testing.T) {
34-
const str = `
35-
local file = require("file")
36-
file.symlink(src, dest)
37-
assert(div:text() == "hello world")
38-
`
39-
evalLua(str, t)
40-
}
41-
42-
func TestFirst(t *testing.T) {
43-
const str = `
44-
local html = require("html")
45-
local doc = html.parse("<html><body><div id='test'>123</div><div id='test'>456</div></body></html>")
46-
local div = doc:find("div")
47-
assert(div:first():text() == "123")
48-
`
49-
evalLua(str, t)
50-
}
51-
52-
func TestContinuousFind(t *testing.T) {
53-
const str = `
54-
local html = require("html")
55-
local doc = html.parse("<html><body><div id='test'>test</div><div id='t2'>456</div></body></html>")
56-
local div = doc:find("body"):find("#t2")
57-
print(div:text() == "456")
58-
`
59-
evalLua(str, t)
60-
}
61-
6234
func evalLua(str string, t *testing.T) {
6335
s := lua.NewState()
6436
defer s.Close()

internal/module/http/http_test.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,41 @@
1717
package http
1818

1919
import (
20+
"runtime"
21+
"testing"
22+
2023
"github.com/version-fox/vfox/internal/config"
2124
lua "github.com/yuin/gopher-lua"
22-
"testing"
2325
)
2426

2527
func TestWithConfig(t *testing.T) {
26-
const str = `
28+
if runtime.GOOS == "windows" {
29+
t.Skip("Skip on windows, the proxy won't error on windows.")
30+
}
31+
32+
const str = `
2733
local http = require("http")
2834
assert(type(http) == "table")
2935
assert(type(http.get) == "function")
3036
local resp, err = http.get({
3137
url = "http://ip.jsontest.com/"
3238
})
39+
print(err)
3340
assert(err == 'Get "http://ip.jsontest.com/": proxyconnect tcp: dial tcp 127.0.0.1:80: connect: connection refused')
3441
`
3542
s := lua.NewState()
3643
defer s.Close()
3744

3845
s.PreloadModule("http", NewModule(&config.Proxy{
3946
Enable: true,
40-
Url: "http://localhost",
47+
Url: "http://127.0.0.1",
4148
}))
4249
if err := s.DoString(str); err != nil {
4350
t.Error(err)
4451
}
4552
}
4653
func TestGetRequest(t *testing.T) {
47-
const str = `
54+
const str = `
4855
local http = require("http")
4956
assert(type(http) == "table")
5057
assert(type(http.get) == "function")
@@ -59,7 +66,7 @@ func TestGetRequest(t *testing.T) {
5966
}
6067

6168
func TestHeadRequest(t *testing.T) {
62-
const str = `
69+
const str = `
6370
local http = require("http")
6471
assert(type(http) == "table")
6572
assert(type(http.get) == "function")

internal/printer/select_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ package printer
1818

1919
import (
2020
"fmt"
21+
"os"
2122
"testing"
2223
)
2324

2425
func TestSelect_Show(t *testing.T) {
26+
if os.Getenv("CI") != "" {
27+
t.Skip("Skipping TestSelect_Show in CI environment because it requires user input")
28+
}
29+
2530
source := []*KV{
2631
{
2732
Key: "1",
@@ -46,7 +51,7 @@ func TestSelect_Show(t *testing.T) {
4651
}
4752
s := &PageKVSelect{
4853
index: 0,
49-
SourceFunc: func(page, size int) ([]*KV, error) {
54+
SourceFunc: func(page, size int, options []*KV) ([]*KV, error) {
5055
// 计算开始和结束索引
5156
start := page * size
5257
end := start + size

0 commit comments

Comments
 (0)