From 865f9f83a7cf2f9eb1fe2735b6bd498f56486f50 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 13 Nov 2017 13:59:51 -0600 Subject: Improve test coverage reporting / accuracy (#7819) * improve test coverage reporting / accuracy * handle absolute coverpaths * move tests into multiple files * rename codecov.yml (https://github.com/codecov/support/issues/426) --- .codecov.yml | 8 -- Makefile | 8 +- app/app_test.go | 1 + app/web_hub.go | 4 +- app/web_hub_test.go | 60 +++++++++ cmd/platform/channel_test.go | 89 +++++++++++++ cmd/platform/cli_test.go | 287 ------------------------------------------ cmd/platform/platform_test.go | 53 ++++++++ cmd/platform/roles_test.go | 27 ++++ cmd/platform/team_test.go | 79 ++++++++++++ cmd/platform/user_test.go | 81 ++++++++++++ cmd/platform/version_test.go | 12 ++ codecov.yml | 8 ++ 13 files changed, 416 insertions(+), 301 deletions(-) delete mode 100644 .codecov.yml create mode 100644 app/web_hub_test.go create mode 100644 cmd/platform/channel_test.go delete mode 100644 cmd/platform/cli_test.go create mode 100644 cmd/platform/platform_test.go create mode 100644 cmd/platform/roles_test.go create mode 100644 cmd/platform/team_test.go create mode 100644 cmd/platform/user_test.go create mode 100644 cmd/platform/version_test.go create mode 100644 codecov.yml diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 29fa07a58..000000000 --- a/.codecov.yml +++ /dev/null @@ -1,8 +0,0 @@ -coverage: - status: - project: - default: - threshold: 1% - patch: off -ignore: - - store/storetest diff --git a/Makefile b/Makefile index 8da00f0c3..755c3fbb9 100644 --- a/Makefile +++ b/Makefile @@ -318,18 +318,18 @@ do-cover-file: test-te: do-cover-file @echo Testing TE @echo "Packages to test: "$(TE_PACKAGES) - find . -name 'cprofile.out' -exec sh -c 'rm "{}"' \; + find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \; $(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGS) -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(TE_PACKAGES) - find . -name 'cprofile.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \; + find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \; test-ee: do-cover-file @echo Testing EE ifeq ($(BUILD_ENTERPRISE_READY),true) @echo "Packages to test: "$(EE_PACKAGES) - find . -name 'cprofile.out' -exec sh -c 'rm "{}"' \; + find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \; $(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGSEE) -p 1 -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(EE_PACKAGES) - find . -name 'cprofile.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \; + find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \; rm -f config/*.crt rm -f config/*.key endif diff --git a/app/app_test.go b/app/app_test.go index 17189956d..2058ddd79 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -48,6 +48,7 @@ func TestMain(m *testing.M) { func TestAppRace(t *testing.T) { for i := 0; i < 10; i++ { a := New() + a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" }) a.StartServer() a.Shutdown() } diff --git a/app/web_hub.go b/app/web_hub.go index c8c650246..eeae13e09 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -50,7 +50,7 @@ func (a *App) NewWebHub() *Hub { connections: make([]*WebConn, 0, model.SESSION_CACHE_SIZE), broadcast: make(chan *model.WebSocketEvent, BROADCAST_QUEUE_SIZE), stop: make(chan struct{}), - didStop: make(chan struct{}, 1), + didStop: make(chan struct{}), invalidateUser: make(chan string), ExplicitStop: false, } @@ -446,7 +446,7 @@ func (h *Hub) Start() { h.connections = make([]*WebConn, 0, model.SESSION_CACHE_SIZE) h.ExplicitStop = true - h.didStop <- struct{}{} + close(h.didStop) return } diff --git a/app/web_hub_test.go b/app/web_hub_test.go new file mode 100644 index 000000000..62c2552de --- /dev/null +++ b/app/web_hub_test.go @@ -0,0 +1,60 @@ +package app + +import ( + "net" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gorilla/websocket" + goi18n "github.com/nicksnyder/go-i18n/i18n" + "github.com/stretchr/testify/require" + + "github.com/mattermost/mattermost-server/model" +) + +func dummyWebsocketHandler(t *testing.T) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { + upgrader := &websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, + } + conn, err := upgrader.Upgrade(w, req, nil) + for err == nil { + _, _, err = conn.ReadMessage() + } + if _, ok := err.(*websocket.CloseError); !ok { + require.NoError(t, err) + } + } +} + +func registerDummyWebConn(t *testing.T, a *App, addr net.Addr, userId string) *WebConn { + session, appErr := a.CreateSession(&model.Session{ + UserId: userId, + }) + require.Nil(t, appErr) + + d := websocket.Dialer{} + c, _, err := d.Dial("ws://"+addr.String()+"/ws", nil) + require.NoError(t, err) + + wc := a.NewWebConn(c, *session, goi18n.IdentityTfunc(), "en") + a.HubRegister(wc) + go wc.Pump() + return wc +} + +func TestHubStopWithMultipleConnections(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + s := httptest.NewServer(http.HandlerFunc(dummyWebsocketHandler(t))) + defer s.Close() + + th.App.HubStart() + registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id) + registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id) + registerDummyWebConn(t, th.App, s.Listener.Addr(), th.BasicUser.Id) + th.App.HubStop() +} diff --git a/cmd/platform/channel_test.go b/cmd/platform/channel_test.go new file mode 100644 index 000000000..1e6915679 --- /dev/null +++ b/cmd/platform/channel_test.go @@ -0,0 +1,89 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "strings" + "testing" + + "github.com/mattermost/mattermost-server/api" + "github.com/mattermost/mattermost-server/model" + "github.com/stretchr/testify/require" +) + +func TestJoinChannel(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + channel := th.CreateChannel(th.BasicClient, th.BasicTeam) + + checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) + + // Joining twice should succeed + checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) + + // should fail because channel does not exist + require.Error(t, runCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email)) +} + +func TestRemoveChannel(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + channel := th.CreateChannel(th.BasicClient, th.BasicTeam) + + checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) + + // should fail because channel does not exist + require.Error(t, runCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email)) + + checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) + + // Leaving twice should succeed + checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) +} + +func TestListChannels(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + channel := th.CreateChannel(th.BasicClient, th.BasicTeam) + th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) + + output := checkCommand(t, "channel", "list", th.BasicTeam.Name) + + if !strings.Contains(string(output), "town-square") { + t.Fatal("should have channels") + } + + if !strings.Contains(string(output), channel.Name+" (archived)") { + t.Fatal("should have archived channel") + } +} + +func TestRestoreChannel(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + channel := th.CreateChannel(th.BasicClient, th.BasicTeam) + th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) + + checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) + + // restoring twice should succeed + checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) +} + +func TestCreateChannel(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + id := model.NewId() + name := "name" + id + + checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name) + + name = name + "-private" + checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name) +} diff --git a/cmd/platform/cli_test.go b/cmd/platform/cli_test.go deleted file mode 100644 index 7d6717660..000000000 --- a/cmd/platform/cli_test.go +++ /dev/null @@ -1,287 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package main - -import ( - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/mattermost/mattermost-server/api" - "github.com/mattermost/mattermost-server/model" -) - -var testExePath string - -func checkCommand(t *testing.T, args ...string) string { - output, err := exec.Command(testExePath, args...).CombinedOutput() - require.NoError(t, err, string(output)) - return string(output) -} - -func TestCliVersion(t *testing.T) { - checkCommand(t, "version") -} - -func TestCliCreateTeam(t *testing.T) { - th := api.Setup().InitSystemAdmin() - defer th.TearDown() - - id := model.NewId() - name := "name" + id - displayName := "Name " + id - - checkCommand(t, "team", "create", "--name", name, "--display_name", displayName) - - found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool) - - if !found { - t.Fatal("Failed to create Team") - } -} - -func TestCliCreateUserWithTeam(t *testing.T) { - th := api.Setup().InitSystemAdmin() - defer th.TearDown() - - id := model.NewId() - email := "success+" + id + "@simulator.amazonses.com" - username := "name" + id - - checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) - - checkCommand(t, "team", "add", th.SystemAdminTeam.Id, email) - - profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) - - found := false - - for _, user := range profiles { - if user.Email == email { - found = true - } - - } - - if !found { - t.Fatal("Failed to create User") - } -} - -func TestCliCreateUserWithoutTeam(t *testing.T) { - th := api.Setup() - defer th.TearDown() - - id := model.NewId() - email := "success+" + id + "@simulator.amazonses.com" - username := "name" + id - - checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) - - if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { - t.Fatal() - } else { - user := result.Data.(*model.User) - if user.Email != email { - t.Fatal() - } - } -} - -func TestCliAssignRole(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - checkCommand(t, "roles", "system_admin", th.BasicUser.Email) - - if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { - t.Fatal() - } else { - user := result.Data.(*model.User) - if user.Roles != "system_admin system_user" { - t.Fatal() - } - } -} - -func TestCliJoinChannel(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - channel := th.CreateChannel(th.BasicClient, th.BasicTeam) - - checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) - - // Joining twice should succeed - checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) - - // should fail because channel does not exist - require.Error(t, exec.Command(testExePath, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email).Run()) -} - -func TestCliRemoveChannel(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - channel := th.CreateChannel(th.BasicClient, th.BasicTeam) - - checkCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) - - // should fail because channel does not exist - require.Error(t, exec.Command(testExePath, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email).Run()) - - checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) - - // Leaving twice should succeed - checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email) -} - -func TestCliListChannels(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - channel := th.CreateChannel(th.BasicClient, th.BasicTeam) - th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) - - output := checkCommand(t, "channel", "list", th.BasicTeam.Name) - - if !strings.Contains(string(output), "town-square") { - t.Fatal("should have channels") - } - - if !strings.Contains(string(output), channel.Name+" (archived)") { - t.Fatal("should have archived channel") - } -} - -func TestCliRestoreChannel(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - channel := th.CreateChannel(th.BasicClient, th.BasicTeam) - th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id)) - - checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) - - // restoring twice should succeed - checkCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name) -} - -func TestCliJoinTeam(t *testing.T) { - th := api.Setup().InitSystemAdmin().InitBasic() - defer th.TearDown() - - checkCommand(t, "team", "add", th.SystemAdminTeam.Name, th.BasicUser.Email) - - profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) - - found := false - - for _, user := range profiles { - if user.Email == th.BasicUser.Email { - found = true - } - - } - - if !found { - t.Fatal("Failed to create User") - } -} - -func TestCliLeaveTeam(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - checkCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email) - - profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) - - found := false - - for _, user := range profiles { - if user.Email == th.BasicUser.Email { - found = true - } - - } - - if found { - t.Fatal("profile should not be on team") - } - - if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { - teamMembers := result.Data.([]*model.TeamMember) - if len(teamMembers) > 0 { - t.Fatal("Shouldn't be in team") - } - } -} - -func TestCliResetPassword(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - checkCommand(t, "user", "password", th.BasicUser.Email, "password2") - - th.BasicClient.Logout() - th.BasicUser.Password = "password2" - th.LoginBasic() -} - -func TestCliCreateChannel(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - id := model.NewId() - name := "name" + id - - checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name) - - name = name + "-private" - checkCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name) -} - -func TestCliMakeUserActiveAndInactive(t *testing.T) { - th := api.Setup().InitBasic() - defer th.TearDown() - - // first inactivate the user - checkCommand(t, "user", "deactivate", th.BasicUser.Email) - - // activate the inactive user - checkCommand(t, "user", "activate", th.BasicUser.Email) -} - -func TestMain(m *testing.M) { - dir, err := ioutil.TempDir("", "cli_test") - if err != nil { - panic(err) - } - defer os.RemoveAll(dir) - - testExePath = filepath.Join(dir, "cli") - files, err := filepath.Glob("./*.go") - if err != nil { - panic(err) - } - - cmd := exec.Command("go", append([]string{"build", "-o", testExePath}, files...)...) - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - if err := cmd.Run(); err != nil { - panic(err) - } - - status := 0 - defer func() { - os.Exit(status) - }() - status = m.Run() -} diff --git a/cmd/platform/platform_test.go b/cmd/platform/platform_test.go new file mode 100644 index 000000000..8a2839c7e --- /dev/null +++ b/cmd/platform/platform_test.go @@ -0,0 +1,53 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "flag" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +var coverprofileCounters map[string]int = make(map[string]int) + +func execArgs(t *testing.T, args []string) []string { + ret := []string{"-test.run", "ExecCommand"} + if coverprofile := flag.Lookup("test.coverprofile").Value.String(); coverprofile != "" { + dir := filepath.Dir(coverprofile) + base := filepath.Base(coverprofile) + baseParts := strings.SplitN(base, ".", 2) + coverprofileCounters[t.Name()] = coverprofileCounters[t.Name()] + 1 + baseParts[0] = fmt.Sprintf("%v-%v-%v", baseParts[0], t.Name(), coverprofileCounters[t.Name()]) + ret = append(ret, "-test.coverprofile", filepath.Join(dir, strings.Join(baseParts, "."))) + } + return append(append(ret, "--"), args...) +} + +func checkCommand(t *testing.T, args ...string) string { + path, err := os.Executable() + require.NoError(t, err) + output, err := exec.Command(path, execArgs(t, args)...).CombinedOutput() + require.NoError(t, err, string(output)) + return string(output) +} + +func runCommand(t *testing.T, args ...string) error { + path, err := os.Executable() + require.NoError(t, err) + return exec.Command(path, execArgs(t, args)...).Run() +} + +func TestExecCommand(t *testing.T) { + if filter := flag.Lookup("test.run").Value.String(); filter != "ExecCommand" { + t.Skip("use -run ExecCommand to execute a command via the test executable") + } + rootCmd.SetArgs(flag.Args()) + require.NoError(t, rootCmd.Execute()) +} diff --git a/cmd/platform/roles_test.go b/cmd/platform/roles_test.go new file mode 100644 index 000000000..1a5ae5173 --- /dev/null +++ b/cmd/platform/roles_test.go @@ -0,0 +1,27 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "testing" + + "github.com/mattermost/mattermost-server/api" + "github.com/mattermost/mattermost-server/model" +) + +func TestAssignRole(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + checkCommand(t, "roles", "system_admin", th.BasicUser.Email) + + if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { + t.Fatal() + } else { + user := result.Data.(*model.User) + if user.Roles != "system_admin system_user" { + t.Fatal() + } + } +} diff --git a/cmd/platform/team_test.go b/cmd/platform/team_test.go new file mode 100644 index 000000000..1e13d6cfa --- /dev/null +++ b/cmd/platform/team_test.go @@ -0,0 +1,79 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "testing" + + "github.com/mattermost/mattermost-server/api" + "github.com/mattermost/mattermost-server/model" +) + +func TestCreateTeam(t *testing.T) { + th := api.Setup().InitSystemAdmin() + defer th.TearDown() + + id := model.NewId() + name := "name" + id + displayName := "Name " + id + + checkCommand(t, "team", "create", "--name", name, "--display_name", displayName) + + found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool) + + if !found { + t.Fatal("Failed to create Team") + } +} + +func TestJoinTeam(t *testing.T) { + th := api.Setup().InitSystemAdmin().InitBasic() + defer th.TearDown() + + checkCommand(t, "team", "add", th.SystemAdminTeam.Name, th.BasicUser.Email) + + profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) + + found := false + + for _, user := range profiles { + if user.Email == th.BasicUser.Email { + found = true + } + + } + + if !found { + t.Fatal("Failed to create User") + } +} + +func TestLeaveTeam(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + checkCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email) + + profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) + + found := false + + for _, user := range profiles { + if user.Email == th.BasicUser.Email { + found = true + } + + } + + if found { + t.Fatal("profile should not be on team") + } + + if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { + teamMembers := result.Data.([]*model.TeamMember) + if len(teamMembers) > 0 { + t.Fatal("Shouldn't be in team") + } + } +} diff --git a/cmd/platform/user_test.go b/cmd/platform/user_test.go new file mode 100644 index 000000000..5383ad914 --- /dev/null +++ b/cmd/platform/user_test.go @@ -0,0 +1,81 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "testing" + + "github.com/mattermost/mattermost-server/api" + "github.com/mattermost/mattermost-server/model" +) + +func TestCreateUserWithTeam(t *testing.T) { + th := api.Setup().InitSystemAdmin() + defer th.TearDown() + + id := model.NewId() + email := "success+" + id + "@simulator.amazonses.com" + username := "name" + id + + checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) + + checkCommand(t, "team", "add", th.SystemAdminTeam.Id, email) + + profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User) + + found := false + + for _, user := range profiles { + if user.Email == email { + found = true + } + + } + + if !found { + t.Fatal("Failed to create User") + } +} + +func TestCreateUserWithoutTeam(t *testing.T) { + th := api.Setup() + defer th.TearDown() + + id := model.NewId() + email := "success+" + id + "@simulator.amazonses.com" + username := "name" + id + + checkCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) + + if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { + t.Fatal() + } else { + user := result.Data.(*model.User) + if user.Email != email { + t.Fatal() + } + } +} + +func TestResetPassword(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + checkCommand(t, "user", "password", th.BasicUser.Email, "password2") + + th.BasicClient.Logout() + th.BasicUser.Password = "password2" + th.LoginBasic() +} + +func TestMakeUserActiveAndInactive(t *testing.T) { + th := api.Setup().InitBasic() + defer th.TearDown() + + // first inactivate the user + checkCommand(t, "user", "deactivate", th.BasicUser.Email) + + // activate the inactive user + checkCommand(t, "user", "activate", th.BasicUser.Email) +} diff --git a/cmd/platform/version_test.go b/cmd/platform/version_test.go new file mode 100644 index 000000000..eea2549ee --- /dev/null +++ b/cmd/platform/version_test.go @@ -0,0 +1,12 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "testing" +) + +func TestVersion(t *testing.T) { + checkCommand(t, "version") +} diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..29fa07a58 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +coverage: + status: + project: + default: + threshold: 1% + patch: off +ignore: + - store/storetest -- cgit v1.2.3-1-g7c22