Skip to content

Commit

Permalink
add testcmd option: specify all or testname
Browse files Browse the repository at this point in the history
  • Loading branch information
ak1ra24 committed Feb 5, 2020
1 parent 631d89e commit 81b1859
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
21 changes: 20 additions & 1 deletion command_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,26 @@ func CmdTest(c *cli.Context) error {
return err
}

tnTestCmds := shell.TnTestCmdExec(tnconfig.Test)
testName := c.Args().Get(0)

var tnTestCmds []string

if testName == "all" || testName == "" {
for _, test := range tnconfig.Test {
tnTestCmds = test.TnTestCmdExec()
}
} else {
for _, test := range tnconfig.Test {
if testName == test.Name {
tnTestCmds = test.TnTestCmdExec()
}
}
}

if len(tnTestCmds) == 0 {
return fmt.Errorf("not found test name\n")
}

fmt.Fprintln(os.Stdout, strings.Join(tnTestCmds, "\n"))

return nil
Expand Down
9 changes: 3 additions & 6 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,11 @@ func Pull(nodes []Node) []string {
}

// TnTestCmdExec Execute test cmds
func TnTestCmdExec(tests []Test) []string {
func (t *Test) TnTestCmdExec() []string {
var tnTestCmds []string
for _, test := range tests {

for _, testCmd := range test.Cmds {
tnTestCmds = append(tnTestCmds, testCmd.Cmd)
}

for _, testCmd := range t.Cmds {
tnTestCmds = append(tnTestCmds, testCmd.Cmd)
}

return tnTestCmds
Expand Down
51 changes: 24 additions & 27 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,43 +387,36 @@ func TestPull(t *testing.T) {
}

func TestTnTestCmdExec(t *testing.T) {
type args struct {
tests []Test
type fields struct {
Name string
Cmds []Cmd
}
tests := []struct {
name string
args args
want []string
name string
fields fields
want []string
}{
{
name: "test name not set",
args: args{
tests: []Test{
Test{
Cmds: []Cmd{
Cmd{
Cmd: "echo slankdev",
},
},
fields: fields{
Cmds: []Cmd{
Cmd{
Cmd: "echo slankdev",
},
},
},
want: []string{"echo slankdev"},
},
{
name: "test name set",
args: args{
tests: []Test{
Test{
Name: "p2p",
Cmds: []Cmd{
Cmd{
Cmd: "docker exec R1 echo hello",
},
Cmd{
Cmd: "docker exec R2 echo world",
},
},
fields: fields{
Name: "p2p",
Cmds: []Cmd{
Cmd{
Cmd: "docker exec R1 echo hello",
},
Cmd{
Cmd: "docker exec R2 echo world",
},
},
},
Expand All @@ -432,8 +425,12 @@ func TestTnTestCmdExec(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := TnTestCmdExec(tt.args.tests); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TnTestCmdExec() = %v, want %v", got, tt.want)
tr := &Test{
Name: tt.fields.Name,
Cmds: tt.fields.Cmds,
}
if got := tr.TnTestCmdExec(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Test.TnTestCmdExec() = %v, want %v", got, tt.want)
}
})
}
Expand Down

0 comments on commit 81b1859

Please sign in to comment.