Skip to content

Commit c2425ba

Browse files
committed
add unit tests
1 parent b3b18d8 commit c2425ba

File tree

17 files changed

+240
-56
lines changed

17 files changed

+240
-56
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Coverage Report
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
TestAndReport:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- name: Set up Go
12+
uses: actions/setup-go@v3
13+
with:
14+
go-version: 1.18.x
15+
- uses: actions/[email protected]
16+
- name: Test
17+
run: |
18+
go test ./... -coverprofile coverage.out
19+
- name: Report
20+
env:
21+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
22+
run: |
23+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.out --force-coverage-parser go

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build:
44

55
copy: build
66
cp bin/atest /usr/local/bin/
7+
test:
8+
go test ./...

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/3f16717cd6f841118006f12c346e9341)](https://www.codacy.com/gh/LinuxSuRen/api-testing/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=LinuxSuRen/api-testing&amp;utm_campaign=Badge_Grade)
2+
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/5022a74d146f487581821fd1c3435437)](https://www.codacy.com/gh/LinuxSuRen/api-testing/dashboard?utm_source=github.com&utm_medium=referral&utm_content=LinuxSuRen/api-testing&utm_campaign=Badge_Coverage)
3+
![GitHub All Releases](https://img.shields.io/github/downloads/linuxsuren/api-testing/total)
4+
15
This is a API testing tool.
26

37
## Feature

cmd/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type initOption struct {
1111
waitResource string
1212
}
1313

14+
// CreateInitCommand returns the init command
1415
func CreateInitCommand() (cmd *cobra.Command) {
1516
opt := &initOption{}
1617
cmd = &cobra.Command{

cmd/root_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ func Test_setRelativeDir(t *testing.T) {
3838
})
3939
}
4040
}
41+
42+
func TestCreateRunCommand(t *testing.T) {
43+
cmd := CreateRunCommand()
44+
assert.Equal(t, "run", cmd.Use)
45+
46+
init := CreateInitCommand()
47+
assert.Equal(t, "init", init.Use)
48+
}

cmd/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type runOption struct {
1313
pattern string
1414
}
1515

16+
// CreateRunCommand returns the run command
1617
func CreateRunCommand() (cmd *cobra.Command) {
1718
opt := &runOption{}
1819
cmd = &cobra.Command{

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ require (
1616
github.com/antonmedv/expr v1.12.1 // indirect
1717
github.com/davecgh/go-spew v1.1.1 // indirect
1818
github.com/google/uuid v1.1.1 // indirect
19+
github.com/h2non/gock v1.2.0 // indirect
20+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
1921
github.com/huandu/xstrings v1.3.3 // indirect
2022
github.com/imdario/mergo v0.3.11 // indirect
2123
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1414
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1515
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
1616
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
17+
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
18+
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
19+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
20+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
1721
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
1822
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
1923
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
@@ -31,6 +35,7 @@ github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMK
3135
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
3236
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
3337
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
38+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
3439
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3540
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3641
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

pkg/runner/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package runner responsible for excute the test case
2+
package runner

pkg/runner/simple.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
unstructured "github.com/linuxsuren/unstructured/pkg"
2020
)
2121

22+
// RunTestCase runs the test case
2223
func RunTestCase(testcase *testing.TestCase, ctx interface{}) (output interface{}, err error) {
2324
fmt.Printf("start to run: '%s'\n", testcase.Name)
2425
if err = doPrepare(testcase); err != nil {
@@ -140,7 +141,7 @@ func RunTestCase(testcase *testing.TestCase, ctx interface{}) (output interface{
140141
}
141142

142143
if !result.(bool) {
143-
err = fmt.Errorf("faild to verify")
144+
err = fmt.Errorf("faild to verify: %s", verify)
144145
break
145146
}
146147
}

0 commit comments

Comments
 (0)