[MM-31079]: Change receiver name for (me *TestHelper) in api4/apitestlib.go to be more idiomatic (#16501)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
625185cb5b
Коммит
0b012ad468
@@ -268,10 +268,10 @@ func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
||||
return th
|
||||
}
|
||||
|
||||
func (me *TestHelper) ShutdownApp() {
|
||||
func (th *TestHelper) ShutdownApp() {
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
me.Server.Shutdown()
|
||||
th.Server.Shutdown()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
@@ -284,14 +284,14 @@ func (me *TestHelper) ShutdownApp() {
|
||||
}
|
||||
}
|
||||
|
||||
func (me *TestHelper) TearDown() {
|
||||
func (th *TestHelper) TearDown() {
|
||||
utils.DisableDebugLogForTest()
|
||||
if me.IncludeCacheLayer {
|
||||
if th.IncludeCacheLayer {
|
||||
// Clean all the caches
|
||||
me.App.Srv().InvalidateAllCaches()
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
}
|
||||
|
||||
me.ShutdownApp()
|
||||
th.ShutdownApp()
|
||||
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
@@ -304,84 +304,84 @@ var userCache struct {
|
||||
BasicUser2 *model.User
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitLogin() *TestHelper {
|
||||
me.waitForConnectivity()
|
||||
func (th *TestHelper) InitLogin() *TestHelper {
|
||||
th.waitForConnectivity()
|
||||
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
me.SystemAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
|
||||
me.SystemAdminUser, _ = me.App.GetUser(me.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = me.SystemAdminUser.DeepCopy()
|
||||
th.SystemAdminUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
|
||||
th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy()
|
||||
|
||||
me.TeamAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
me.TeamAdminUser, _ = me.App.GetUser(me.TeamAdminUser.Id)
|
||||
userCache.TeamAdminUser = me.TeamAdminUser.DeepCopy()
|
||||
th.TeamAdminUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
th.TeamAdminUser, _ = th.App.GetUser(th.TeamAdminUser.Id)
|
||||
userCache.TeamAdminUser = th.TeamAdminUser.DeepCopy()
|
||||
|
||||
me.BasicUser = me.CreateUser()
|
||||
me.BasicUser, _ = me.App.GetUser(me.BasicUser.Id)
|
||||
userCache.BasicUser = me.BasicUser.DeepCopy()
|
||||
th.BasicUser = th.CreateUser()
|
||||
th.BasicUser, _ = th.App.GetUser(th.BasicUser.Id)
|
||||
userCache.BasicUser = th.BasicUser.DeepCopy()
|
||||
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
me.BasicUser2, _ = me.App.GetUser(me.BasicUser2.Id)
|
||||
userCache.BasicUser2 = me.BasicUser2.DeepCopy()
|
||||
th.BasicUser2 = th.CreateUser()
|
||||
th.BasicUser2, _ = th.App.GetUser(th.BasicUser2.Id)
|
||||
userCache.BasicUser2 = th.BasicUser2.DeepCopy()
|
||||
})
|
||||
// restore cached users
|
||||
me.SystemAdminUser = userCache.SystemAdminUser.DeepCopy()
|
||||
me.TeamAdminUser = userCache.TeamAdminUser.DeepCopy()
|
||||
me.BasicUser = userCache.BasicUser.DeepCopy()
|
||||
me.BasicUser2 = userCache.BasicUser2.DeepCopy()
|
||||
mainHelper.GetSQLStore().GetMaster().Insert(me.SystemAdminUser, me.TeamAdminUser, me.BasicUser, me.BasicUser2)
|
||||
th.SystemAdminUser = userCache.SystemAdminUser.DeepCopy()
|
||||
th.TeamAdminUser = userCache.TeamAdminUser.DeepCopy()
|
||||
th.BasicUser = userCache.BasicUser.DeepCopy()
|
||||
th.BasicUser2 = userCache.BasicUser2.DeepCopy()
|
||||
mainHelper.GetSQLStore().GetMaster().Insert(th.SystemAdminUser, th.TeamAdminUser, th.BasicUser, th.BasicUser2)
|
||||
// restore non hashed password for login
|
||||
me.SystemAdminUser.Password = "Pa$$word11"
|
||||
me.TeamAdminUser.Password = "Pa$$word11"
|
||||
me.BasicUser.Password = "Pa$$word11"
|
||||
me.BasicUser2.Password = "Pa$$word11"
|
||||
th.SystemAdminUser.Password = "Pa$$word11"
|
||||
th.TeamAdminUser.Password = "Pa$$word11"
|
||||
th.BasicUser.Password = "Pa$$word11"
|
||||
th.BasicUser2.Password = "Pa$$word11"
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
me.LoginSystemAdmin()
|
||||
th.LoginSystemAdmin()
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
me.LoginTeamAdmin()
|
||||
th.LoginTeamAdmin()
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
return me
|
||||
return th
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.BasicTeam = me.CreateTeam()
|
||||
me.BasicChannel = me.CreatePublicChannel()
|
||||
me.BasicPrivateChannel = me.CreatePrivateChannel()
|
||||
me.BasicPrivateChannel2 = me.CreatePrivateChannel()
|
||||
me.BasicDeletedChannel = me.CreatePublicChannel()
|
||||
me.BasicChannel2 = me.CreatePublicChannel()
|
||||
me.BasicPost = me.CreatePost()
|
||||
me.LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.App.AddUserToChannel(me.BasicUser, me.BasicChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser, me.BasicChannel2)
|
||||
me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel2)
|
||||
me.App.AddUserToChannel(me.BasicUser, me.BasicPrivateChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser2, me.BasicPrivateChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser, me.BasicDeletedChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser2, me.BasicDeletedChannel)
|
||||
me.App.UpdateUserRoles(me.BasicUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
me.Client.DeleteChannel(me.BasicDeletedChannel.Id)
|
||||
me.LoginBasic()
|
||||
me.Group = me.CreateGroup()
|
||||
func (th *TestHelper) InitBasic() *TestHelper {
|
||||
th.BasicTeam = th.CreateTeam()
|
||||
th.BasicChannel = th.CreatePublicChannel()
|
||||
th.BasicPrivateChannel = th.CreatePrivateChannel()
|
||||
th.BasicPrivateChannel2 = th.CreatePrivateChannel()
|
||||
th.BasicDeletedChannel = th.CreatePublicChannel()
|
||||
th.BasicChannel2 = th.CreatePublicChannel()
|
||||
th.BasicPost = th.CreatePost()
|
||||
th.LinkUserToTeam(th.BasicUser, th.BasicTeam)
|
||||
th.LinkUserToTeam(th.BasicUser2, th.BasicTeam)
|
||||
th.App.AddUserToChannel(th.BasicUser, th.BasicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, th.BasicChannel2)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel2)
|
||||
th.App.AddUserToChannel(th.BasicUser, th.BasicPrivateChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicPrivateChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser, th.BasicDeletedChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicDeletedChannel)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
th.Client.DeleteChannel(th.BasicDeletedChannel.Id)
|
||||
th.LoginBasic()
|
||||
th.Group = th.CreateGroup()
|
||||
|
||||
return me
|
||||
return th
|
||||
}
|
||||
|
||||
func (me *TestHelper) waitForConnectivity() {
|
||||
func (th *TestHelper) waitForConnectivity() {
|
||||
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 {
|
||||
conn.Close()
|
||||
return
|
||||
@@ -391,12 +391,12 @@ func (me *TestHelper) waitForConnectivity() {
|
||||
panic("unable to connect")
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateClient() *model.Client4 {
|
||||
return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", me.App.Srv().ListenAddr.Port))
|
||||
func (th *TestHelper) CreateClient() *model.Client4 {
|
||||
return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port))
|
||||
}
|
||||
|
||||
// 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{
|
||||
Transport: &http.Transport{
|
||||
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) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.Client.AuthToken)
|
||||
func (th *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.Client.AuthToken)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateWebSocketSystemAdminClient() (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.SystemAdminClient.AuthToken)
|
||||
func (th *TestHelper) CreateWebSocketSystemAdminClient() (*model.WebSocketClient, *model.AppError) {
|
||||
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) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), client.AuthToken)
|
||||
func (th *TestHelper) CreateWebSocketClientWithClient(client *model.Client4) (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), client.AuthToken)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateBotWithSystemAdminClient() *model.Bot {
|
||||
return me.CreateBotWithClient((me.SystemAdminClient))
|
||||
func (th *TestHelper) CreateBotWithSystemAdminClient() *model.Bot {
|
||||
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{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
@@ -443,20 +443,20 @@ func (me *TestHelper) CreateBotWithClient(client *model.Client4) *model.Bot {
|
||||
return rbot
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateUser() *model.User {
|
||||
return me.CreateUserWithClient(me.Client)
|
||||
func (th *TestHelper) CreateUser() *model.User {
|
||||
return th.CreateUserWithClient(th.Client)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateTeam() *model.Team {
|
||||
return me.CreateTeamWithClient(me.Client)
|
||||
func (th *TestHelper) CreateTeam() *model.Team {
|
||||
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()
|
||||
team := &model.Team{
|
||||
DisplayName: "dn_" + id,
|
||||
Name: GenerateTestTeamName(),
|
||||
Email: me.GenerateTestEmail(),
|
||||
Email: th.GenerateTestEmail(),
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
@@ -469,11 +469,11 @@ func (me *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
|
||||
return rteam
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
func (th *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
id := model.NewId()
|
||||
|
||||
user := &model.User{
|
||||
Email: me.GenerateTestEmail(),
|
||||
Email: th.GenerateTestEmail(),
|
||||
Username: GenerateTestUsername(),
|
||||
Nickname: "nn_" + id,
|
||||
FirstName: "f_" + id,
|
||||
@@ -488,7 +488,7 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
@@ -496,19 +496,19 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
return ruser
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreatePublicChannel() *model.Channel {
|
||||
return me.CreateChannelWithClient(me.Client, model.CHANNEL_OPEN)
|
||||
func (th *TestHelper) CreatePublicChannel() *model.Channel {
|
||||
return th.CreateChannelWithClient(th.Client, model.CHANNEL_OPEN)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreatePrivateChannel() *model.Channel {
|
||||
return me.CreateChannelWithClient(me.Client, model.CHANNEL_PRIVATE)
|
||||
func (th *TestHelper) CreatePrivateChannel() *model.Channel {
|
||||
return th.CreateChannelWithClient(th.Client, model.CHANNEL_PRIVATE)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateChannelWithClient(client *model.Client4, channelType string) *model.Channel {
|
||||
return me.CreateChannelWithClientAndTeam(client, channelType, me.BasicTeam.Id)
|
||||
func (th *TestHelper) CreateChannelWithClient(client *model.Client4, channelType string) *model.Channel {
|
||||
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()
|
||||
|
||||
channel := &model.Channel{
|
||||
@@ -527,19 +527,19 @@ func (me *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, chan
|
||||
return rchannel
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreatePost() *model.Post {
|
||||
return me.CreatePostWithClient(me.Client, me.BasicChannel)
|
||||
func (th *TestHelper) CreatePost() *model.Post {
|
||||
return th.CreatePostWithClient(th.Client, th.BasicChannel)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreatePinnedPost() *model.Post {
|
||||
return me.CreatePinnedPostWithClient(me.Client, me.BasicChannel)
|
||||
func (th *TestHelper) CreatePinnedPost() *model.Post {
|
||||
return th.CreatePinnedPostWithClient(th.Client, th.BasicChannel)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateMessagePost(message string) *model.Post {
|
||||
return me.CreateMessagePostWithClient(me.Client, me.BasicChannel, message)
|
||||
func (th *TestHelper) CreateMessagePost(message string) *model.Post {
|
||||
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()
|
||||
|
||||
post := &model.Post{
|
||||
@@ -556,7 +556,7 @@ func (me *TestHelper) CreatePostWithClient(client *model.Client4, channel *model
|
||||
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()
|
||||
|
||||
post := &model.Post{
|
||||
@@ -574,7 +574,7 @@ func (me *TestHelper) CreatePinnedPostWithClient(client *model.Client4, channel
|
||||
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{
|
||||
ChannelId: channel.Id,
|
||||
Message: message,
|
||||
@@ -589,9 +589,9 @@ func (me *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel
|
||||
return rpost
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post {
|
||||
post, err := me.App.Srv().Store.Post().Save(&model.Post{
|
||||
UserId: me.BasicUser.Id,
|
||||
func (th *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post {
|
||||
post, err := th.App.Srv().Store.Post().Save(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: message,
|
||||
CreateAt: createAtTime,
|
||||
@@ -604,11 +604,11 @@ func (me *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message
|
||||
return post
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
|
||||
func (th *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
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())
|
||||
|
||||
time.Sleep(time.Second)
|
||||
@@ -618,62 +618,62 @@ func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
|
||||
return channel
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginBasic() {
|
||||
me.LoginBasicWithClient(me.Client)
|
||||
func (th *TestHelper) LoginBasic() {
|
||||
th.LoginBasicWithClient(th.Client)
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginBasic2() {
|
||||
me.LoginBasic2WithClient(me.Client)
|
||||
func (th *TestHelper) LoginBasic2() {
|
||||
th.LoginBasic2WithClient(th.Client)
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginTeamAdmin() {
|
||||
me.LoginTeamAdminWithClient(me.Client)
|
||||
func (th *TestHelper) LoginTeamAdmin() {
|
||||
th.LoginTeamAdminWithClient(th.Client)
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginSystemAdmin() {
|
||||
me.LoginSystemAdminWithClient(me.SystemAdminClient)
|
||||
func (th *TestHelper) LoginSystemAdmin() {
|
||||
th.LoginSystemAdminWithClient(th.SystemAdminClient)
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginBasicWithClient(client *model.Client4) {
|
||||
func (th *TestHelper) LoginBasicWithClient(client *model.Client4) {
|
||||
utils.DisableDebugLogForTest()
|
||||
_, resp := client.Login(me.BasicUser.Email, me.BasicUser.Password)
|
||||
_, resp := client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
if resp.Error != nil {
|
||||
panic(resp.Error)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginBasic2WithClient(client *model.Client4) {
|
||||
func (th *TestHelper) LoginBasic2WithClient(client *model.Client4) {
|
||||
utils.DisableDebugLogForTest()
|
||||
_, resp := client.Login(me.BasicUser2.Email, me.BasicUser2.Password)
|
||||
_, resp := client.Login(th.BasicUser2.Email, th.BasicUser2.Password)
|
||||
if resp.Error != nil {
|
||||
panic(resp.Error)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginTeamAdminWithClient(client *model.Client4) {
|
||||
func (th *TestHelper) LoginTeamAdminWithClient(client *model.Client4) {
|
||||
utils.DisableDebugLogForTest()
|
||||
_, resp := client.Login(me.TeamAdminUser.Email, me.TeamAdminUser.Password)
|
||||
_, resp := client.Login(th.TeamAdminUser.Email, th.TeamAdminUser.Password)
|
||||
if resp.Error != nil {
|
||||
panic(resp.Error)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
|
||||
func (th *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
|
||||
utils.DisableDebugLogForTest()
|
||||
_, resp := client.Login(me.SystemAdminUser.Email, me.SystemAdminUser.Password)
|
||||
_, resp := client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
if resp.Error != nil {
|
||||
panic(resp.Error)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
func (th *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
_, err := me.App.UpdateActive(user, active)
|
||||
_, err := th.App.UpdateActive(user, active)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
@@ -684,10 +684,10 @@ func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
func (th *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
err := me.App.JoinUserToTeam(team, user, "")
|
||||
err := th.App.JoinUserToTeam(team, user, "")
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
@@ -698,10 +698,10 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
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()
|
||||
|
||||
member, err := me.App.AddUserToChannel(user, channel)
|
||||
member, err := th.App.AddUserToChannel(user, channel)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
@@ -714,14 +714,14 @@ func (me *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel)
|
||||
return member
|
||||
}
|
||||
|
||||
func (me *TestHelper) GenerateTestEmail() string {
|
||||
if *me.App.Config().EmailSettings.SMTPServer != "localhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
|
||||
func (th *TestHelper) GenerateTestEmail() string {
|
||||
if *th.App.Config().EmailSettings.SMTPServer != "localhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
|
||||
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
|
||||
}
|
||||
return strings.ToLower(model.NewId() + "@localhost")
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateGroup() *model.Group {
|
||||
func (th *TestHelper) CreateGroup() *model.Group {
|
||||
id := model.NewId()
|
||||
group := &model.Group{
|
||||
Name: model.NewString("n-" + id),
|
||||
@@ -731,7 +731,7 @@ func (me *TestHelper) CreateGroup() *model.Group {
|
||||
}
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
group, err := me.App.CreateGroup(group)
|
||||
group, err := th.App.CreateGroup(group)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -743,39 +743,39 @@ func (me *TestHelper) CreateGroup() *model.Group {
|
||||
// SystemAdmin and Local clients. Several endpoints work in the same
|
||||
// way when used by a fully privileged user and through the local
|
||||
// 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
|
||||
if len(name) > 0 {
|
||||
testName = name[0] + "/"
|
||||
}
|
||||
|
||||
t.Run(testName+"SystemAdminClient", func(t *testing.T) {
|
||||
f(t, me.SystemAdminClient)
|
||||
f(t, th.SystemAdminClient)
|
||||
})
|
||||
|
||||
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
|
||||
// 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
|
||||
if len(name) > 0 {
|
||||
testName = name[0] + "/"
|
||||
}
|
||||
|
||||
t.Run(testName+"Client", func(t *testing.T) {
|
||||
f(t, me.Client)
|
||||
f(t, th.Client)
|
||||
})
|
||||
|
||||
t.Run(testName+"SystemAdminClient", func(t *testing.T) {
|
||||
f(t, me.SystemAdminClient)
|
||||
f(t, th.SystemAdminClient)
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
|
||||
cfg := me.App.Config()
|
||||
func (th *TestHelper) cleanupTestFile(info *model.FileInfo) error {
|
||||
cfg := th.App.Config()
|
||||
if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
|
||||
endpoint := *cfg.FileSettings.AmazonS3Endpoint
|
||||
accessKey := *cfg.FileSettings.AmazonS3AccessKeyId
|
||||
@@ -964,12 +964,12 @@ func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
|
||||
func (th *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
|
||||
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
|
||||
if _, err = me.App.Srv().Store.Channel().UpdateMember(cm); err != nil {
|
||||
if _, err = th.App.Srv().Store.Channel().UpdateMember(cm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
@@ -981,12 +981,12 @@ func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Chan
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
|
||||
func (th *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
|
||||
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
|
||||
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
if _, err = th.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
@@ -1001,12 +1001,12 @@ func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team)
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
|
||||
func (th *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
|
||||
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
|
||||
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
if _, err = th.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
@@ -1021,7 +1021,7 @@ func (me *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Tea
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string {
|
||||
func (th *TestHelper) SaveDefaultRolePermissions() map[string][]string {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
results := make(map[string][]string)
|
||||
@@ -1034,7 +1034,7 @@ func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string {
|
||||
"channel_user",
|
||||
"channel_admin",
|
||||
} {
|
||||
role, err1 := me.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1047,11 +1047,11 @@ func (me *TestHelper) SaveDefaultRolePermissions() map[string][]string {
|
||||
return results
|
||||
}
|
||||
|
||||
func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
func (th *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
for roleName, permissions := range data {
|
||||
role, err1 := me.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1063,7 +1063,7 @@ func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
|
||||
role.Permissions = permissions
|
||||
|
||||
_, err2 := me.App.UpdateRole(role)
|
||||
_, err2 := th.App.UpdateRole(role)
|
||||
if err2 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err2)
|
||||
@@ -1073,10 +1073,10 @@ func (me *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) RemovePermissionFromRole(permission string, roleName string) {
|
||||
func (th *TestHelper) RemovePermissionFromRole(permission string, roleName string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
role, err1 := me.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1096,7 +1096,7 @@ func (me *TestHelper) RemovePermissionFromRole(permission string, roleName strin
|
||||
|
||||
role.Permissions = newPermissions
|
||||
|
||||
_, err2 := me.App.UpdateRole(role)
|
||||
_, err2 := th.App.UpdateRole(role)
|
||||
if err2 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err2)
|
||||
@@ -1105,10 +1105,10 @@ func (me *TestHelper) RemovePermissionFromRole(permission string, roleName strin
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) AddPermissionToRole(permission string, roleName string) {
|
||||
func (th *TestHelper) AddPermissionToRole(permission string, roleName string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
role, err1 := me.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1123,7 +1123,7 @@ func (me *TestHelper) AddPermissionToRole(permission string, roleName string) {
|
||||
|
||||
role.Permissions = append(role.Permissions, permission)
|
||||
|
||||
_, err2 := me.App.UpdateRole(role)
|
||||
_, err2 := th.App.UpdateRole(role)
|
||||
if err2 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err2)
|
||||
@@ -1132,22 +1132,22 @@ func (me *TestHelper) AddPermissionToRole(permission string, roleName string) {
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func (me *TestHelper) SetupTeamScheme() *model.Scheme {
|
||||
return me.SetupScheme(model.SCHEME_SCOPE_TEAM)
|
||||
func (th *TestHelper) SetupTeamScheme() *model.Scheme {
|
||||
return th.SetupScheme(model.SCHEME_SCOPE_TEAM)
|
||||
}
|
||||
|
||||
func (me *TestHelper) SetupChannelScheme() *model.Scheme {
|
||||
return me.SetupScheme(model.SCHEME_SCOPE_CHANNEL)
|
||||
func (th *TestHelper) SetupChannelScheme() *model.Scheme {
|
||||
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{
|
||||
Name: model.NewId(),
|
||||
DisplayName: model.NewId(),
|
||||
Scope: scope,
|
||||
}
|
||||
|
||||
if scheme, err := me.App.CreateScheme(&scheme); err == nil {
|
||||
if scheme, err := th.App.CreateScheme(&scheme); err == nil {
|
||||
return scheme
|
||||
} else {
|
||||
panic(err)
|
||||
|
||||
Ссылка в новой задаче
Block a user