Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testcmd option: specify all or testname #33

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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