Skip to content

Commit 958b966

Browse files
committed
feat: support to print a sample YAML
1 parent 5ebb0e9 commit 958b966

File tree

10 files changed

+60
-28
lines changed

10 files changed

+60
-28
lines changed

cmd/init.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ type initOption struct {
1111
waitResource string
1212
}
1313

14-
// CreateInitCommand returns the init command
15-
func CreateInitCommand() (cmd *cobra.Command) {
14+
// createInitCommand returns the init command
15+
func createInitCommand() (cmd *cobra.Command) {
1616
opt := &initOption{}
1717
cmd = &cobra.Command{
18-
Use: "init",
19-
Long: "Support to init Kubernetes cluster with kustomization, and wait it with command: kubectl wait",
20-
RunE: opt.runE,
18+
Use: "init",
19+
Long: "Support to init Kubernetes cluster with kustomization, and wait it with command: kubectl wait",
20+
Hidden: true,
21+
RunE: opt.runE,
2122
}
2223

2324
flags := cmd.Flags()

cmd/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
// NewRootCmd creates the root command
6+
func NewRootCmd() (c *cobra.Command) {
7+
c = &cobra.Command{
8+
Use: "atest",
9+
Short: "API testing tool",
10+
}
11+
c.AddCommand(createInitCommand(),
12+
createRunCommand(), createSampleCmd())
13+
return
14+
}

cmd/root_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func Test_setRelativeDir(t *testing.T) {
4040
}
4141

4242
func TestCreateRunCommand(t *testing.T) {
43-
cmd := CreateRunCommand()
43+
cmd := createRunCommand()
4444
assert.Equal(t, "run", cmd.Use)
4545

46-
init := CreateInitCommand()
46+
init := createInitCommand()
4747
assert.Equal(t, "init", init.Use)
4848
}

cmd/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func newDiskCardRunOption() *runOption {
4848
}
4949
}
5050

51-
// CreateRunCommand returns the run command
52-
func CreateRunCommand() (cmd *cobra.Command) {
51+
// createRunCommand returns the run command
52+
func createRunCommand() (cmd *cobra.Command) {
5353
opt := newDefaultRunOption()
5454
cmd = &cobra.Command{
5555
Use: "run",

cmd/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestRunCommand(t *testing.T) {
9292
tt.prepare()
9393

9494
root := &cobra.Command{Use: "root"}
95-
root.AddCommand(CreateRunCommand())
95+
root.AddCommand(createRunCommand())
9696

9797
root.SetArgs(append([]string{"run"}, tt.args...))
9898

cmd/sample.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import (
4+
"github.com/linuxsuren/api-testing/sample"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func createSampleCmd() (c *cobra.Command) {
9+
c = &cobra.Command{
10+
Use: "sample",
11+
Short: "Generate a sample test case YAML file",
12+
RunE: func(cmd *cobra.Command, args []string) (err error) {
13+
cmd.Println(sample.TestSuiteGitLab)
14+
return
15+
},
16+
}
17+
return
18+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ require (
88
github.com/antonmedv/expr v1.12.1
99
github.com/h2non/gock v1.2.0
1010
github.com/linuxsuren/unstructured v0.0.1
11-
github.com/spf13/cobra v1.4.0
11+
github.com/spf13/cobra v1.6.1
1212
github.com/stretchr/testify v1.8.2
13+
golang.org/x/sync v0.1.0
1314
gopkg.in/yaml.v2 v2.4.0
1415
)
1516

@@ -21,7 +22,7 @@ require (
2122
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
2223
github.com/huandu/xstrings v1.3.3 // indirect
2324
github.com/imdario/mergo v0.3.11 // indirect
24-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
25+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
2526
github.com/mitchellh/copystructure v1.0.0 // indirect
2627
github.com/mitchellh/reflectwalk v1.0.0 // indirect
2728
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -30,6 +31,5 @@ require (
3031
github.com/spf13/cast v1.3.1 // indirect
3132
github.com/spf13/pflag v1.0.5 // indirect
3233
golang.org/x/crypto v0.3.0 // indirect
33-
golang.org/x/sync v0.1.0 // indirect
3434
gopkg.in/yaml.v3 v3.0.1 // indirect
3535
)

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg
88
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
99
github.com/antonmedv/expr v1.12.1 h1:GTGrGN1kxxb+le0uQKaFRK8By4cvq1sleUCGE/U6hHg=
1010
github.com/antonmedv/expr v1.12.1/go.mod h1:FPC8iWArxls7axbVLsW+kpg1mz29A1b2M6jt+hZfDkU=
11-
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
11+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1212
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1313
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=
@@ -22,8 +22,8 @@ github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4
2222
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
2323
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
2424
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
25-
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
26-
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
25+
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
26+
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2727
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
2828
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2929
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -46,8 +46,8 @@ github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXY
4646
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
4747
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
4848
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
49-
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
50-
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
49+
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
50+
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
5151
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
5252
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
5353
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

main.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@ package main
33
import (
44
"os"
55

6-
c "github.com/linuxsuren/api-testing/cmd"
7-
"github.com/spf13/cobra"
6+
"github.com/linuxsuren/api-testing/cmd"
87
)
98

109
func main() {
11-
cmd := &cobra.Command{
12-
Use: "atest",
13-
Short: "API testing tool",
14-
}
15-
cmd.AddCommand(c.CreateInitCommand(), c.CreateRunCommand())
16-
17-
// run command
18-
if err := cmd.Execute(); err != nil {
10+
c := cmd.NewRootCmd()
11+
if err := c.Execute(); err != nil {
1912
os.Exit(1)
2013
}
2114
}

sample/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package sample
2+
3+
import _ "embed"
4+
5+
//go:embed testsuite-gitlab.yaml
6+
var TestSuiteGitLab string

0 commit comments

Comments
 (0)