From 026553e4f87bfc647a5c03129752e30fc523fa07 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 6 Dec 2016 10:49:34 -0500 Subject: Improving command line interface (#4689) --- api/cli_test.go | 65 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'api/cli_test.go') diff --git a/api/cli_test.go b/api/cli_test.go index 4613988f3..ed8f764a3 100644 --- a/api/cli_test.go +++ b/api/cli_test.go @@ -17,7 +17,7 @@ func TestCliVersion(t *testing.T) { return } - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -version`) + cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go version`) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -33,10 +33,10 @@ func TestCliCreateTeam(t *testing.T) { th := Setup().InitSystemAdmin() id := model.NewId() - email := "success+" + id + "@simulator.amazonses.com" name := "name" + id + displayName := "Name " + id - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -create_team -team_name="`+name+`" -email="`+email+`"`) + cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go team create --name "`+name+`" --display_name "`+displayName+`"`) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -61,13 +61,20 @@ func TestCliCreateUserWithTeam(t *testing.T) { email := "success+" + id + "@simulator.amazonses.com" username := "name" + id - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -create_user -team_name="`+th.SystemAdminTeam.Name+`" -email="`+email+`" -password="mypassword1" -username="`+username+`"`) + cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go user create --email "`+email+`" --password "mypassword1" --username "`+username+`"`) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) t.Fatal(err) } + cmd2 := exec.Command("bash", "-c", `go run ../cmd/platform/*.go team add `+th.SystemAdminTeam.Id+" "+email) + output2, err2 := cmd2.CombinedOutput() + if err2 != nil { + t.Log(string(output2)) + t.Fatal(err2) + } + profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) found := false @@ -94,7 +101,7 @@ func TestCliCreateUserWithoutTeam(t *testing.T) { email := "success+" + id + "@simulator.amazonses.com" username := "name" + id - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -create_user -email="`+email+`" -password="mypassword1" -username="`+username+`"`) + cmd := exec.Command("bash", "-c", `go run ../cmd/platform/*.go user create --email "`+email+`" --password "mypassword1" --username "`+username+`"`) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -118,7 +125,7 @@ func TestCliAssignRole(t *testing.T) { th := Setup().InitBasic() - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -assign_role -email="`+th.BasicUser.Email+`" -role="system_user system_admin"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go roles system_admin "+th.BasicUser.Email) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -129,7 +136,7 @@ func TestCliAssignRole(t *testing.T) { t.Fatal() } else { user := result.Data.(*model.User) - if user.Roles != "system_user system_admin" { + if user.Roles != "system_admin system_user" { t.Fatal() } } @@ -145,7 +152,7 @@ func TestCliJoinChannel(t *testing.T) { // These test cannot run since this feature requires an enteprise license - // cmd := exec.Command("bash", "-c", `go run ../mattermost.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + // cmd := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) // output, err := cmd.CombinedOutput() // if err != nil { // t.Log(string(output)) @@ -153,7 +160,7 @@ func TestCliJoinChannel(t *testing.T) { // } // // Joining twice should succeed - // cmd1 := exec.Command("bash", "-c", `go run ../mattermost.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + // cmd1 := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) // output1, err1 := cmd1.CombinedOutput() // if err1 != nil { // t.Log(string(output1)) @@ -161,7 +168,7 @@ func TestCliJoinChannel(t *testing.T) { // } // should fail because channel does not exist - cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`asdf" -email="`+th.BasicUser2.Email+`"`) + cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel add "+th.BasicTeam.Name+":"+channel.Name+"asdf "+th.BasicUser2.Email) output2, err2 := cmd2.CombinedOutput() if err2 == nil { t.Log(string(output2)) @@ -169,7 +176,7 @@ func TestCliJoinChannel(t *testing.T) { } // should fail because channel does not have license - cmd3 := exec.Command("bash", "-c", `go run ../mattermost.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel add "+th.BasicTeam.Name+":"+channel.Name+" "+th.BasicUser2.Email) output3, err3 := cmd3.CombinedOutput() if err3 == nil { t.Log(string(output3)) @@ -187,14 +194,14 @@ func TestCliRemoveChannel(t *testing.T) { // These test cannot run since this feature requires an enteprise license - // cmd := exec.Command("bash", "-c", `go run ../mattermost.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + // cmd := exec.Command("bash", "-c", `go run ../*.go -join_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) // output, err := cmd.CombinedOutput() // if err != nil { // t.Log(string(output)) // t.Fatal(err) // } - // cmd0 := exec.Command("bash", "-c", `go run ../mattermost.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + // cmd0 := exec.Command("bash", "-c", `go run ../*.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) // output0, err0 := cmd0.CombinedOutput() // if err0 != nil { // t.Log(string(output0)) @@ -202,7 +209,7 @@ func TestCliRemoveChannel(t *testing.T) { // } // // Leaving twice should succeed - // cmd1 := exec.Command("bash", "-c", `go run ../mattermost.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + // cmd1 := exec.Command("bash", "-c", `go run ../*.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) // output1, err1 := cmd1.CombinedOutput() // if err1 != nil { // t.Log(string(output1)) @@ -210,7 +217,7 @@ func TestCliRemoveChannel(t *testing.T) { // } // cannot leave town-square - cmd1a := exec.Command("bash", "-c", `go run ../mattermost.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="town-square" -email="`+th.BasicUser2.Email+`"`) + cmd1a := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":town-square "+th.BasicUser2.Email) output1a, err1a := cmd1a.CombinedOutput() if err1a == nil { t.Log(string(output1a)) @@ -218,7 +225,7 @@ func TestCliRemoveChannel(t *testing.T) { } // should fail because channel does not exist - cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`asdf" -email="`+th.BasicUser2.Email+`"`) + cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":doesnotexist "+th.BasicUser2.Email) output2, err2 := cmd2.CombinedOutput() if err2 == nil { t.Log(string(output2)) @@ -226,7 +233,7 @@ func TestCliRemoveChannel(t *testing.T) { } // should fail because channel does not have license - cmd3 := exec.Command("bash", "-c", `go run ../mattermost.go -leave_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`" -email="`+th.BasicUser2.Email+`"`) + cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel remove "+th.BasicTeam.Name+":"+channel.Name+" "+th.BasicUser2.Email) output3, err3 := cmd3.CombinedOutput() if err3 == nil { t.Log(string(output3)) @@ -245,7 +252,7 @@ func TestCliListChannels(t *testing.T) { // These test cannot run since this feature requires an enteprise license - // cmd := exec.Command("bash", "-c", `go run ../mattermost.go -list_channels -team_name="`+th.BasicTeam.Name+`"`) + // cmd := exec.Command("bash", "-c", `go run ../*.go -list_channels -team_name="`+th.BasicTeam.Name+`"`) // output, err := cmd.CombinedOutput() // if err != nil { // t.Log(string(output)) @@ -261,7 +268,7 @@ func TestCliListChannels(t *testing.T) { // } // should fail because channel does not have license - cmd3 := exec.Command("bash", "-c", `go run ../mattermost.go -list_channels -team_name="`+th.BasicTeam.Name+``) + cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel list "+th.BasicTeam.Name) output3, err3 := cmd3.CombinedOutput() if err3 == nil { t.Log(string(output3)) @@ -280,7 +287,7 @@ func TestCliRestoreChannel(t *testing.T) { // These test cannot run since this feature requires an enteprise license - // cmd := exec.Command("bash", "-c", `go run ../mattermost.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`) + // cmd := exec.Command("bash", "-c", `go run ../*.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`) // output, err := cmd.CombinedOutput() // if err != nil { // t.Log(string(output)) @@ -288,7 +295,7 @@ func TestCliRestoreChannel(t *testing.T) { // } // // restoring twice should succeed - // cmd1 := exec.Command("bash", "-c", `go run ../mattermost.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`) + // cmd1 := exec.Command("bash", "-c", `go run ../*.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`) // output1, err1 := cmd1.CombinedOutput() // if err1 != nil { // t.Log(string(output1)) @@ -296,7 +303,7 @@ func TestCliRestoreChannel(t *testing.T) { // } // should fail because channel does not have license - cmd3 := exec.Command("bash", "-c", `go run ../mattermost.go -restore_channel -team_name="`+th.BasicTeam.Name+`" -channel_name="`+channel.Name+`"`) + cmd3 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel restore "+th.BasicTeam.Name+":"+channel.Name) output3, err3 := cmd3.CombinedOutput() if err3 == nil { t.Log(string(output3)) @@ -311,7 +318,7 @@ func TestCliJoinTeam(t *testing.T) { th := Setup().InitSystemAdmin().InitBasic() - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -join_team -team_name="`+th.SystemAdminTeam.Name+`" -email="`+th.BasicUser.Email+`"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go team add "+th.SystemAdminTeam.Name+" "+th.BasicUser.Email) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -341,7 +348,7 @@ func TestCliLeaveTeam(t *testing.T) { th := Setup().InitBasic() - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -leave_team -team_name="`+th.BasicTeam.Name+`" -email="`+th.BasicUser.Email+`"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go team remove "+th.BasicTeam.Name+" "+th.BasicUser.Email) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -378,7 +385,7 @@ func TestCliResetPassword(t *testing.T) { th := Setup().InitBasic() - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -reset_password -email="`+th.BasicUser.Email+`" -password="password2"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user password "+th.BasicUser.Email+" password2") output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -401,7 +408,7 @@ func TestCliCreateChannel(t *testing.T) { name := "name" + id // should fail because channel does not have license - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -create_channel -email="`+th.BasicUser.Email+`" -team_name="`+th.BasicTeam.Name+`" -channel_type="O" -channel_name="`+name+`"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel create --display_name "+name+" --team "+th.BasicTeam.Name+" --name "+name) output, err := cmd.CombinedOutput() if err == nil { t.Log(string(output)) @@ -410,7 +417,7 @@ func TestCliCreateChannel(t *testing.T) { // should fail because channel does not have license name = name + "-private" - cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -create_channel -email="`+th.BasicUser.Email+`" -team_name="`+th.BasicTeam.Name+`" -channel_type="P" -channel_name="`+name+`"`) + cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go channel create --display_name="+name+" --team "+th.BasicTeam.Name+" --private --name "+name) output2, err2 := cmd2.CombinedOutput() if err2 == nil { t.Log(string(output2)) @@ -426,7 +433,7 @@ func TestCliMakeUserActiveAndInactive(t *testing.T) { th := Setup().InitBasic() // first inactivate the user - cmd := exec.Command("bash", "-c", `go run ../mattermost.go -activate_user -inactive -email="`+th.BasicUser.Email+`"`) + cmd := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user deactivate "+th.BasicUser.Email) output, err := cmd.CombinedOutput() if err != nil { t.Log(string(output)) @@ -434,7 +441,7 @@ func TestCliMakeUserActiveAndInactive(t *testing.T) { } // activate the inactive user - cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -activate_user -email="`+th.BasicUser.Email+`"`) + cmd2 := exec.Command("bash", "-c", "go run ../cmd/platform/*.go user activate "+th.BasicUser.Email) output2, err2 := cmd2.CombinedOutput() if err2 != nil { t.Log(string(output2)) -- cgit v1.2.3-1-g7c22