Skip to content

Commit

Permalink
ci: add coverage and codecov (#138)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bytemain authored Mar 25, 2024
1 parent be89b48 commit 02dec8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 45 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ name: VersionFox CI

on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
go-version: [ '1.21.x' ]

steps:
Expand All @@ -15,16 +20,14 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version
- name: Install dependencies
run: |
go get .
- name: Build with the Go CLI
- name: Build
run: |
go build .
- name: Test with the Go CLI
# we cannot use `go test ./...` currently, because many test cases are failed
- name: Test and coverage
run: |
go test ./internal
go test ./internal/luai
go test ./... -coverprofile=coverage.out -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
.idea
/docs/node_modules/
/docs/node_modules/


coverage.out
32 changes: 2 additions & 30 deletions internal/module/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package html

import (
lua "github.com/yuin/gopher-lua"
"testing"

lua "github.com/yuin/gopher-lua"
)

func TestRequire(t *testing.T) {
Expand All @@ -30,35 +31,6 @@ func TestRequire(t *testing.T) {
evalLua(str, t)
}

func TestFind(t *testing.T) {
const str = `
local file = require("file")
file.symlink(src, dest)
assert(div:text() == "hello world")
`
evalLua(str, t)
}

func TestFirst(t *testing.T) {
const str = `
local html = require("html")
local doc = html.parse("<html><body><div id='test'>123</div><div id='test'>456</div></body></html>")
local div = doc:find("div")
assert(div:first():text() == "123")
`
evalLua(str, t)
}

func TestContinuousFind(t *testing.T) {
const str = `
local html = require("html")
local doc = html.parse("<html><body><div id='test'>test</div><div id='t2'>456</div></body></html>")
local div = doc:find("body"):find("#t2")
print(div:text() == "456")
`
evalLua(str, t)
}

func evalLua(str string, t *testing.T) {
s := lua.NewState()
defer s.Close()
Expand Down
17 changes: 12 additions & 5 deletions internal/module/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,41 @@
package http

import (
"runtime"
"testing"

"github.com/version-fox/vfox/internal/config"
lua "github.com/yuin/gopher-lua"
"testing"
)

func TestWithConfig(t *testing.T) {
const str = `
if runtime.GOOS == "windows" {
t.Skip("Skip on windows, the proxy won't error on windows.")
}

const str = `
local http = require("http")
assert(type(http) == "table")
assert(type(http.get) == "function")
local resp, err = http.get({
url = "http://ip.jsontest.com/"
})
print(err)
assert(err == 'Get "http://ip.jsontest.com/": proxyconnect tcp: dial tcp 127.0.0.1:80: connect: connection refused')
`
s := lua.NewState()
defer s.Close()

s.PreloadModule("http", NewModule(&config.Proxy{
Enable: true,
Url: "http://localhost",
Url: "http://127.0.0.1",
}))
if err := s.DoString(str); err != nil {
t.Error(err)
}
}
func TestGetRequest(t *testing.T) {
const str = `
const str = `
local http = require("http")
assert(type(http) == "table")
assert(type(http.get) == "function")
Expand All @@ -59,7 +66,7 @@ func TestGetRequest(t *testing.T) {
}

func TestHeadRequest(t *testing.T) {
const str = `
const str = `
local http = require("http")
assert(type(http) == "table")
assert(type(http.get) == "function")
Expand Down
7 changes: 6 additions & 1 deletion internal/printer/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ package printer

import (
"fmt"
"os"
"testing"
)

func TestSelect_Show(t *testing.T) {
if os.Getenv("CI") != "" {
t.Skip("Skipping TestSelect_Show in CI environment because it requires user input")
}

source := []*KV{
{
Key: "1",
Expand All @@ -46,7 +51,7 @@ func TestSelect_Show(t *testing.T) {
}
s := &PageKVSelect{
index: 0,
SourceFunc: func(page, size int) ([]*KV, error) {
SourceFunc: func(page, size int, options []*KV) ([]*KV, error) {
// 计算开始和结束索引
start := page * size
end := start + size
Expand Down

0 comments on commit 02dec8e

Please sign in to comment.