diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-02 11:46:42 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-02-02 11:46:42 -0500 |
commit | 365514174ef00dcf426b2b5704c3d7adebe926e1 (patch) | |
tree | 41f5544aed1b822ae4e476c9ede496ce740d5048 /api4 | |
parent | 60be5c902fe30c978d5b30f265509dc28c451407 (diff) | |
download | chat-365514174ef00dcf426b2b5704c3d7adebe926e1.tar.gz chat-365514174ef00dcf426b2b5704c3d7adebe926e1.tar.bz2 chat-365514174ef00dcf426b2b5704c3d7adebe926e1.zip |
Add tear down to APIv4 tests (#5250)
* Add tear down to APIv4 tests
* Defer tear downs
Diffstat (limited to 'api4')
-rw-r--r-- | api4/apitestlib.go | 28 | ||||
-rw-r--r-- | api4/team_test.go | 1 | ||||
-rw-r--r-- | api4/user_test.go | 6 |
3 files changed, 34 insertions, 1 deletions
diff --git a/api4/apitestlib.go b/api4/apitestlib.go index d5706bf2b..6229c8a08 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -60,6 +60,34 @@ func Setup() *TestHelper { return th } +func TearDown() { + options := map[string]bool{} + options[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true + if result := <-app.Srv.Store.User().Search("", "fakeuser", options); result.Err != nil { + l4g.Error("Error tearing down test users") + } else { + users := result.Data.([]*model.User) + + for _, u := range users { + if err := app.PermanentDeleteUser(u); err != nil { + l4g.Error(err.Error()) + } + } + } + + if result := <-app.Srv.Store.Team().SearchByName("faketeam"); result.Err != nil { + l4g.Error("Error tearing down test teams") + } else { + teams := result.Data.([]*model.Team) + + for _, t := range teams { + if err := app.PermanentDeleteTeam(t); err != nil { + l4g.Error(err.Error()) + } + } + } +} + func (me *TestHelper) InitBasic() *TestHelper { me.TeamAdminUser = me.CreateUser() me.LoginTeamAdmin() diff --git a/api4/team_test.go b/api4/team_test.go index ba7ad094e..90f237151 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -14,6 +14,7 @@ import ( func TestCreateTeam(t *testing.T) { th := Setup().InitBasic() + defer TearDown() Client := th.Client team := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN} diff --git a/api4/user_test.go b/api4/user_test.go index 713e0268b..501bb38e3 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -13,7 +13,8 @@ import ( ) func TestCreateUser(t *testing.T) { - th := Setup() + th := Setup().InitBasic() + defer TearDown() Client := th.Client user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.ROLE_SYSTEM_ADMIN.Id + " " + model.ROLE_SYSTEM_USER.Id} @@ -28,6 +29,7 @@ func TestCreateUser(t *testing.T) { } if ruser.Roles != model.ROLE_SYSTEM_USER.Id { + t.Log(ruser.Roles) t.Fatal("did not clear roles") } @@ -67,6 +69,7 @@ func TestCreateUser(t *testing.T) { func TestGetUser(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() Client := th.Client user := th.CreateUser() @@ -130,6 +133,7 @@ func TestGetUser(t *testing.T) { func TestUpdateUser(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() Client := th.Client user := th.CreateUser() |