[MM-31079]: Change receiver name for (me *TestHelper) in api4/apitestlib.go to be more idiomatic (#16501)

Automatic Merge
Этот коммит содержится в:
Haardik Dharma
2020-12-12 09:45:17 +05:30
коммит произвёл GitHub
родитель 625185cb5b
Коммит 0b012ad468

Просмотреть файл

@@ -268,10 +268,10 @@ func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
return th return th
} }
func (me *TestHelper) ShutdownApp() { func (th *TestHelper) ShutdownApp() {
done := make(chan bool) done := make(chan bool)
go func() { go func() {
me.Server.Shutdown() th.Server.Shutdown()
close(done) close(done)
}() }()
@@ -284,14 +284,14 @@ func (me *TestHelper) ShutdownApp() {
} }
} }
func (me *TestHelper) TearDown() { func (th *TestHelper) TearDown() {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
if me.IncludeCacheLayer { if th.IncludeCacheLayer {
// Clean all the caches // Clean all the caches
me.App.Srv().InvalidateAllCaches() th.App.Srv().InvalidateAllCaches()
} }
me.ShutdownApp() th.ShutdownApp()
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
@@ -304,84 +304,84 @@ var userCache struct {
BasicUser2 *model.User BasicUser2 *model.User
} }
func (me *TestHelper) InitLogin() *TestHelper { func (th *TestHelper) InitLogin() *TestHelper {
me.waitForConnectivity() th.waitForConnectivity()
// create users once and cache them because password hashing is slow // create users once and cache them because password hashing is slow
initBasicOnce.Do(func() { initBasicOnce.Do(func() {
me.SystemAdminUser = me.CreateUser() th.SystemAdminUser = th.CreateUser()
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false) th.App.UpdateUserRoles(th.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
me.SystemAdminUser, _ = me.App.GetUser(me.SystemAdminUser.Id) th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id)
userCache.SystemAdminUser = me.SystemAdminUser.DeepCopy() userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy()
me.TeamAdminUser = me.CreateUser() th.TeamAdminUser = th.CreateUser()
me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false) th.App.UpdateUserRoles(th.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false)
me.TeamAdminUser, _ = me.App.GetUser(me.TeamAdminUser.Id) th.TeamAdminUser, _ = th.App.GetUser(th.TeamAdminUser.Id)
userCache.TeamAdminUser = me.TeamAdminUser.DeepCopy() userCache.TeamAdminUser = th.TeamAdminUser.DeepCopy()
me.BasicUser = me.CreateUser() th.BasicUser = th.CreateUser()
me.BasicUser, _ = me.App.GetUser(me.BasicUser.Id) th.BasicUser, _ = th.App.GetUser(th.BasicUser.Id)
userCache.BasicUser = me.BasicUser.DeepCopy() userCache.BasicUser = th.BasicUser.DeepCopy()
me.BasicUser2 = me.CreateUser() th.BasicUser2 = th.CreateUser()
me.BasicUser2, _ = me.App.GetUser(me.BasicUser2.Id) th.BasicUser2, _ = th.App.GetUser(th.BasicUser2.Id)
userCache.BasicUser2 = me.BasicUser2.DeepCopy() userCache.BasicUser2 = th.BasicUser2.DeepCopy()
}) })
// restore cached users // restore cached users
me.SystemAdminUser = userCache.SystemAdminUser.DeepCopy() th.SystemAdminUser = userCache.SystemAdminUser.DeepCopy()
me.TeamAdminUser = userCache.TeamAdminUser.DeepCopy() th.TeamAdminUser = userCache.TeamAdminUser.DeepCopy()
me.BasicUser = userCache.BasicUser.DeepCopy() th.BasicUser = userCache.BasicUser.DeepCopy()
me.BasicUser2 = userCache.BasicUser2.DeepCopy() th.BasicUser2 = userCache.BasicUser2.DeepCopy()
mainHelper.GetSQLStore().GetMaster().Insert(me.SystemAdminUser, me.TeamAdminUser, me.BasicUser, me.BasicUser2) mainHelper.GetSQLStore().GetMaster().Insert(th.SystemAdminUser, th.TeamAdminUser, th.BasicUser, th.BasicUser2)
// restore non hashed password for login // restore non hashed password for login
me.SystemAdminUser.Password = "Pa$$word11" th.SystemAdminUser.Password = "Pa$$word11"
me.TeamAdminUser.Password = "Pa$$word11" th.TeamAdminUser.Password = "Pa$$word11"
me.BasicUser.Password = "Pa$$word11" th.BasicUser.Password = "Pa$$word11"
me.BasicUser2.Password = "Pa$$word11" th.BasicUser2.Password = "Pa$$word11"
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
go func() { go func() {
me.LoginSystemAdmin() th.LoginSystemAdmin()
wg.Done() wg.Done()
}() }()
go func() { go func() {
me.LoginTeamAdmin() th.LoginTeamAdmin()
wg.Done() wg.Done()
}() }()
wg.Wait() wg.Wait()
return me return th
} }
func (me *TestHelper) InitBasic() *TestHelper { func (th *TestHelper) InitBasic() *TestHelper {
me.BasicTeam = me.CreateTeam() th.BasicTeam = th.CreateTeam()
me.BasicChannel = me.CreatePublicChannel() th.BasicChannel = th.CreatePublicChannel()
me.BasicPrivateChannel = me.CreatePrivateChannel() th.BasicPrivateChannel = th.CreatePrivateChannel()
me.BasicPrivateChannel2 = me.CreatePrivateChannel() th.BasicPrivateChannel2 = th.CreatePrivateChannel()
me.BasicDeletedChannel = me.CreatePublicChannel() th.BasicDeletedChannel = th.CreatePublicChannel()
me.BasicChannel2 = me.CreatePublicChannel() th.BasicChannel2 = th.CreatePublicChannel()
me.BasicPost = me.CreatePost() th.BasicPost = th.CreatePost()
me.LinkUserToTeam(me.BasicUser, me.BasicTeam) th.LinkUserToTeam(th.BasicUser, th.BasicTeam)
me.LinkUserToTeam(me.BasicUser2, me.BasicTeam) th.LinkUserToTeam(th.BasicUser2, th.BasicTeam)
me.App.AddUserToChannel(me.BasicUser, me.BasicChannel) th.App.AddUserToChannel(th.BasicUser, th.BasicChannel)
me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel) th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
me.App.AddUserToChannel(me.BasicUser, me.BasicChannel2) th.App.AddUserToChannel(th.BasicUser, th.BasicChannel2)
me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel2) th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel2)
me.App.AddUserToChannel(me.BasicUser, me.BasicPrivateChannel) th.App.AddUserToChannel(th.BasicUser, th.BasicPrivateChannel)
me.App.AddUserToChannel(me.BasicUser2, me.BasicPrivateChannel) th.App.AddUserToChannel(th.BasicUser2, th.BasicPrivateChannel)
me.App.AddUserToChannel(me.BasicUser, me.BasicDeletedChannel) th.App.AddUserToChannel(th.BasicUser, th.BasicDeletedChannel)
me.App.AddUserToChannel(me.BasicUser2, me.BasicDeletedChannel) th.App.AddUserToChannel(th.BasicUser2, th.BasicDeletedChannel)
me.App.UpdateUserRoles(me.BasicUser.Id, model.SYSTEM_USER_ROLE_ID, false) th.App.UpdateUserRoles(th.BasicUser.Id, model.SYSTEM_USER_ROLE_ID, false)
me.Client.DeleteChannel(me.BasicDeletedChannel.Id) th.Client.DeleteChannel(th.BasicDeletedChannel.Id)
me.LoginBasic() th.LoginBasic()
me.Group = me.CreateGroup() th.Group = th.CreateGroup()
return me return th
} }
func (me *TestHelper) waitForConnectivity() { func (th *TestHelper) waitForConnectivity() {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", me.App.Srv().ListenAddr.Port)) conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", th.App.Srv().ListenAddr.Port))
if err == nil { if err == nil {
conn.Close() conn.Close()
return return
@@ -391,12 +391,12 @@ func (me *TestHelper) waitForConnectivity() {
panic("unable to connect") panic("unable to connect")
} }
func (me *TestHelper) CreateClient() *model.Client4 { func (th *TestHelper) CreateClient() *model.Client4 {
return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", me.App.Srv().ListenAddr.Port)) return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port))
} }
// ToDo: maybe move this to NewAPIv4SocketClient and reuse it in mmctl // ToDo: maybe move this to NewAPIv4SocketClient and reuse it in mmctl
func (me *TestHelper) CreateLocalClient(socketPath string) *model.Client4 { func (th *TestHelper) CreateLocalClient(socketPath string) *model.Client4 {
httpClient := &http.Client{ httpClient := &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) { Dial: func(network, addr string) (net.Conn, error) {
@@ -411,23 +411,23 @@ func (me *TestHelper) CreateLocalClient(socketPath string) *model.Client4 {
} }
} }
func (me *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) { func (th *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) {
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.Client.AuthToken) return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.Client.AuthToken)
} }
func (me *TestHelper) CreateWebSocketSystemAdminClient() (*model.WebSocketClient, *model.AppError) { func (th *TestHelper) CreateWebSocketSystemAdminClient() (*model.WebSocketClient, *model.AppError) {
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.SystemAdminClient.AuthToken) return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.SystemAdminClient.AuthToken)
} }
func (me *TestHelper) CreateWebSocketClientWithClient(client *model.Client4) (*model.WebSocketClient, *model.AppError) { func (th *TestHelper) CreateWebSocketClientWithClient(client *model.Client4) (*model.WebSocketClient, *model.AppError) {
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), client.AuthToken) return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), client.AuthToken)
} }
func (me *TestHelper) CreateBotWithSystemAdminClient() *model.Bot { func (th *TestHelper) CreateBotWithSystemAdminClient() *model.Bot {
return me.CreateBotWithClient((me.SystemAdminClient)) return th.CreateBotWithClient((th.SystemAdminClient))
} }
func (me *TestHelper) CreateBotWithClient(client *model.Client4) *model.Bot { func (th *TestHelper) CreateBotWithClient(client *model.Client4) *model.Bot {
bot := &model.Bot{ bot := &model.Bot{
Username: GenerateTestUsername(), Username: GenerateTestUsername(),
DisplayName: "a bot", DisplayName: "a bot",
@@ -443,20 +443,20 @@ func (me *TestHelper) CreateBotWithClient(client *model.Client4) *model.Bot {
return rbot return rbot
} }
func (me *TestHelper) CreateUser() *model.User { func (th *TestHelper) CreateUser() *model.User {
return me.CreateUserWithClient(me.Client) return th.CreateUserWithClient(th.Client)
} }
func (me *TestHelper) CreateTeam() *model.Team { func (th *TestHelper) CreateTeam() *model.Team {
return me.CreateTeamWithClient(me.Client) return th.CreateTeamWithClient(th.Client)
} }
func (me *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team { func (th *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
id := model.NewId() id := model.NewId()
team := &model.Team{ team := &model.Team{
DisplayName: "dn_" + id, DisplayName: "dn_" + id,
Name: GenerateTestTeamName(), Name: GenerateTestTeamName(),
Email: me.GenerateTestEmail(), Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN, Type: model.TEAM_OPEN,
} }
@@ -469,11 +469,11 @@ func (me *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
return rteam return rteam
} }
func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User { func (th *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
id := model.NewId() id := model.NewId()
user := &model.User{ user := &model.User{
Email: me.GenerateTestEmail(), Email: th.GenerateTestEmail(),
Username: GenerateTestUsername(), Username: GenerateTestUsername(),
Nickname: "nn_" + id, Nickname: "nn_" + id,
FirstName: "f_" + id, FirstName: "f_" + id,
@@ -488,7 +488,7 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
} }
ruser.Password = "Pa$$word11" ruser.Password = "Pa$$word11"
_, err := me.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email) _, err := th.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
if err != nil { if err != nil {
return nil return nil
} }
@@ -496,19 +496,19 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
return ruser return ruser
} }
func (me *TestHelper) CreatePublicChannel() *model.Channel { func (th *TestHelper) CreatePublicChannel() *model.Channel {
return me.CreateChannelWithClient(me.Client, model.CHANNEL_OPEN) return th.CreateChannelWithClient(th.Client, model.CHANNEL_OPEN)
} }
func (me *TestHelper) CreatePrivateChannel() *model.Channel { func (th *TestHelper) CreatePrivateChannel() *model.Channel {
return me.CreateChannelWithClient(me.Client, model.CHANNEL_PRIVATE) return th.CreateChannelWithClient(th.Client, model.CHANNEL_PRIVATE)
} }
func (me *TestHelper) CreateChannelWithClient(client *model.Client4, channelType string) *model.Channel { func (th *TestHelper) CreateChannelWithClient(client *model.Client4, channelType string) *model.Channel {
return me.CreateChannelWithClientAndTeam(client, channelType, me.BasicTeam.Id) return th.CreateChannelWithClientAndTeam(client, channelType, th.BasicTeam.Id)
} }
func (me *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, channelType string, teamId string) *model.Channel { func (th *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, channelType string, teamId string) *model.Channel {
id := model.NewId() id := model.NewId()
channel := &model.Channel{ channel := &model.Channel{
@@ -527,19 +527,19 @@ func (me *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, chan
return rchannel return rchannel
} }
func (me *TestHelper) CreatePost() *model.Post { func (th *TestHelper) CreatePost() *model.Post {
return me.CreatePostWithClient(me.Client, me.BasicChannel) return th.CreatePostWithClient(th.Client, th.BasicChannel)
} }
func (me *TestHelper) CreatePinnedPost() *model.Post { func (th *TestHelper) CreatePinnedPost() *model.Post {
return me.CreatePinnedPostWithClient(me.Client, me.BasicChannel) return th.CreatePinnedPostWithClient(th.Client, th.BasicChannel)
} }
func (me *TestHelper) CreateMessagePost(message string) *model.Post { func (th *TestHelper) CreateMessagePost(message string) *model.Post {
return me.CreateMessagePostWithClient(me.Client, me.BasicChannel, message) return th.CreateMessagePostWithClient(th.Client, th.BasicChannel, message)
} }
func (me *TestHelper) CreatePostWithClient(client *model.Client4, channel *model.Channel) *model.Post { func (th *TestHelper) CreatePostWithClient(client *model.Client4, channel *model.Channel) *model.Post {
id := model.NewId() id := model.NewId()
post := &model.Post{ post := &model.Post{
@@ -556,7 +556,7 @@ func (me *TestHelper) CreatePostWithClient(client *model.Client4, channel *model
return rpost return rpost
} }
func (me *TestHelper) CreatePinnedPostWithClient(client *model.Client4, channel *model.Channel) *model.Post { func (th *TestHelper) CreatePinnedPostWithClient(client *model.Client4, channel *model.Channel) *model.Post {
id := model.NewId() id := model.NewId()
post := &model.Post{ post := &model.Post{
@@ -574,7 +574,7 @@ func (me *TestHelper) CreatePinnedPostWithClient(client *model.Client4, channel
return rpost return rpost
} }
func (me *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel *model.Channel, message string) *model.Post { func (th *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel *model.Channel, message string) *model.Post {
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: message, Message: message,
@@ -589,9 +589,9 @@ func (me *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel
return rpost return rpost
} }
func (me *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post { func (th *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post {
post, err := me.App.Srv().Store.Post().Save(&model.Post{ post, err := th.App.Srv().Store.Post().Save(&model.Post{
UserId: me.BasicUser.Id, UserId: th.BasicUser.Id,
ChannelId: channel.Id, ChannelId: channel.Id,
Message: message, Message: message,
CreateAt: createAtTime, CreateAt: createAtTime,
@@ -604,11 +604,11 @@ func (me *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message
return post return post
} }
func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel { func (th *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
var err *model.AppError var err *model.AppError
var channel *model.Channel var channel *model.Channel
if channel, err = me.App.GetOrCreateDirectChannel(me.BasicUser.Id, user.Id); err != nil { if channel, err = th.App.GetOrCreateDirectChannel(th.BasicUser.Id, user.Id); err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())
time.Sleep(time.Second) time.Sleep(time.Second)
@@ -618,62 +618,62 @@ func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
return channel return channel
} }
func (me *TestHelper) LoginBasic() { func (th *TestHelper) LoginBasic() {
me.LoginBasicWithClient(me.Client) th.LoginBasicWithClient(th.Client)
} }
func (me *TestHelper) LoginBasic2() { func (th *TestHelper) LoginBasic2() {
me.LoginBasic2WithClient(me.Client) th.LoginBasic2WithClient(th.Client)
} }
func (me *TestHelper) LoginTeamAdmin() { func (th *TestHelper) LoginTeamAdmin() {
me.LoginTeamAdminWithClient(me.Client) th.LoginTeamAdminWithClient(th.Client)
} }
func (me *TestHelper) LoginSystemAdmin() { func (th *TestHelper) LoginSystemAdmin() {
me.LoginSystemAdminWithClient(me.SystemAdminClient) th.LoginSystemAdminWithClient(th.SystemAdminClient)
} }
func (me *TestHelper) LoginBasicWithClient(client *model.Client4) { func (th *TestHelper) LoginBasicWithClient(client *model.Client4) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
_, resp := client.Login(me.BasicUser.Email, me.BasicUser.Password) _, resp := client.Login(th.BasicUser.Email, th.BasicUser.Password)
if resp.Error != nil { if resp.Error != nil {
panic(resp.Error) panic(resp.Error)
} }
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) LoginBasic2WithClient(client *model.Client4) { func (th *TestHelper) LoginBasic2WithClient(client *model.Client4) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
_, resp := client.Login(me.BasicUser2.Email, me.BasicUser2.Password) _, resp := client.Login(th.BasicUser2.Email, th.BasicUser2.Password)
if resp.Error != nil { if resp.Error != nil {
panic(resp.Error) panic(resp.Error)
} }
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) LoginTeamAdminWithClient(client *model.Client4) { func (th *TestHelper) LoginTeamAdminWithClient(client *model.Client4) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
_, resp := client.Login(me.TeamAdminUser.Email, me.TeamAdminUser.Password) _, resp := client.Login(th.TeamAdminUser.Email, th.TeamAdminUser.Password)
if resp.Error != nil { if resp.Error != nil {
panic(resp.Error) panic(resp.Error)
} }
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) LoginSystemAdminWithClient(client *model.Client4) { func (th *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
_, resp := client.Login(me.SystemAdminUser.Email, me.SystemAdminUser.Password) _, resp := client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
if resp.Error != nil { if resp.Error != nil {
panic(resp.Error) panic(resp.Error)
} }
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) { func (th *TestHelper) UpdateActiveUser(user *model.User, active bool) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
_, err := me.App.UpdateActive(user, active) _, err := th.App.UpdateActive(user, active)
if err != nil { if err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())
@@ -684,10 +684,10 @@ func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) { func (th *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
err := me.App.JoinUserToTeam(team, user, "") err := th.App.JoinUserToTeam(team, user, "")
if err != nil { if err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())
@@ -698,10 +698,10 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel) *model.ChannelMember { func (th *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel) *model.ChannelMember {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
member, err := me.App.AddUserToChannel(user, channel) member, err := th.App.AddUserToChannel(user, channel)
if err != nil { if err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())
@@ -714,14 +714,14 @@ func (me *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel)
return member return member
} }
func (me *TestHelper) GenerateTestEmail() string { func (th *TestHelper) GenerateTestEmail() string {
if *me.App.Config().EmailSettings.SMTPServer != "localhost" && os.Getenv("CI_INBUCKET_PORT") == "" { if *th.App.Config().EmailSettings.SMTPServer != "localhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com") return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
} }
return strings.ToLower(model.NewId() + "@localhost") return strings.ToLower(model.NewId() + "@localhost")
} }
func (me *TestHelper) CreateGroup() *model.Group { func (th *TestHelper) CreateGroup() *model.Group {
id := model.NewId() id := model.NewId()
group := &model.Group{ group := &model.Group{
Name: model.NewString("n-" + id), Name: model.NewString("n-" + id),
@@ -731,7 +731,7 @@ func (me *TestHelper) CreateGroup() *model.Group {
} }
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
group, err := me.App.CreateGroup(group) group, err := th.App.CreateGroup(group)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -743,39 +743,39 @@ func (me *TestHelper) CreateGroup() *model.Group {
// SystemAdmin and Local clients. Several endpoints work in the same // SystemAdmin and Local clients. Several endpoints work in the same
// way when used by a fully privileged user and through the local // way when used by a fully privileged user and through the local
// mode, so this helper facilitates checking both // mode, so this helper facilitates checking both
func (me *TestHelper) TestForSystemAdminAndLocal(t *testing.T, f func(*testing.T, *model.Client4), name ...string) { func (th *TestHelper) TestForSystemAdminAndLocal(t *testing.T, f func(*testing.T, *model.Client4), name ...string) {
var testName string var testName string
if len(name) > 0 { if len(name) > 0 {
testName = name[0] + "/" testName = name[0] + "/"
} }
t.Run(testName+"SystemAdminClient", func(t *testing.T) { t.Run(testName+"SystemAdminClient", func(t *testing.T) {
f(t, me.SystemAdminClient) f(t, th.SystemAdminClient)
}) })
t.Run(testName+"LocalClient", func(t *testing.T) { t.Run(testName+"LocalClient", func(t *testing.T) {
f(t, me.LocalClient) f(t, th.LocalClient)
}) })
} }
// TestForAllClients runs a test function for all the clients // TestForAllClients runs a test function for all the clients
// registered in the TestHelper // registered in the TestHelper
func (me *TestHelper) TestForAllClients(t *testing.T, f func(*testing.T, *model.Client4), name ...string) { func (th *TestHelper) TestForAllClients(t *testing.T, f func(*testing.T, *model.Client4), name ...string) {
var testName string var testName string
if len(name) > 0 { if len(name) > 0 {
testName = name[0] + "/" testName = name[0] + "/"
} }
t.Run(testName+"Client", func(t *testing.T) { t.Run(testName+"Client", func(t *testing.T) {
f(t, me.Client) f(t, th.Client)
}) })
t.Run(testName+"SystemAdminClient", func(t *testing.T) { t.Run(testName+"SystemAdminClient", func(t *testing.T) {
f(t, me.SystemAdminClient) f(t, th.SystemAdminClient)
}) })
t.Run(testName+"LocalClient", func(t *testing.T) { t.Run(testName+"LocalClient", func(t *testing.T) {
f(t, me.LocalClient) f(t, th.LocalClient)
}) })
} }
@@ -914,8 +914,8 @@ func s3New(endpoint, accessKey, secretKey string, secure bool, signV2 bool, regi
return s3.New(endpoint, &opts) return s3.New(endpoint, &opts)
} }
func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error { func (th *TestHelper) cleanupTestFile(info *model.FileInfo) error {
cfg := me.App.Config() cfg := th.App.Config()
if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
endpoint := *cfg.FileSettings.AmazonS3Endpoint endpoint := *cfg.FileSettings.AmazonS3Endpoint
accessKey := *cfg.FileSettings.AmazonS3AccessKeyId accessKey := *cfg.FileSettings.AmazonS3AccessKeyId
@@ -964,12 +964,12 @@ func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
return nil return nil
} }
func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) { func (th *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
if cm, err := me.App.Srv().Store.Channel().GetMember(channel.Id, user.Id); err == nil { if cm, err := th.App.Srv().Store.Channel().GetMember(channel.Id, user.Id); err == nil {
cm.SchemeAdmin = true cm.SchemeAdmin = true
if _, err = me.App.Srv().Store.Channel().UpdateMember(cm); err != nil { if _, err = th.App.Srv().Store.Channel().UpdateMember(cm); err != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err) panic(err)
} }
@@ -981,12 +981,12 @@ func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Chan
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) { func (th *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
if tm, err := me.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil { if tm, err := th.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil {
tm.SchemeAdmin = true tm.SchemeAdmin = true
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil { if _, err = th.App.Srv().Store.Team().UpdateMember(tm); err != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err) panic(err)
} }
@@ -1001,12 +1001,12 @@ func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team)
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) { func (th *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
if tm, err := me.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil { if tm, err := th.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil {
tm.SchemeAdmin = false tm.SchemeAdmin = false
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil { if _, err = th.App.Srv().Store.Team().UpdateMember(tm); err != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err) panic(err)
} }
@@ -1021,7 +1021,7 @@ func (me *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Tea
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string { func (th *TestHelper) SaveDefaultRolePermissions() map[string][]string {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
results := make(map[string][]string) results := make(map[string][]string)
@@ -1034,7 +1034,7 @@ func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string {
"channel_user", "channel_user",
"channel_admin", "channel_admin",
} { } {
role, err1 := me.App.GetRoleByName(roleName) role, err1 := th.App.GetRoleByName(roleName)
if err1 != nil { if err1 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err1) panic(err1)
@@ -1047,11 +1047,11 @@ func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string {
return results return results
} }
func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) { func (th *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
for roleName, permissions := range data { for roleName, permissions := range data {
role, err1 := me.App.GetRoleByName(roleName) role, err1 := th.App.GetRoleByName(roleName)
if err1 != nil { if err1 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err1) panic(err1)
@@ -1063,7 +1063,7 @@ func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
role.Permissions = permissions role.Permissions = permissions
_, err2 := me.App.UpdateRole(role) _, err2 := th.App.UpdateRole(role)
if err2 != nil { if err2 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err2) panic(err2)
@@ -1073,10 +1073,10 @@ func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) RemovePermissionFromRole(permission string, roleName string) { func (th *TestHelper) RemovePermissionFromRole(permission string, roleName string) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
role, err1 := me.App.GetRoleByName(roleName) role, err1 := th.App.GetRoleByName(roleName)
if err1 != nil { if err1 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err1) panic(err1)
@@ -1096,7 +1096,7 @@ func (me *TestHelper) RemovePermissionFromRole(permission string, roleName strin
role.Permissions = newPermissions role.Permissions = newPermissions
_, err2 := me.App.UpdateRole(role) _, err2 := th.App.UpdateRole(role)
if err2 != nil { if err2 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err2) panic(err2)
@@ -1105,10 +1105,10 @@ func (me *TestHelper) RemovePermissionFromRole(permission string, roleName strin
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) AddPermissionToRole(permission string, roleName string) { func (th *TestHelper) AddPermissionToRole(permission string, roleName string) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
role, err1 := me.App.GetRoleByName(roleName) role, err1 := th.App.GetRoleByName(roleName)
if err1 != nil { if err1 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err1) panic(err1)
@@ -1123,7 +1123,7 @@ func (me *TestHelper) AddPermissionToRole(permission string, roleName string) {
role.Permissions = append(role.Permissions, permission) role.Permissions = append(role.Permissions, permission)
_, err2 := me.App.UpdateRole(role) _, err2 := th.App.UpdateRole(role)
if err2 != nil { if err2 != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(err2) panic(err2)
@@ -1132,22 +1132,22 @@ func (me *TestHelper) AddPermissionToRole(permission string, roleName string) {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
} }
func (me *TestHelper) SetupTeamScheme() *model.Scheme { func (th *TestHelper) SetupTeamScheme() *model.Scheme {
return me.SetupScheme(model.SCHEME_SCOPE_TEAM) return th.SetupScheme(model.SCHEME_SCOPE_TEAM)
} }
func (me *TestHelper) SetupChannelScheme() *model.Scheme { func (th *TestHelper) SetupChannelScheme() *model.Scheme {
return me.SetupScheme(model.SCHEME_SCOPE_CHANNEL) return th.SetupScheme(model.SCHEME_SCOPE_CHANNEL)
} }
func (me *TestHelper) SetupScheme(scope string) *model.Scheme { func (th *TestHelper) SetupScheme(scope string) *model.Scheme {
scheme := model.Scheme{ scheme := model.Scheme{
Name: model.NewId(), Name: model.NewId(),
DisplayName: model.NewId(), DisplayName: model.NewId(),
Scope: scope, Scope: scope,
} }
if scheme, err := me.App.CreateScheme(&scheme); err == nil { if scheme, err := th.App.CreateScheme(&scheme); err == nil {
return scheme return scheme
} else { } else {
panic(err) panic(err)