Skip to content

Commit

Permalink
[MM-61302] Use model.NewPointer throughout the code base (mattermost#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Oct 29, 2024
1 parent 97c7c25 commit 2424358
Show file tree
Hide file tree
Showing 10 changed files with 804 additions and 849 deletions.
42 changes: 19 additions & 23 deletions server/channels/api4/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ func TestPatchBot(t *testing.T) {

th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}
patchedBot, patchResp, err2 := client.PatchBot(context.Background(), createdBot.UserId, botPatch)
require.NoError(t, err2)
Expand All @@ -231,9 +231,9 @@ func TestPatchBot(t *testing.T) {

th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}
patchedBot, patchResp, err := client.PatchBot(context.Background(), createdBotSystemAdmin.UserId, botPatch)
require.NoError(t, err)
Expand Down Expand Up @@ -323,9 +323,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}

patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
Expand Down Expand Up @@ -379,9 +379,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}

_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
Expand Down Expand Up @@ -414,9 +414,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}

_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
Expand Down Expand Up @@ -449,9 +449,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer(GenerateTestUsername()),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}

patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(GenerateTestUsername()),
Username: model.NewPointer(GenerateTestUsername()),
}

patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
Expand Down Expand Up @@ -1546,7 +1546,3 @@ func TestConvertBotToUser(t *testing.T) {
CheckNotFoundStatus(t, resp)
})
}

func sToP(s string) *string {
return &s
}
2 changes: 1 addition & 1 deletion server/channels/api4/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestUpdateConfig(t *testing.T) {
require.Equal(t, nonEmptyURL, *cfg.ServiceSettings.SiteURL)

// Check that the Site URL can't be cleared
cfg.ServiceSettings.SiteURL = sToP("")
cfg.ServiceSettings.SiteURL = model.NewPointer("")
cfg, resp, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
require.Error(t, err)
CheckBadRequestStatus(t, resp)
Expand Down
24 changes: 10 additions & 14 deletions server/channels/app/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP("invalid username"),
DisplayName: sToP("an updated bot"),
Description: sToP("updated bot"),
Username: model.NewPointer("invalid username"),
DisplayName: model.NewPointer("an updated bot"),
Description: model.NewPointer("updated bot"),
}

_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
Expand All @@ -232,9 +232,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP("username"),
DisplayName: sToP("display name"),
Description: sToP(strings.Repeat("x", 1025)),
Username: model.NewPointer("username"),
DisplayName: model.NewPointer("display name"),
Description: model.NewPointer(strings.Repeat("x", 1025)),
}

_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
Expand All @@ -261,9 +261,9 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP("username2"),
DisplayName: sToP("updated bot"),
Description: sToP("an updated bot"),
Username: model.NewPointer("username2"),
DisplayName: model.NewPointer("updated bot"),
Description: model.NewPointer("an updated bot"),
}

patchedBot, err := th.App.PatchBot(th.Context, createdBot.UserId, botPatch)
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestPatchBot(t *testing.T) {
}()

botPatch := &model.BotPatch{
Username: sToP(th.BasicUser2.Username),
Username: model.NewPointer(th.BasicUser2.Username),
}

_, err = th.App.PatchBot(th.Context, bot.UserId, botPatch)
Expand Down Expand Up @@ -927,7 +927,3 @@ func TestGetSystemBot(t *testing.T) {
require.Equal(t, bot.UserId, botUser.Id)
})
}

func sToP(s string) *string {
return &s
}
Loading

0 comments on commit 2424358

Please sign in to comment.