diff --git a/server/channels/api4/bot_test.go b/server/channels/api4/bot_test.go index dded8d514be..be7e79337b3 100644 --- a/server/channels/api4/bot_test.go +++ b/server/channels/api4/bot_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -1546,7 +1546,3 @@ func TestConvertBotToUser(t *testing.T) { CheckNotFoundStatus(t, resp) }) } - -func sToP(s string) *string { - return &s -} diff --git a/server/channels/api4/config_test.go b/server/channels/api4/config_test.go index df915f11244..e2c34c2ae1b 100644 --- a/server/channels/api4/config_test.go +++ b/server/channels/api4/config_test.go @@ -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) diff --git a/server/channels/app/bot_test.go b/server/channels/app/bot_test.go index 560c0023468..7c3fdfe694b 100644 --- a/server/channels/app/bot_test.go +++ b/server/channels/app/bot_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -927,7 +927,3 @@ func TestGetSystemBot(t *testing.T) { require.Equal(t, bot.UserId, botUser.Id) }) } - -func sToP(s string) *string { - return &s -} diff --git a/server/channels/app/import_functions_test.go b/server/channels/app/import_functions_test.go index 41dc0159bec..08aa496cf90 100644 --- a/server/channels/app/import_functions_test.go +++ b/server/channels/app/import_functions_test.go @@ -39,33 +39,33 @@ func TestImportImportScheme(t *testing.T) { // Try importing an invalid scheme in dryRun mode. data := imports.SchemeImportData{ - Name: ptrStr(model.NewId()), - Scope: ptrStr("team"), + Name: model.NewPointer(model.NewId()), + Scope: model.NewPointer("team"), DefaultTeamGuestRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultTeamUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultTeamAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelGuestRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, - Description: ptrStr("description"), + Description: model.NewPointer("description"), } err := th.App.importScheme(th.Context, &data, true) @@ -75,7 +75,7 @@ func TestImportImportScheme(t *testing.T) { require.Error(t, nErr, "Scheme should not have imported.") // Try importing a valid scheme in dryRun mode. - data.DisplayName = ptrStr("display name") + data.DisplayName = model.NewPointer("display name") err = th.App.importScheme(th.Context, &data, true) require.Nil(t, err, "Should have succeeded.") @@ -93,7 +93,7 @@ func TestImportImportScheme(t *testing.T) { require.Error(t, nErr, "Scheme should not have imported.") // Try importing a valid scheme with all params set. - data.DisplayName = ptrStr("display name") + data.DisplayName = model.NewPointer("display name") err = th.App.importScheme(th.Context, &data, false) require.Nil(t, err, "Should have succeeded.") @@ -149,8 +149,8 @@ func TestImportImportScheme(t *testing.T) { assert.True(t, role.SchemeManaged) // Try modifying all the fields and re-importing. - data.DisplayName = ptrStr("new display name") - data.Description = ptrStr("new description") + data.DisplayName = model.NewPointer("new display name") + data.Description = model.NewPointer("new description") err = th.App.importScheme(th.Context, &data, false) require.Nil(t, err, "Should have succeeded: %v", err) @@ -206,7 +206,7 @@ func TestImportImportScheme(t *testing.T) { assert.True(t, role.SchemeManaged) // Try changing the scope of the scheme and reimporting. - data.Scope = ptrStr("channel") + data.Scope = model.NewPointer("channel") err = th.App.importScheme(th.Context, &data, false) require.NotNil(t, err, "Should have failed to import.") @@ -233,25 +233,25 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { // Try importing an invalid scheme in dryRun mode. data := imports.SchemeImportData{ - Name: ptrStr(model.NewId()), - Scope: ptrStr("team"), + Name: model.NewPointer(model.NewId()), + Scope: model.NewPointer("team"), DefaultTeamUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultTeamAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, - Description: ptrStr("description"), + Description: model.NewPointer("description"), } err := th.App.importScheme(th.Context, &data, true) @@ -261,7 +261,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { require.Error(t, nErr, "Scheme should not have imported.") // Try importing a valid scheme in dryRun mode. - data.DisplayName = ptrStr("display name") + data.DisplayName = model.NewPointer("display name") err = th.App.importScheme(th.Context, &data, true) require.Nil(t, err, "Should have succeeded.") @@ -279,7 +279,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { require.Error(t, nErr, "Scheme should not have imported.") // Try importing a valid scheme with all params set. - data.DisplayName = ptrStr("display name") + data.DisplayName = model.NewPointer("display name") err = th.App.importScheme(th.Context, &data, false) require.Nil(t, err, "Should have succeeded.") @@ -335,8 +335,8 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { assert.True(t, role.SchemeManaged) // Try modifying all the fields and re-importing. - data.DisplayName = ptrStr("new display name") - data.Description = ptrStr("new description") + data.DisplayName = model.NewPointer("new display name") + data.Description = model.NewPointer("new description") err = th.App.importScheme(th.Context, &data, false) require.Nil(t, err, "Should have succeeded: %v", err) @@ -392,7 +392,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { assert.True(t, role.SchemeManaged) // Try changing the scope of the scheme and reimporting. - data.Scope = ptrStr("channel") + data.Scope = model.NewPointer("channel") err = th.App.importScheme(th.Context, &data, false) require.NotNil(t, err, "Should have failed to import.") @@ -423,7 +423,7 @@ func TestImportImportRole(t *testing.T) { require.Error(t, nErr, "Should have failed to import.") // Try importing the valid role in dryRun mode. - data.DisplayName = ptrStr("display name") + data.DisplayName = model.NewPointer("display name") err = th.App.importRole(th.Context, &data, true) require.Nil(t, err, "Should have succeeded.") @@ -441,8 +441,8 @@ func TestImportImportRole(t *testing.T) { require.Error(t, nErr, "Role should not have imported.") // Try importing a valid role with all params set. - data.DisplayName = ptrStr("display name") - data.Description = ptrStr("description") + data.DisplayName = model.NewPointer("display name") + data.Description = model.NewPointer("description") data.Permissions = &[]string{"invite_user", "add_user_to_team"} err = th.App.importRole(th.Context, &data, false) @@ -459,8 +459,8 @@ func TestImportImportRole(t *testing.T) { assert.False(t, role.SchemeManaged) // Try changing all the params and reimporting. - data.DisplayName = ptrStr("new display name") - data.Description = ptrStr("description") + data.DisplayName = model.NewPointer("new display name") + data.Description = model.NewPointer("description") data.Permissions = &[]string{"manage_slash_commands"} data.SchemeManaged = model.NewPointer(true) @@ -480,7 +480,7 @@ func TestImportImportRole(t *testing.T) { // Check that re-importing with only required fields doesn't update the others. data2 := imports.RoleImportData{ Name: &rid1, - DisplayName: ptrStr("new display name again"), + DisplayName: model.NewPointer("new display name again"), } err = th.App.importRole(th.Context, &data2, false) @@ -533,7 +533,7 @@ func TestImportImportTeam(t *testing.T) { require.Error(t, err, "Should have received an error importing an invalid team.") // Do a valid team in dry-run mode. - data.Type = ptrStr("O") + data.Type = model.NewPointer("O") appErr := th.App.importTeam(th.Context, &data, true) require.Nil(t, appErr, "Received an error validating valid team.") @@ -541,7 +541,7 @@ func TestImportImportTeam(t *testing.T) { th.CheckTeamCount(t, teamsCount) // Do an invalid team in apply mode, check db changes. - data.Type = ptrStr("XYZ") + data.Type = model.NewPointer("XYZ") err = th.App.importTeam(th.Context, &data, false) require.Error(t, err, "Import should have failed on invalid team.") @@ -549,7 +549,7 @@ func TestImportImportTeam(t *testing.T) { th.CheckTeamCount(t, teamsCount) // Do a valid team in apply mode, check db changes. - data.Type = ptrStr("O") + data.Type = model.NewPointer("O") appErr = th.App.importTeam(th.Context, &data, false) require.Nil(t, appErr, "Received an error importing valid team: %v", err) @@ -567,14 +567,14 @@ func TestImportImportTeam(t *testing.T) { assert.Equal(t, scheme1.Id, *team.SchemeId) // Alter all the fields of that team (apart from unique identifier) and import again. - data.DisplayName = ptrStr("Display Name 2") - data.Type = ptrStr("P") - data.Description = ptrStr("The new description") - data.AllowOpenInvite = ptrBool(false) + data.DisplayName = model.NewPointer("Display Name 2") + data.Type = model.NewPointer("P") + data.Description = model.NewPointer("The new description") + data.AllowOpenInvite = model.NewPointer(false) data.Scheme = &scheme2.Name // Check that the original number of teams are again in the DB (because this query doesn't include deleted). - data.Type = ptrStr("O") + data.Type = model.NewPointer("O") appErr = th.App.importTeam(th.Context, &data, false) require.Nil(t, appErr, "Received an error importing updated valid team.") @@ -609,8 +609,8 @@ func TestImportImportChannel(t *testing.T) { teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, err := th.App.GetTeamByName(teamName) require.Nil(t, err, "Failed to get team from database.") @@ -623,10 +623,10 @@ func TestImportImportChannel(t *testing.T) { chanOpen := model.ChannelTypeOpen data := imports.ChannelImportData{ Team: &teamName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanOpen, - Header: ptrStr("Channel Header"), - Purpose: ptrStr("Channel Purpose"), + Header: model.NewPointer("Channel Header"), + Purpose: model.NewPointer("Channel Purpose"), Scheme: &scheme1.Name, } err = th.App.importChannel(th.Context, &data, true) @@ -636,8 +636,8 @@ func TestImportImportChannel(t *testing.T) { th.CheckChannelsCount(t, channelCount) // Do a valid channel with a nonexistent team in dry-run mode. - data.Name = ptrStr("channelname") - data.Team = ptrStr(model.NewId()) + data.Name = model.NewPointer("channelname") + data.Team = model.NewPointer(model.NewId()) err = th.App.importChannel(th.Context, &data, true) require.Nil(t, err, "Expected success as cannot validate channel name in dry run mode.") @@ -661,8 +661,8 @@ func TestImportImportChannel(t *testing.T) { th.CheckChannelsCount(t, channelCount) // Do a valid channel in apply mode with a non-existent team. - data.Name = ptrStr("channelname") - data.Team = ptrStr(model.NewId()) + data.Name = model.NewPointer("channelname") + data.Team = model.NewPointer(model.NewId()) err = th.App.importChannel(th.Context, &data, false) require.NotNil(t, err, "Expected error due to non-existent team (apply mode).") @@ -696,10 +696,10 @@ func TestImportImportChannel(t *testing.T) { // Alter all the fields of that channel. cTypePr := model.ChannelTypePrivate - data.DisplayName = ptrStr("Changed Disp Name") + data.DisplayName = model.NewPointer("Changed Disp Name") data.Type = &cTypePr - data.Header = ptrStr("New Header") - data.Purpose = ptrStr("New Purpose") + data.Header = model.NewPointer("New Header") + data.Purpose = model.NewPointer("New Purpose") data.Scheme = &scheme2.Name err = th.App.importChannel(th.Context, &data, false) require.Nil(t, err, "Expected success in apply mode") @@ -720,11 +720,11 @@ func TestImportImportChannel(t *testing.T) { // Do a valid archived channel. now := model.GetMillis() - data.Name = ptrStr("archivedchannel") - data.DisplayName = ptrStr("Archived Channel") + data.Name = model.NewPointer("archivedchannel") + data.DisplayName = model.NewPointer("Archived Channel") data.Type = &chanOpen - data.Header = ptrStr("Archived Channel Header") - data.Purpose = ptrStr("Archived Channel Purpose") + data.Header = model.NewPointer("Archived Channel Header") + data.Purpose = model.NewPointer("Archived Channel Purpose") data.Scheme = &scheme1.Name data.DeletedAt = &now err = th.App.importChannel(th.Context, &data, false) @@ -747,7 +747,7 @@ func TestImportImportUser(t *testing.T) { // Do an invalid user in dry-run mode. data := imports.UserImportData{ - Username: ptrStr(model.NewUsername()), + Username: model.NewPointer(model.NewUsername()), } err = th.App.importUser(th.Context, &data, true) require.Error(t, err, "Should have failed to import invalid user.") @@ -762,8 +762,8 @@ func TestImportImportUser(t *testing.T) { // Do a valid user in dry-run mode. data = imports.UserImportData{ - Username: ptrStr(model.NewUsername()), - Email: ptrStr(model.NewId() + "@example.com"), + Username: model.NewPointer(model.NewUsername()), + Email: model.NewPointer(model.NewId() + "@example.com"), } appErr := th.App.importUser(th.Context, &data, true) require.Nil(t, appErr, "Should have succeeded to import valid user.") @@ -778,7 +778,7 @@ func TestImportImportUser(t *testing.T) { // Do an invalid user in apply mode. data = imports.UserImportData{ - Username: ptrStr(model.NewUsername()), + Username: model.NewPointer(model.NewUsername()), } err = th.App.importUser(th.Context, &data, false) require.Error(t, err, "Should have failed to import invalid user.") @@ -795,13 +795,13 @@ func TestImportImportUser(t *testing.T) { username := model.NewUsername() testsDir, _ := fileutils.FindDir("tests") data = imports.UserImportData{ - ProfileImage: ptrStr(filepath.Join(testsDir, "test.png")), + ProfileImage: model.NewPointer(filepath.Join(testsDir, "test.png")), Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), - Nickname: ptrStr(model.NewId()), - FirstName: ptrStr(model.NewId()), - LastName: ptrStr(model.NewId()), - Position: ptrStr(model.NewId()), + Email: model.NewPointer(model.NewId() + "@example.com"), + Nickname: model.NewPointer(model.NewId()), + FirstName: model.NewPointer(model.NewId()), + LastName: model.NewPointer(model.NewId()), + Position: model.NewPointer(model.NewId()), } appErr = th.App.importUser(th.Context, &data, false) require.Nil(t, appErr, "Should have succeeded to import valid user.") @@ -835,16 +835,16 @@ func TestImportImportUser(t *testing.T) { require.Equal(t, user.Roles, "system_user", "Expected roles to be system_user") // Alter all the fields of that user. - data.Email = ptrStr(model.NewId() + "@example.com") - data.ProfileImage = ptrStr(filepath.Join(testsDir, "testgif.gif")) - data.AuthService = ptrStr("ldap") + data.Email = model.NewPointer(model.NewId() + "@example.com") + data.ProfileImage = model.NewPointer(filepath.Join(testsDir, "testgif.gif")) + data.AuthService = model.NewPointer("ldap") data.AuthData = &username - data.Nickname = ptrStr(model.NewId()) - data.FirstName = ptrStr(model.NewId()) - data.LastName = ptrStr(model.NewId()) - data.Position = ptrStr(model.NewId()) - data.Roles = ptrStr("system_admin system_user") - data.Locale = ptrStr("zh_CN") + data.Nickname = model.NewPointer(model.NewId()) + data.FirstName = model.NewPointer(model.NewId()) + data.LastName = model.NewPointer(model.NewId()) + data.Position = model.NewPointer(model.NewId()) + data.Roles = model.NewPointer("system_admin system_user") + data.Locale = model.NewPointer("zh_CN") appErr = th.App.importUser(th.Context, &data, false) require.Nil(t, appErr, "Should have succeeded to update valid user %v", err) @@ -877,7 +877,7 @@ func TestImportImportUser(t *testing.T) { require.Equal(t, *data.Roles, user.Roles, "Expected roles to be set: %v", user.Roles) // Check Password and AuthData together. - data.Password = ptrStr("PasswordTest") + data.Password = model.NewPointer("PasswordTest") appErr = th.App.importUser(th.Context, &data, false) require.NotNil(t, appErr, "Should have failed to import invalid user.") @@ -886,22 +886,22 @@ func TestImportImportUser(t *testing.T) { appErr = th.App.importUser(th.Context, &data, false) require.Nil(t, appErr, "Should have succeeded to update valid user %v", err) - data.Password = ptrStr("") + data.Password = model.NewPointer("") appErr = th.App.importUser(th.Context, &data, false) require.NotNil(t, appErr, "Should have failed to import invalid user.") - data.Password = ptrStr(strings.Repeat("0123456789", 10)) + data.Password = model.NewPointer(strings.Repeat("0123456789", 10)) appErr = th.App.importUser(th.Context, &data, false) require.NotNil(t, appErr, "Should have failed to import invalid user.") - data.Password = ptrStr("TestPassword") + data.Password = model.NewPointer("TestPassword") // Test team and channel memberships teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, appErr := th.App.GetTeamByName(teamName) require.Nil(t, appErr, "Failed to get team from database.") @@ -911,7 +911,7 @@ func TestImportImportUser(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) channel, appErr := th.App.GetChannelByName(th.Context, channelName, team.Id, false) @@ -920,11 +920,11 @@ func TestImportImportUser(t *testing.T) { username = model.NewUsername() data = imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), - Nickname: ptrStr(model.NewId()), - FirstName: ptrStr(model.NewId()), - LastName: ptrStr(model.NewId()), - Position: ptrStr(model.NewId()), + Email: model.NewPointer(model.NewId() + "@example.com"), + Nickname: model.NewPointer(model.NewId()), + FirstName: model.NewPointer(model.NewId()), + LastName: model.NewPointer(model.NewId()), + Position: model.NewPointer(model.NewId()), } teamMembers, appErr := th.App.GetTeamMembers(team.Id, 0, 1000, nil) @@ -937,10 +937,10 @@ func TestImportImportUser(t *testing.T) { // Test with an invalid team & channel membership in dry-run mode. data.Teams = &[]imports.UserTeamImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -951,10 +951,10 @@ func TestImportImportUser(t *testing.T) { // Test with an unknown team name & invalid channel membership in dry-run mode. data.Teams = &[]imports.UserTeamImportData{ { - Name: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -968,7 +968,7 @@ func TestImportImportUser(t *testing.T) { Name: &teamName, Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -982,7 +982,7 @@ func TestImportImportUser(t *testing.T) { Name: &teamName, Channels: &[]imports.UserChannelImportData{ { - Name: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), }, }, }, @@ -1016,10 +1016,10 @@ func TestImportImportUser(t *testing.T) { // Test with an invalid team & channel membership in apply mode. data.Teams = &[]imports.UserTeamImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -1030,10 +1030,10 @@ func TestImportImportUser(t *testing.T) { // Test with an unknown team name & invalid channel membership in apply mode. data.Teams = &[]imports.UserTeamImportData{ { - Name: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -1047,7 +1047,7 @@ func TestImportImportUser(t *testing.T) { Name: &teamName, Channels: &[]imports.UserChannelImportData{ { - Roles: ptrStr("invalid"), + Roles: model.NewPointer("invalid"), }, }, }, @@ -1070,7 +1070,7 @@ func TestImportImportUser(t *testing.T) { Name: &teamName, Channels: &[]imports.UserChannelImportData{ { - Name: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), }, }, }, @@ -1130,18 +1130,18 @@ func TestImportImportUser(t *testing.T) { data.Teams = &[]imports.UserTeamImportData{ { Name: &teamName, - Theme: ptrStr(`{"awayIndicator":"#DBBD4E","buttonBg":"#23A1FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), - Roles: ptrStr("team_user team_admin"), + Theme: model.NewPointer(`{"awayIndicator":"#DBBD4E","buttonBg":"#23A1FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), + Roles: model.NewPointer("team_user team_admin"), Channels: &[]imports.UserChannelImportData{ { Name: &channelName, - Roles: ptrStr("channel_user channel_admin"), + Roles: model.NewPointer("channel_user channel_admin"), NotifyProps: &imports.UserChannelNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyMention), - Mobile: ptrStr(model.UserNotifyMention), - MarkUnread: ptrStr(model.UserNotifyMention), + Desktop: model.NewPointer(model.UserNotifyMention), + Mobile: model.NewPointer(model.UserNotifyMention), + MarkUnread: model.NewPointer(model.UserNotifyMention), }, - Favorite: ptrBool(true), + Favorite: model.NewPointer(true), }, }, }, @@ -1177,18 +1177,18 @@ func TestImportImportUser(t *testing.T) { username = model.NewUsername() data = imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), - Theme: ptrStr(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), - UseMilitaryTime: ptrStr("true"), - CollapsePreviews: ptrStr("true"), - MessageDisplay: ptrStr("compact"), - ColorizeUsernames: ptrStr("true"), - ChannelDisplayMode: ptrStr("centered"), - TutorialStep: ptrStr("3"), - UseMarkdownPreview: ptrStr("true"), - UseFormatting: ptrStr("true"), - ShowUnreadSection: ptrStr("true"), - EmailInterval: ptrStr("immediately"), + Email: model.NewPointer(model.NewId() + "@example.com"), + Theme: model.NewPointer(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), + UseMilitaryTime: model.NewPointer("true"), + CollapsePreviews: model.NewPointer("true"), + MessageDisplay: model.NewPointer("compact"), + ColorizeUsernames: model.NewPointer("true"), + ChannelDisplayMode: model.NewPointer("centered"), + TutorialStep: model.NewPointer("3"), + UseMarkdownPreview: model.NewPointer("true"), + UseFormatting: model.NewPointer("true"), + ShowUnreadSection: model.NewPointer("true"), + EmailInterval: model.NewPointer("immediately"), NameFormat: model.NewPointer("full_name"), SendOnCtrlEnter: model.NewPointer("true"), CodeBlockCtrlEnter: model.NewPointer("true"), @@ -1225,15 +1225,15 @@ func TestImportImportUser(t *testing.T) { // Change those preferences. data = imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), - Theme: ptrStr(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), - UseMilitaryTime: ptrStr("false"), - CollapsePreviews: ptrStr("false"), - MessageDisplay: ptrStr("clean"), - ColorizeUsernames: ptrStr("false"), - ChannelDisplayMode: ptrStr("full"), - TutorialStep: ptrStr("2"), - EmailInterval: ptrStr("hour"), + Email: model.NewPointer(model.NewId() + "@example.com"), + Theme: model.NewPointer(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBg":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`), + UseMilitaryTime: model.NewPointer("false"), + CollapsePreviews: model.NewPointer("false"), + MessageDisplay: model.NewPointer("clean"), + ColorizeUsernames: model.NewPointer("false"), + ChannelDisplayMode: model.NewPointer("full"), + TutorialStep: model.NewPointer("2"), + EmailInterval: model.NewPointer("hour"), } appErr = th.App.importUser(th.Context, &data, false) assert.Nil(t, appErr) @@ -1250,13 +1250,13 @@ func TestImportImportUser(t *testing.T) { // Set Notify Without mention keys data.NotifyProps = &imports.UserNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyAll), - DesktopSound: ptrStr("true"), - Email: ptrStr("true"), - Mobile: ptrStr(model.UserNotifyAll), - MobilePushStatus: ptrStr(model.StatusOnline), - ChannelTrigger: ptrStr("true"), - CommentsTrigger: ptrStr(model.CommentsNotifyRoot), + Desktop: model.NewPointer(model.UserNotifyAll), + DesktopSound: model.NewPointer("true"), + Email: model.NewPointer("true"), + Mobile: model.NewPointer(model.UserNotifyAll), + MobilePushStatus: model.NewPointer(model.StatusOnline), + ChannelTrigger: model.NewPointer("true"), + CommentsTrigger: model.NewPointer(model.CommentsNotifyRoot), } appErr = th.App.importUser(th.Context, &data, false) assert.Nil(t, appErr) @@ -1275,14 +1275,14 @@ func TestImportImportUser(t *testing.T) { // Set Notify Props with Mention keys data.NotifyProps = &imports.UserNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyAll), - DesktopSound: ptrStr("true"), - Email: ptrStr("true"), - Mobile: ptrStr(model.UserNotifyAll), - MobilePushStatus: ptrStr(model.StatusOnline), - ChannelTrigger: ptrStr("true"), - CommentsTrigger: ptrStr(model.CommentsNotifyRoot), - MentionKeys: ptrStr("valid,misc"), + Desktop: model.NewPointer(model.UserNotifyAll), + DesktopSound: model.NewPointer("true"), + Email: model.NewPointer("true"), + Mobile: model.NewPointer(model.UserNotifyAll), + MobilePushStatus: model.NewPointer(model.StatusOnline), + ChannelTrigger: model.NewPointer("true"), + CommentsTrigger: model.NewPointer(model.CommentsNotifyRoot), + MentionKeys: model.NewPointer("valid,misc"), } appErr = th.App.importUser(th.Context, &data, false) assert.Nil(t, appErr) @@ -1301,14 +1301,14 @@ func TestImportImportUser(t *testing.T) { // Change Notify Props with mention keys data.NotifyProps = &imports.UserNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyMention), - DesktopSound: ptrStr("false"), - Email: ptrStr("false"), - Mobile: ptrStr(model.UserNotifyNone), - MobilePushStatus: ptrStr(model.StatusAway), - ChannelTrigger: ptrStr("false"), - CommentsTrigger: ptrStr(model.CommentsNotifyAny), - MentionKeys: ptrStr("misc"), + Desktop: model.NewPointer(model.UserNotifyMention), + DesktopSound: model.NewPointer("false"), + Email: model.NewPointer("false"), + Mobile: model.NewPointer(model.UserNotifyNone), + MobilePushStatus: model.NewPointer(model.StatusAway), + ChannelTrigger: model.NewPointer("false"), + CommentsTrigger: model.NewPointer(model.CommentsNotifyAny), + MentionKeys: model.NewPointer("misc"), } appErr = th.App.importUser(th.Context, &data, false) assert.Nil(t, appErr) @@ -1327,13 +1327,13 @@ func TestImportImportUser(t *testing.T) { // Change Notify Props without mention keys data.NotifyProps = &imports.UserNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyMention), - DesktopSound: ptrStr("false"), - Email: ptrStr("false"), - Mobile: ptrStr(model.UserNotifyNone), - MobilePushStatus: ptrStr(model.StatusAway), - ChannelTrigger: ptrStr("false"), - CommentsTrigger: ptrStr(model.CommentsNotifyAny), + Desktop: model.NewPointer(model.UserNotifyMention), + DesktopSound: model.NewPointer("false"), + Email: model.NewPointer("false"), + Mobile: model.NewPointer(model.UserNotifyNone), + MobilePushStatus: model.NewPointer(model.StatusAway), + ChannelTrigger: model.NewPointer("false"), + CommentsTrigger: model.NewPointer(model.CommentsNotifyAny), } appErr = th.App.importUser(th.Context, &data, false) assert.Nil(t, appErr) @@ -1354,17 +1354,17 @@ func TestImportImportUser(t *testing.T) { username = model.NewUsername() data = imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), } data.NotifyProps = &imports.UserNotifyPropsImportData{ - Desktop: ptrStr(model.UserNotifyMention), - DesktopSound: ptrStr("false"), - Email: ptrStr("false"), - Mobile: ptrStr(model.UserNotifyNone), - MobilePushStatus: ptrStr(model.StatusAway), - ChannelTrigger: ptrStr("false"), - CommentsTrigger: ptrStr(model.CommentsNotifyAny), - MentionKeys: ptrStr("misc"), + Desktop: model.NewPointer(model.UserNotifyMention), + DesktopSound: model.NewPointer("false"), + Email: model.NewPointer("false"), + Mobile: model.NewPointer(model.UserNotifyNone), + MobilePushStatus: model.NewPointer(model.StatusAway), + ChannelTrigger: model.NewPointer("false"), + CommentsTrigger: model.NewPointer(model.CommentsNotifyAny), + MentionKeys: model.NewPointer("misc"), } appErr = th.App.importUser(th.Context, &data, false) @@ -1394,34 +1394,34 @@ func TestImportImportUser(t *testing.T) { }() teamSchemeData := &imports.SchemeImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), - Scope: ptrStr("team"), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), + Scope: model.NewPointer("team"), DefaultTeamGuestRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultTeamUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultTeamAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelGuestRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelUserRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, DefaultChannelAdminRole: &imports.RoleImportData{ - Name: ptrStr(model.NewId()), - DisplayName: ptrStr(model.NewId()), + Name: model.NewPointer(model.NewId()), + DisplayName: model.NewPointer(model.NewId()), }, - Description: ptrStr("description"), + Description: model.NewPointer("description"), } appErr = th.App.importScheme(th.Context, teamSchemeData, false) @@ -1431,11 +1431,11 @@ func TestImportImportUser(t *testing.T) { require.NoError(t, nErr, "Failed to import scheme") teamData := &imports.TeamImportData{ - Name: ptrStr(NewTestId()), - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), - Description: ptrStr("The team description."), - AllowOpenInvite: ptrBool(true), + Name: model.NewPointer(NewTestId()), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), + Description: model.NewPointer("The team description."), + AllowOpenInvite: model.NewPointer(true), Scheme: &teamScheme.Name, } appErr = th.App.importTeam(th.Context, teamData, false) @@ -1445,11 +1445,11 @@ func TestImportImportUser(t *testing.T) { channelData := &imports.ChannelImportData{ Team: &teamName, - Name: ptrStr(NewTestId()), - DisplayName: ptrStr("Display Name"), + Name: model.NewPointer(NewTestId()), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, - Header: ptrStr("Channel Header"), - Purpose: ptrStr("Channel Purpose"), + Header: model.NewPointer("Channel Header"), + Purpose: model.NewPointer("Channel Purpose"), } appErr = th.App.importChannel(th.Context, channelData, false) assert.Nil(t, appErr) @@ -1459,15 +1459,15 @@ func TestImportImportUser(t *testing.T) { // Test with a valid team & valid channel name in apply mode. userData := &imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), Teams: &[]imports.UserTeamImportData{ { Name: &team.Name, - Roles: ptrStr("team_user team_admin"), + Roles: model.NewPointer("team_user team_admin"), Channels: &[]imports.UserChannelImportData{ { Name: &channel.Name, - Roles: ptrStr("channel_admin channel_user"), + Roles: model.NewPointer("channel_admin channel_user"), }, }, }, @@ -1501,15 +1501,15 @@ func TestImportImportUser(t *testing.T) { deletedUserData := &imports.UserImportData{ Username: &username, DeleteAt: &deleteAt, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), Teams: &[]imports.UserTeamImportData{ { Name: &team.Name, - Roles: ptrStr("team_user"), + Roles: model.NewPointer("team_user"), Channels: &[]imports.UserChannelImportData{ { Name: &channel.Name, - Roles: ptrStr("channel_user"), + Roles: model.NewPointer("channel_user"), }, }, }, @@ -1544,15 +1544,15 @@ func TestImportImportUser(t *testing.T) { // deletedGuestData := &imports.UserImportData{ // Username: &username, // DeleteAt: &deleteAt, - // Email: ptrStr(model.NewId() + "@example.com"), + // Email: model.NewPointer(model.NewId() + "@example.com"), // Teams: &[]imports.UserTeamImportData{ // { // Name: &team.Name, - // Roles: ptrStr("team_guest"), + // Roles: model.NewPointer("team_guest"), // Channels: &[]imports.UserChannelImportData{ // { // Name: &channel.Name, - // Roles: ptrStr("channel_guest"), + // Roles: model.NewPointer("channel_guest"), // }, // }, // }, @@ -1692,7 +1692,7 @@ func TestImportUserTeams(t *testing.T) { Name: &th.BasicTeam.Name, Channels: &[]imports.UserChannelImportData{ { - Name: ptrStr(model.DefaultChannelName), + Name: model.NewPointer(model.DefaultChannelName), }, }, }, @@ -1945,10 +1945,10 @@ func TestImportUserDefaultNotifyProps(t *testing.T) { username := model.NewUsername() data := imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), NotifyProps: &imports.UserNotifyPropsImportData{ - Email: ptrStr("false"), - MentionKeys: ptrStr(""), + Email: model.NewPointer("false"), + MentionKeys: model.NewPointer(""), }, } require.Nil(t, th.App.importUser(th.Context, &data, false)) @@ -1984,8 +1984,8 @@ func TestImportimportMultiplePostLines(t *testing.T) { teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, err := th.App.GetTeamByName(teamName) require.Nil(t, err, "Failed to get team from database.") @@ -1996,7 +1996,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) channel, err := th.App.GetChannelByName(th.Context, channelName, team.Id, false) @@ -2006,7 +2006,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { username := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user, err := th.App.GetUserByUsername(username) require.Nil(t, err, "Failed to get user from database.") @@ -2038,8 +2038,8 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Hello"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -2056,7 +2056,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - CreateAt: ptrInt64(model.GetMillis()), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 35, @@ -2070,11 +2070,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { data = imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ Post: &imports.PostImportData{ - Team: ptrStr(NewTestId()), + Team: model.NewPointer(NewTestId()), Channel: &channelName, User: &username, - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 10, @@ -2091,10 +2091,10 @@ func TestImportimportMultiplePostLines(t *testing.T) { LineImportData: imports.LineImportData{ Post: &imports.PostImportData{ Team: &teamName, - Channel: ptrStr(NewTestId()), + Channel: model.NewPointer(NewTestId()), User: &username, - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 7, @@ -2112,9 +2112,9 @@ func TestImportimportMultiplePostLines(t *testing.T) { Post: &imports.PostImportData{ Team: &teamName, Channel: &channelName, - User: ptrStr(model.NewId()), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(model.NewId()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 2, @@ -2134,7 +2134,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &createAt, }, }, @@ -2162,7 +2162,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &createAt, }, }, @@ -2191,7 +2191,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &newTime, }, }, @@ -2209,7 +2209,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message 2"), + Message: model.NewPointer("Message 2"), CreateAt: &createAt, }, }, @@ -2228,7 +2228,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message 2 #hashtagmashupcity"), + Message: model.NewPointer("Message 2 #hashtagmashupcity"), CreateAt: &hashtagTime, }, }, @@ -2254,7 +2254,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { username2 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username2, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user2, err := th.App.GetUserByUsername(username2) require.Nil(t, err, "Failed to get user from database.") @@ -2266,7 +2266,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with Favorites"), + Message: model.NewPointer("Message with Favorites"), CreateAt: &flagsTime, FlaggedBy: &[]string{ username, @@ -2305,11 +2305,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with reaction"), + Message: model.NewPointer("Message with reaction"), CreateAt: &reactionPostTime, Reactions: &[]imports.ReactionImportData{{ User: &user2.Username, - EmojiName: ptrStr("+1"), + EmojiName: model.NewPointer("+1"), CreateAt: &reactionTime, }}, }, @@ -2346,11 +2346,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &user2.Username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -2392,11 +2392,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -2416,11 +2416,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply 2"), + Message: model.NewPointer("Message with reply 2"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -2440,11 +2440,11 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply 2"), + Message: model.NewPointer("Message reply 2"), CreateAt: &replyTime, }}, }, @@ -2470,12 +2470,12 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &editedReplyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Type: ptrStr(model.PostTypeSystemGeneric), - Message: ptrStr("Message reply 3"), + Type: model.NewPointer(model.PostTypeSystemGeneric), + Message: model.NewPointer("Message reply 3"), CreateAt: &editedReplyTime, EditAt: &editedReplyEditTime, }}, @@ -2501,8 +2501,8 @@ func TestImportimportMultiplePostLines(t *testing.T) { teamName2 := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName2, - DisplayName: ptrStr("Display Name 2"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name 2"), + Type: model.NewPointer("O"), }, false) team2, err := th.App.GetTeamByName(teamName2) require.Nil(t, err, "Failed to get team from database.") @@ -2511,7 +2511,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName2, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) _, err = th.App.GetChannelByName(th.Context, channelName, team2.Id, false) @@ -2528,7 +2528,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("another message"), + Message: model.NewPointer("another message"), CreateAt: &createAt, }, }, @@ -2540,7 +2540,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName2, Channel: &channelName, User: &username, - Message: ptrStr("another message"), + Message: model.NewPointer("another message"), CreateAt: &createAt, }, }, @@ -2557,9 +2557,9 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Pinned Message"), - CreateAt: ptrInt64(model.GetMillis()), - IsPinned: ptrBool(true), + Message: model.NewPointer("Pinned Message"), + CreateAt: model.NewPointer(model.GetMillis()), + IsPinned: model.NewPointer(true), }, }, LineNumber: 1, @@ -2626,19 +2626,19 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user.Username, - Message: ptrStr("Thread Message"), - CreateAt: ptrInt64(importCreate), + Message: model.NewPointer("Thread Message"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ User: &user.Username, - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ User: &user.Username, - LastViewed: ptrInt64(model.GetMillis()), + LastViewed: model.NewPointer(model.GetMillis()), }, { User: &user2.Username, - LastViewed: ptrInt64(model.GetMillis()), + LastViewed: model.NewPointer(model.GetMillis()), }}, }, }, @@ -2668,18 +2668,18 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user.Username, - Message: ptrStr("Thread Message"), - CreateAt: ptrInt64(importCreate), + Message: model.NewPointer("Thread Message"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ User: &user.Username, - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ User: &user.Username, - LastViewed: ptrInt64(model.GetMillis()), + LastViewed: model.NewPointer(model.GetMillis()), }, { - User: ptrStr("invalid.user"), + User: model.NewPointer("invalid.user"), }}, }, }, @@ -2699,18 +2699,18 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user.Username, - Message: ptrStr("Thread Message"), - CreateAt: ptrInt64(importCreate), + Message: model.NewPointer("Thread Message"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ User: &user.Username, - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ User: &user.Username, - LastViewed: ptrInt64(model.GetMillis()), + LastViewed: model.NewPointer(model.GetMillis()), }, { - User: ptrStr("invalid.user"), + User: model.NewPointer("invalid.user"), }}, }, }, @@ -2730,8 +2730,8 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Hello"), - CreateAt: ptrInt64(importCreate), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(importCreate), }, }, LineNumber: 1, @@ -2751,16 +2751,16 @@ func TestImportimportMultiplePostLines(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user.Username, - Message: ptrStr("Hello"), - CreateAt: ptrInt64(importCreate), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ User: &user.Username, - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ User: &user.Username, - LastViewed: ptrInt64(model.GetMillis()), + LastViewed: model.NewPointer(model.GetMillis()), }}, }, }, @@ -2856,8 +2856,8 @@ func TestImportImportPost(t *testing.T) { teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, appErr := th.App.GetTeamByName(teamName) require.Nil(t, appErr, "Failed to get team from database.") @@ -2868,7 +2868,7 @@ func TestImportImportPost(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) channel, appErr := th.App.GetChannelByName(th.Context, channelName, team.Id, false) @@ -2878,7 +2878,7 @@ func TestImportImportPost(t *testing.T) { username := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user, appErr := th.App.GetUserByUsername(username) require.Nil(t, appErr, "Failed to get user from database.") @@ -2886,7 +2886,7 @@ func TestImportImportPost(t *testing.T) { username2 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username2, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user2, appErr := th.App.GetUserByUsername(username2) require.Nil(t, appErr, "Failed to get user from database.") @@ -2927,8 +2927,8 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Hello"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -2946,7 +2946,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - CreateAt: ptrInt64(model.GetMillis()), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 2, @@ -2961,11 +2961,11 @@ func TestImportImportPost(t *testing.T) { data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ Post: &imports.PostImportData{ - Team: ptrStr(NewTestId()), + Team: model.NewPointer(NewTestId()), Channel: &channelName, User: &username, - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 7, @@ -2981,10 +2981,10 @@ func TestImportImportPost(t *testing.T) { LineImportData: imports.LineImportData{ Post: &imports.PostImportData{ Team: &teamName, - Channel: ptrStr(NewTestId()), + Channel: model.NewPointer(NewTestId()), User: &username, - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 8, @@ -3001,9 +3001,9 @@ func TestImportImportPost(t *testing.T) { Post: &imports.PostImportData{ Team: &teamName, Channel: &channelName, - User: ptrStr(model.NewId()), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(model.NewId()), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 9, @@ -3021,7 +3021,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &time, }, }, @@ -3050,7 +3050,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username2, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &time, }, }, @@ -3080,7 +3080,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message"), + Message: model.NewPointer("Message"), CreateAt: &newTime, }, }, @@ -3099,7 +3099,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message 2"), + Message: model.NewPointer("Message 2"), CreateAt: &time, }, }, @@ -3118,7 +3118,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message 2 #hashtagmashupcity"), + Message: model.NewPointer("Message 2 #hashtagmashupcity"), CreateAt: &hashtagTime, }, }, @@ -3149,7 +3149,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with Favorites"), + Message: model.NewPointer("Message with Favorites"), CreateAt: &flagsTime, FlaggedBy: &[]string{ username, @@ -3189,11 +3189,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with reaction"), + Message: model.NewPointer("Message with reaction"), CreateAt: &reactionPostTime, Reactions: &[]imports.ReactionImportData{{ User: &user2.Username, - EmojiName: ptrStr("+1"), + EmojiName: model.NewPointer("+1"), CreateAt: &reactionTime, }}, }, @@ -3229,11 +3229,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &user2.Username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -3276,11 +3276,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -3301,11 +3301,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply 2"), + Message: model.NewPointer("Message with reply 2"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &replyTime, }}, }, @@ -3326,11 +3326,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &replyPostTime, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply 2"), + Message: model.NewPointer("Message reply 2"), CreateAt: &replyTime, }}, }, @@ -3351,8 +3351,8 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Type: ptrStr(model.PostTypeSystemGeneric), - Message: ptrStr("Message with Type"), + Type: model.NewPointer(model.PostTypeSystemGeneric), + Message: model.NewPointer("Message with Type"), CreateAt: &posttypeTime, }, }, @@ -3383,7 +3383,7 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username, - Message: ptrStr("Message with Type"), + Message: model.NewPointer("Message with Type"), CreateAt: &editatCreateTime, EditAt: &editatEditTime, }, @@ -3417,11 +3417,11 @@ func TestImportImportPost(t *testing.T) { Team: &teamName, Channel: &channelName, User: &user2.Username, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &now, Replies: &[]imports.ReplyImportData{{ User: &username, - Message: ptrStr("Message reply 2"), + Message: model.NewPointer("Message reply 2"), CreateAt: &before, }}, }, @@ -3484,7 +3484,7 @@ func TestImportImportDirectChannel(t *testing.T) { Username: model.NewPointer(model.NewId()), }, }, - Header: ptrStr("Channel Header"), + Header: model.NewPointer("Channel Header"), }) for name, data := range dataset { t.Run(name, func(t *testing.T) { @@ -3596,7 +3596,7 @@ func TestImportImportDirectChannel(t *testing.T) { AssertChannelCount(t, th.App, model.ChannelTypeGroup, groupChannelCount) // Update the channel's HEADER - data.Header = ptrStr("New Channel Header 2") + data.Header = model.NewPointer("New Channel Header 2") appErr = th.App.importDirectChannel(th.Context, &data, false) require.Nil(t, appErr) @@ -3673,7 +3673,7 @@ func TestImportImportDirectChannel(t *testing.T) { AssertChannelCount(t, th.App, model.ChannelTypeGroup, groupChannelCount+1) // Update the channel's HEADER - data.Header = ptrStr("New Channel Header 3") + data.Header = model.NewPointer("New Channel Header 3") appErr = th.App.importDirectChannel(th.Context, &data, false) require.Nil(t, appErr) @@ -3728,7 +3728,7 @@ func TestImportImportDirectChannel(t *testing.T) { Participants: []*imports.DirectChannelMemberImportData{ { Username: model.NewPointer(th.BasicUser.Username), - LastViewedAt: ptrInt64(lastView), + LastViewedAt: model.NewPointer(lastView), }, { Username: model.NewPointer(th.BasicUser2.Username), @@ -3863,8 +3863,8 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 7, @@ -3883,9 +3883,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -3904,9 +3904,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, model.NewId(), }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 9, @@ -3925,9 +3925,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate), }, }, LineNumber: 1, @@ -3956,9 +3956,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate), }, }, LineNumber: 1, @@ -3987,9 +3987,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate + 1), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate + 1), }, }, LineNumber: 1, @@ -4008,9 +4008,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message 2"), - CreateAt: ptrInt64(initialDate + 1), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message 2"), + CreateAt: model.NewPointer(initialDate + 1), }, }, LineNumber: 1, @@ -4029,9 +4029,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message 2 #hashtagmashupcity"), - CreateAt: ptrInt64(initialDate + 2), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message 2 #hashtagmashupcity"), + CreateAt: model.NewPointer(initialDate + 2), }, }, LineNumber: 1, @@ -4064,9 +4064,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -4095,10 +4095,10 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Type: ptrStr(model.PostTypeSystemGeneric), - Message: ptrStr("Message with Type"), - CreateAt: ptrInt64(posttypeDate), + User: model.NewPointer(th.BasicUser.Username), + Type: model.NewPointer(model.PostTypeSystemGeneric), + Message: model.NewPointer("Message with Type"), + CreateAt: model.NewPointer(posttypeDate), }, }, LineNumber: 1, @@ -4127,10 +4127,10 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message with EditAt"), - CreateAt: ptrInt64(editatCreateDate), - EditAt: ptrInt64(editatEditDate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message with EditAt"), + CreateAt: model.NewPointer(editatCreateDate), + EditAt: model.NewPointer(editatEditDate), }, }, LineNumber: 1, @@ -4161,8 +4161,8 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message with EditAt"), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message with EditAt"), CreateAt: &creationTime, IsPinned: &pinnedValue, }, @@ -4192,20 +4192,20 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Thread Message"), - CreateAt: ptrInt64(importCreate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Thread Message"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ - User: ptrStr(th.BasicUser.Username), - LastViewed: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + LastViewed: model.NewPointer(model.GetMillis()), }, { - User: ptrStr(th.BasicUser2.Username), - LastViewed: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser2.Username), + LastViewed: model.NewPointer(model.GetMillis()), }}, }, }, @@ -4235,9 +4235,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Hello"), - CreateAt: ptrInt64(importCreate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(importCreate), }, }, LineNumber: 1, @@ -4258,17 +4258,17 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Hello"), - CreateAt: ptrInt64(importCreate), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Hello"), + CreateAt: model.NewPointer(importCreate), Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Reply"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Reply"), + CreateAt: model.NewPointer(model.GetMillis()), }}, ThreadFollowers: &[]imports.ThreadFollowerImportData{{ - User: ptrStr(th.BasicUser.Username), - LastViewed: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + LastViewed: model.NewPointer(model.GetMillis()), }}, }, }, @@ -4330,8 +4330,8 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 4, @@ -4351,9 +4351,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -4374,9 +4374,9 @@ func TestImportImportDirectPost(t *testing.T) { user3.Username, model.NewId(), }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 8, @@ -4396,9 +4396,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate + 10), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate + 10), }, }, LineNumber: 1, @@ -4428,9 +4428,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate + 10), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate + 10), }, }, LineNumber: 1, @@ -4460,9 +4460,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(initialDate + 11), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(initialDate + 11), }, }, LineNumber: 1, @@ -4482,9 +4482,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message 2"), - CreateAt: ptrInt64(initialDate + 11), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message 2"), + CreateAt: model.NewPointer(initialDate + 11), }, }, LineNumber: 1, @@ -4504,9 +4504,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message 2 #hashtagmashupcity"), - CreateAt: ptrInt64(initialDate + 12), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message 2 #hashtagmashupcity"), + CreateAt: model.NewPointer(initialDate + 12), }, }, LineNumber: 1, @@ -4540,9 +4540,9 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser.Username, th.BasicUser2.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message"), - CreateAt: ptrInt64(model.GetMillis()), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message"), + CreateAt: model.NewPointer(model.GetMillis()), }, }, LineNumber: 1, @@ -4565,8 +4565,8 @@ func TestImportImportDirectPost(t *testing.T) { }) t.Run("Post with reaction", func(t *testing.T) { - reactionPostTime := ptrInt64(initialDate + 22) - reactionTime := ptrInt64(initialDate + 23) + reactionPostTime := model.NewPointer(initialDate + 22) + reactionTime := model.NewPointer(initialDate + 23) data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ DirectPost: &imports.DirectPostImportData{ @@ -4575,12 +4575,12 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message with reaction"), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message with reaction"), CreateAt: reactionPostTime, Reactions: &[]imports.ReactionImportData{{ - User: ptrStr(th.BasicUser2.Username), - EmojiName: ptrStr("+1"), + User: model.NewPointer(th.BasicUser2.Username), + EmojiName: model.NewPointer("+1"), CreateAt: reactionTime, }}, }, @@ -4610,8 +4610,8 @@ func TestImportImportDirectPost(t *testing.T) { }) t.Run("Post with reply", func(t *testing.T) { - replyPostTime := ptrInt64(initialDate + 25) - replyTime := ptrInt64(initialDate + 26) + replyPostTime := model.NewPointer(initialDate + 25) + replyTime := model.NewPointer(initialDate + 26) data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ DirectPost: &imports.DirectPostImportData{ @@ -4620,12 +4620,12 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message with reply"), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message with reply"), CreateAt: replyPostTime, Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser2.Username), - Message: ptrStr("Message reply"), + User: model.NewPointer(th.BasicUser2.Username), + Message: model.NewPointer("Message reply"), CreateAt: replyTime, }}, }, @@ -4662,8 +4662,8 @@ func TestImportImportDirectPost(t *testing.T) { }) t.Run("Update post with replies", func(t *testing.T) { - replyPostTime := ptrInt64(initialDate + 25) - replyTime := ptrInt64(initialDate + 26) + replyPostTime := model.NewPointer(initialDate + 25) + replyTime := model.NewPointer(initialDate + 26) data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ DirectPost: &imports.DirectPostImportData{ @@ -4672,12 +4672,12 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser2.Username), - Message: ptrStr("Message with reply"), + User: model.NewPointer(th.BasicUser2.Username), + Message: model.NewPointer("Message with reply"), CreateAt: replyPostTime, Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message reply"), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message reply"), CreateAt: replyTime, }}, }, @@ -4692,8 +4692,8 @@ func TestImportImportDirectPost(t *testing.T) { }) t.Run("Create new post with replies based on the previous one", func(t *testing.T) { - replyPostTime := ptrInt64(initialDate + 27) - replyTime := ptrInt64(initialDate + 28) + replyPostTime := model.NewPointer(initialDate + 27) + replyTime := model.NewPointer(initialDate + 28) data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ DirectPost: &imports.DirectPostImportData{ @@ -4702,12 +4702,12 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser2.Username), - Message: ptrStr("Message with reply 2"), + User: model.NewPointer(th.BasicUser2.Username), + Message: model.NewPointer("Message with reply 2"), CreateAt: replyPostTime, Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser.Username), - Message: ptrStr("Message reply"), + User: model.NewPointer(th.BasicUser.Username), + Message: model.NewPointer("Message reply"), CreateAt: replyTime, }}, }, @@ -4722,9 +4722,9 @@ func TestImportImportDirectPost(t *testing.T) { }) t.Run("Post with reply having non-empty type and edit_at", func(t *testing.T) { - replyPostTime := ptrInt64(initialDate + 29) - replyTime := ptrInt64(initialDate + 30) - replyEditTime := ptrInt64(initialDate + 31) + replyPostTime := model.NewPointer(initialDate + 29) + replyTime := model.NewPointer(initialDate + 30) + replyEditTime := model.NewPointer(initialDate + 31) data := imports.LineImportWorkerData{ LineImportData: imports.LineImportData{ DirectPost: &imports.DirectPostImportData{ @@ -4733,13 +4733,13 @@ func TestImportImportDirectPost(t *testing.T) { th.BasicUser2.Username, user3.Username, }, - User: ptrStr(th.BasicUser2.Username), - Message: ptrStr("Message with reply"), + User: model.NewPointer(th.BasicUser2.Username), + Message: model.NewPointer("Message with reply"), CreateAt: replyPostTime, Replies: &[]imports.ReplyImportData{{ - User: ptrStr(th.BasicUser.Username), - Type: ptrStr(model.PostTypeSystemGeneric), - Message: ptrStr("Message reply 2"), + User: model.NewPointer(th.BasicUser.Username), + Type: model.NewPointer(model.PostTypeSystemGeneric), + Message: model.NewPointer("Message reply 2"), CreateAt: replyTime, EditAt: replyEditTime, }}, @@ -4775,7 +4775,7 @@ func TestImportImportEmoji(t *testing.T) { testsDir, _ := fileutils.FindDir("tests") testImage := filepath.Join(testsDir, "test.png") - data := imports.EmojiImportData{Name: ptrStr(model.NewId())} + data := imports.EmojiImportData{Name: model.NewPointer(model.NewId())} appErr := th.App.importEmoji(th.Context, &data, true) assert.NotNil(t, appErr, "Invalid emoji should have failed dry run") @@ -4783,19 +4783,19 @@ func TestImportImportEmoji(t *testing.T) { assert.Nil(t, emoji, "Emoji should not have been imported") assert.Error(t, nErr) - data.Image = ptrStr(testImage) + data.Image = model.NewPointer(testImage) appErr = th.App.importEmoji(th.Context, &data, true) assert.Nil(t, appErr, "Valid emoji should have passed dry run") - data = imports.EmojiImportData{Name: ptrStr(model.NewId())} + data = imports.EmojiImportData{Name: model.NewPointer(model.NewId())} appErr = th.App.importEmoji(th.Context, &data, false) assert.NotNil(t, appErr, "Invalid emoji should have failed apply mode") - data.Image = ptrStr("non-existent-file") + data.Image = model.NewPointer("non-existent-file") appErr = th.App.importEmoji(th.Context, &data, false) assert.NotNil(t, appErr, "Emoji with bad image file should have failed apply mode") - data.Image = ptrStr(testImage) + data.Image = model.NewPointer(testImage) appErr = th.App.importEmoji(th.Context, &data, false) assert.Nil(t, appErr, "Valid emoji should have succeeded apply mode") @@ -4806,12 +4806,12 @@ func TestImportImportEmoji(t *testing.T) { appErr = th.App.importEmoji(th.Context, &data, false) assert.Nil(t, appErr, "Second run should have succeeded apply mode") - data = imports.EmojiImportData{Name: ptrStr("smiley"), Image: ptrStr(testImage)} + data = imports.EmojiImportData{Name: model.NewPointer("smiley"), Image: model.NewPointer(testImage)} appErr = th.App.importEmoji(th.Context, &data, false) assert.Nil(t, appErr, "System emoji should not fail") largeImage := filepath.Join(testsDir, "large_image_file.jpg") - data = imports.EmojiImportData{Name: ptrStr(model.NewId()), Image: ptrStr(largeImage)} + data = imports.EmojiImportData{Name: model.NewPointer(model.NewId()), Image: model.NewPointer(largeImage)} appErr = th.App.importEmoji(th.Context, &data, false) require.NotNil(t, appErr) require.ErrorIs(t, appErr.Unwrap(), utils.ErrSizeLimitExceeded) @@ -4847,8 +4847,8 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, appErr := th.App.GetTeamByName(teamName) require.Nil(t, appErr, "Failed to get team from database.") @@ -4859,7 +4859,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) _, appErr = th.App.GetChannelByName(th.Context, channelName, team.Id, false) @@ -4869,7 +4869,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { username := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user3, appErr := th.App.GetUserByUsername(username) require.Nil(t, appErr, "Failed to get user3 from database.") @@ -4878,7 +4878,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { username2 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username2, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user2, appErr := th.App.GetUserByUsername(username2) require.Nil(t, appErr, "Failed to get user2 from database.") @@ -4887,7 +4887,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { username3 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username3, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user3, appErr = th.App.GetUserByUsername(username3) require.Nil(t, appErr, "Failed to get user3 from database.") @@ -4895,7 +4895,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { username4 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username4, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user4, appErr := th.App.GetUserByUsername(username4) @@ -4914,12 +4914,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username3, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &attachmentsPostTime, Attachments: &[]imports.AttachmentImportData{{Path: &testImage}, {Path: &testMarkDown}}, Replies: &[]imports.ReplyImportData{{ User: &user4.Username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &attachmentsReplyTime, Attachments: &[]imports.AttachmentImportData{{Path: &testImage}}, }}, @@ -4971,12 +4971,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { user2.Username, }, User: &user3.Username, - Message: ptrStr("Message with Replies"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message with Replies"), + CreateAt: model.NewPointer(model.GetMillis()), Replies: &[]imports.ReplyImportData{{ User: &user2.Username, - Message: ptrStr("Message reply with attachment"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message reply with attachment"), + CreateAt: model.NewPointer(model.GetMillis()), Attachments: &[]imports.AttachmentImportData{{Path: &testImage}}, }}, }, @@ -5093,7 +5093,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) { username := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user1, appErr := th.App.GetUserByUsername(username) require.Nil(t, appErr, "Failed to get user1 from database.") @@ -5101,7 +5101,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) { username2 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username2, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user2, appErr := th.App.GetUserByUsername(username2) @@ -5115,8 +5115,8 @@ func TestImportDirectPostWithAttachments(t *testing.T) { user2.Username, }, User: &user1.Username, - Message: ptrStr("Direct message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Direct message"), + CreateAt: model.NewPointer(model.GetMillis()), Attachments: &[]imports.AttachmentImportData{{Path: &testImage}}, }, }, @@ -5152,8 +5152,8 @@ func TestImportDirectPostWithAttachments(t *testing.T) { user2.Username, }, User: &user1.Username, - Message: ptrStr("Direct message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Direct message"), + CreateAt: model.NewPointer(model.GetMillis()), Attachments: &[]imports.AttachmentImportData{{Path: &testImageFake}}, }, }, @@ -5177,8 +5177,8 @@ func TestImportDirectPostWithAttachments(t *testing.T) { user2.Username, }, User: &user1.Username, - Message: ptrStr("Direct message"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Direct message"), + CreateAt: model.NewPointer(model.GetMillis()), Attachments: &[]imports.AttachmentImportData{{Path: &testImage2}}, }, }, @@ -5202,8 +5202,8 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { teamName := model.NewRandomTeamName() th.App.importTeam(th.Context, &imports.TeamImportData{ Name: &teamName, - DisplayName: ptrStr("Display Name"), - Type: ptrStr("O"), + DisplayName: model.NewPointer("Display Name"), + Type: model.NewPointer("O"), }, false) team, appErr := th.App.GetTeamByName(teamName) require.Nil(t, appErr, "Failed to get team from database.") @@ -5214,7 +5214,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { th.App.importChannel(th.Context, &imports.ChannelImportData{ Team: &teamName, Name: &channelName, - DisplayName: ptrStr("Display Name"), + DisplayName: model.NewPointer("Display Name"), Type: &chanTypeOpen, }, false) _, appErr = th.App.GetChannelByName(th.Context, channelName, team.Id, false) @@ -5224,7 +5224,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { username2 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username2, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user2, appErr := th.App.GetUserByUsername(username2) require.Nil(t, appErr, "Failed to get user2 from database.") @@ -5233,7 +5233,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { username3 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username3, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user3, appErr := th.App.GetUserByUsername(username3) require.Nil(t, appErr, "Failed to get user3 from database.") @@ -5241,7 +5241,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { username4 := model.NewUsername() th.App.importUser(th.Context, &imports.UserImportData{ Username: &username4, - Email: ptrStr(model.NewId() + "@example.com"), + Email: model.NewPointer(model.NewId() + "@example.com"), }, false) user4, appErr := th.App.GetUserByUsername(username4) @@ -5271,12 +5271,12 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { Team: &teamName, Channel: &channelName, User: &username3, - Message: ptrStr("Message with reply"), + Message: model.NewPointer("Message with reply"), CreateAt: &attachmentsPostTime, Attachments: &[]imports.AttachmentImportData{{Path: &testImage}, {Path: &testMarkDown}}, Replies: &[]imports.ReplyImportData{{ User: &user4.Username, - Message: ptrStr("Message reply"), + Message: model.NewPointer("Message reply"), CreateAt: &attachmentsReplyTime, Attachments: &[]imports.AttachmentImportData{{Path: &testImage, Data: imageData}}, }}, @@ -5328,12 +5328,12 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { user2.Username, }, User: &user3.Username, - Message: ptrStr("Message with Replies"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message with Replies"), + CreateAt: model.NewPointer(model.GetMillis()), Replies: &[]imports.ReplyImportData{{ User: &user2.Username, - Message: ptrStr("Message reply with attachment"), - CreateAt: ptrInt64(model.GetMillis()), + Message: model.NewPointer("Message reply with attachment"), + CreateAt: model.NewPointer(model.GetMillis()), Attachments: &[]imports.AttachmentImportData{{Path: &testImage}}, }}, }, diff --git a/server/channels/app/import_test.go b/server/channels/app/import_test.go index 139e37eaa3b..2e0a5a291a3 100644 --- a/server/channels/app/import_test.go +++ b/server/channels/app/import_test.go @@ -23,22 +23,6 @@ import ( "github.com/mattermost/mattermost/server/v8/channels/utils/fileutils" ) -func ptrStr(s string) *string { - return &s -} - -func ptrInt64(i int64) *int64 { - return &i -} - -func ptrInt(i int) *int { - return &i -} - -func ptrBool(b bool) *bool { - return &b -} - func checkPreference(t *testing.T, a *App, userID string, category string, name string, value string) { preferences, err := a.Srv().Store().Preference().GetCategory(userID, category) require.NoErrorf(t, err, "Failed to get preferences for user %v with category %v", userID, category) @@ -250,7 +234,7 @@ func TestImportBulkImport(t *testing.T) { func TestImportProcessImportDataFileVersionLine(t *testing.T) { data := imports.LineImportData{ Type: "version", - Version: ptrInt(1), + Version: model.NewPointer(1), } version, err := processImportDataFileVersionLine(data) require.Nil(t, err, "Expected no error") diff --git a/server/channels/app/post_test.go b/server/channels/app/post_test.go index a44bf7a8257..629624f5337 100644 --- a/server/channels/app/post_test.go +++ b/server/channels/app/post_test.go @@ -2992,7 +2992,7 @@ func TestCollapsedThreadFetch(t *testing.T) { Email: "success+" + id + "@simulator.amazonses.com", Username: "un_" + id, Nickname: "nn_" + id, - AuthData: ptrStr("bobbytables"), + AuthData: model.NewPointer("bobbytables"), AuthService: "saml", EmailVerified: true, }) diff --git a/server/channels/utils/merge_test.go b/server/channels/utils/merge_test.go index 985302326b0..2f241d3bbad 100644 --- a/server/channels/utils/merge_test.go +++ b/server/channels/utils/merge_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/v8/channels/utils" ) @@ -63,9 +64,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]*int patch with different keys and values", func(t *testing.T) { - m1 := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(3)} - m2 := map[string]*int{"this": newInt(2), "is": newInt(3), "a key": newInt(4)} - expected := map[string]*int{"this": newInt(2), "is": newInt(3), "a key": newInt(4)} + m1 := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(3)} + m2 := map[string]*int{"this": newPointer(2), "is": newPointer(3), "a key": newPointer(4)} + expected := map[string]*int{"this": newPointer(2), "is": newPointer(3), "a key": newPointer(4)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -74,9 +75,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]*int patch has nil keys -- doesn't matter, maps overwrite completely", func(t *testing.T) { - m1 := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(3)} - m2 := map[string]*int{"this": newInt(1), "is": nil, "a key": newInt(3)} - expected := map[string]*int{"this": newInt(1), "is": nil, "a key": newInt(3)} + m1 := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(3)} + m2 := map[string]*int{"this": newPointer(1), "is": nil, "a key": newPointer(3)} + expected := map[string]*int{"this": newPointer(1), "is": nil, "a key": newPointer(3)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -85,9 +86,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]*int base has nil vals -- overwrite base with patch", func(t *testing.T) { - m1 := map[string]*int{"this": newInt(1), "is": nil, "base key": newInt(4)} - m2 := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(3)} - expected := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(3)} + m1 := map[string]*int{"this": newPointer(1), "is": nil, "base key": newPointer(4)} + m2 := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(3)} + expected := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(3)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -96,9 +97,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]*int base has nil vals -- but patch is nil, so keep base", func(t *testing.T) { - m1 := map[string]*int{"this": newInt(1), "is": nil, "base key": newInt(4)} + m1 := map[string]*int{"this": newPointer(1), "is": nil, "base key": newPointer(4)} var m2 map[string]*int - expected := map[string]*int{"this": newInt(1), "is": nil, "base key": newInt(4)} + expected := map[string]*int{"this": newPointer(1), "is": nil, "base key": newPointer(4)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -108,9 +109,9 @@ func TestMergeWithMaps(t *testing.T) { t.Run("merge map[string]*int pointers are not copied - change in base do not affect merged", func(t *testing.T) { // that should never happen, since patch overwrites completely - m1 := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(4)} - m2 := map[string]*int{"this": newInt(1), "a key": newInt(5)} - expected := map[string]*int{"this": newInt(1), "a key": newInt(5)} + m1 := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(4)} + m2 := map[string]*int{"this": newPointer(1), "a key": newPointer(5)} + expected := map[string]*int{"this": newPointer(1), "a key": newPointer(5)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -121,9 +122,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]*int pointers are not copied - change in patched do not affect merged", func(t *testing.T) { - m1 := map[string]*int{"this": newInt(1), "is": newInt(3), "a key": newInt(4)} - m2 := map[string]*int{"this": newInt(2), "a key": newInt(5)} - expected := map[string]*int{"this": newInt(2), "a key": newInt(5)} + m1 := map[string]*int{"this": newPointer(1), "is": newPointer(3), "a key": newPointer(4)} + m2 := map[string]*int{"this": newPointer(2), "a key": newPointer(5)} + expected := map[string]*int{"this": newPointer(2), "a key": newPointer(5)} merged, err := mergeStringPtrIntMap(m1, m2) require.NoError(t, err) @@ -204,9 +205,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]map[string]*int", func(t *testing.T) { - m1 := map[string]map[string]*int{"this": {"second": newInt(99)}, "base": {"level": newInt(10)}} - m2 := map[string]map[string]*int{"this": {"second": newInt(77)}, "patch": {"level": newInt(15)}} - expected := map[string]map[string]*int{"this": {"second": newInt(77)}, "patch": {"level": newInt(15)}} + m1 := map[string]map[string]*int{"this": {"second": newPointer(99)}, "base": {"level": newPointer(10)}} + m2 := map[string]map[string]*int{"this": {"second": newPointer(77)}, "patch": {"level": newPointer(15)}} + expected := map[string]map[string]*int{"this": {"second": newPointer(77)}, "patch": {"level": newPointer(15)}} merged, err := mergeMapOfMap(m1, m2) require.NoError(t, err) @@ -215,9 +216,9 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]map[string]*int, patch has nil keys -- /do/ overwrite base with nil", func(t *testing.T) { - m1 := map[string]map[string]*int{"this": {"second": newInt(99)}, "base": {"level": newInt(10)}} - m2 := map[string]map[string]*int{"this": {"second": nil}, "base": nil, "patch": {"level": newInt(15)}} - expected := map[string]map[string]*int{"this": {"second": nil}, "base": nil, "patch": {"level": newInt(15)}} + m1 := map[string]map[string]*int{"this": {"second": newPointer(99)}, "base": {"level": newPointer(10)}} + m2 := map[string]map[string]*int{"this": {"second": nil}, "base": nil, "patch": {"level": newPointer(15)}} + expected := map[string]map[string]*int{"this": {"second": nil}, "base": nil, "patch": {"level": newPointer(15)}} merged, err := mergeMapOfMap(m1, m2) require.NoError(t, err) @@ -227,8 +228,8 @@ func TestMergeWithMaps(t *testing.T) { t.Run("merge map[string]map[string]*int, base has nil vals -- overwrite base with patch", func(t *testing.T) { m1 := map[string]map[string]*int{"this": {"second": nil}, "base": nil} - m2 := map[string]map[string]*int{"this": {"second": newInt(77)}, "base": {"level": newInt(10)}, "patch": {"level": newInt(15)}} - expected := map[string]map[string]*int{"this": {"second": newInt(77)}, "base": {"level": newInt(10)}, "patch": {"level": newInt(15)}} + m2 := map[string]map[string]*int{"this": {"second": newPointer(77)}, "base": {"level": newPointer(10)}, "patch": {"level": newPointer(15)}} + expected := map[string]map[string]*int{"this": {"second": newPointer(77)}, "base": {"level": newPointer(10)}, "patch": {"level": newPointer(15)}} merged, err := mergeMapOfMap(m1, m2) require.NoError(t, err) @@ -238,9 +239,9 @@ func TestMergeWithMaps(t *testing.T) { t.Run("merge map[string]map[string]*int, pointers are not copied - change in base does not affect merged", func(t *testing.T) { // shouldn't, if we're overwriting completely - m1 := map[string]map[string]*int{"this": {"second": newInt(99)}, "base": {"level": newInt(10)}, "are belong": {"to us": newInt(23)}} - m2 := map[string]map[string]*int{"base": {"level": newInt(10)}} - expected := map[string]map[string]*int{"base": {"level": newInt(10)}} + m1 := map[string]map[string]*int{"this": {"second": newPointer(99)}, "base": {"level": newPointer(10)}, "are belong": {"to us": newPointer(23)}} + m2 := map[string]map[string]*int{"base": {"level": newPointer(10)}} + expected := map[string]map[string]*int{"base": {"level": newPointer(10)}} merged, err := mergeMapOfMap(m1, m2) require.NoError(t, err) @@ -252,20 +253,20 @@ func TestMergeWithMaps(t *testing.T) { assert.Equal(t, 10, *merged["base"]["level"]) // test replacing map entry - m1["base"]["level"] = newInt(12) + m1["base"]["level"] = newPointer(12) assert.Equal(t, 10, *merged["base"]["level"]) // test replacing a referenced map - m1["base"] = map[string]*int{"third": newInt(777)} + m1["base"] = map[string]*int{"third": newPointer(777)} assert.Equal(t, 10, *merged["base"]["level"]) }) t.Run("merge map[string]map[string]*int, pointers are not copied - change in patch do not affect merged", func(t *testing.T) { - m1 := map[string]map[string]*int{"base": {"level": newInt(15)}} - m2 := map[string]map[string]*int{"this": {"second": newInt(99)}, "patch": {"level": newInt(10)}, - "are belong": {"to us": newInt(23)}} - expected := map[string]map[string]*int{"this": {"second": newInt(99)}, "patch": {"level": newInt(10)}, - "are belong": {"to us": newInt(23)}} + m1 := map[string]map[string]*int{"base": {"level": newPointer(15)}} + m2 := map[string]map[string]*int{"this": {"second": newPointer(99)}, "patch": {"level": newPointer(10)}, + "are belong": {"to us": newPointer(23)}} + expected := map[string]map[string]*int{"this": {"second": newPointer(99)}, "patch": {"level": newPointer(10)}, + "are belong": {"to us": newPointer(23)}} merged, err := mergeMapOfMap(m1, m2) require.NoError(t, err) @@ -273,11 +274,11 @@ func TestMergeWithMaps(t *testing.T) { assert.Equal(t, expected, merged) // test replacing a referenced map - m2["this"] = map[string]*int{"third": newInt(777)} + m2["this"] = map[string]*int{"third": newPointer(777)} assert.Equal(t, 99, *merged["this"]["second"]) // test replacing map entry - m2["patch"]["level"] = newInt(12) + m2["patch"]["level"] = newPointer(12) assert.Equal(t, 10, *merged["patch"]["level"]) // test changing the map entry's referenced value @@ -286,12 +287,12 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]any", func(t *testing.T) { - m1 := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "base": map[string]*int{"level": newInt(10)}} - m2 := map[string]any{"this": map[string]*int{"second": newInt(77)}, - "patch": map[string]*int{"level": newInt(15)}} - expected := map[string]any{"this": map[string]*int{"second": newInt(77)}, - "patch": map[string]*int{"level": newInt(15)}} + m1 := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "base": map[string]*int{"level": newPointer(10)}} + m2 := map[string]any{"this": map[string]*int{"second": newPointer(77)}, + "patch": map[string]*int{"level": newPointer(15)}} + expected := map[string]any{"this": map[string]*int{"second": newPointer(77)}, + "patch": map[string]*int{"level": newPointer(15)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -300,7 +301,7 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]any, patch has nil keys -- /do/ overwrite base with nil", func(t *testing.T) { - m1 := map[string]any{"this": map[string]*int{"second": newInt(99)}} + m1 := map[string]any{"this": map[string]*int{"second": newPointer(99)}} m2 := map[string]any{"this": map[string]*int{"second": nil}} expected := map[string]any{"this": map[string]*int{"second": nil}} @@ -311,12 +312,12 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]any, patch has nil keys -- /do/ overwrite base with nil (more complex)", func(t *testing.T) { - m1 := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "base": map[string]*int{"level": newInt(10)}} + m1 := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "base": map[string]*int{"level": newPointer(10)}} m2 := map[string]any{"this": map[string]*int{"second": nil}, - "base": nil, "patch": map[string]*int{"level": newInt(15)}} + "base": nil, "patch": map[string]*int{"level": newPointer(15)}} expected := map[string]any{"this": map[string]*int{"second": nil}, - "base": nil, "patch": map[string]*int{"level": newInt(15)}} + "base": nil, "patch": map[string]*int{"level": newPointer(15)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -326,8 +327,8 @@ func TestMergeWithMaps(t *testing.T) { t.Run("merge map[string]map[string]*int, base has nil vals -- overwrite base with patch", func(t *testing.T) { m1 := map[string]any{"base": nil} - m2 := map[string]any{"base": map[string]*int{"level": newInt(10)}} - expected := map[string]any{"base": map[string]*int{"level": newInt(10)}} + m2 := map[string]any{"base": map[string]*int{"level": newPointer(10)}} + expected := map[string]any{"base": map[string]*int{"level": newPointer(10)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -337,10 +338,10 @@ func TestMergeWithMaps(t *testing.T) { t.Run("merge map[string]map[string]*int, base has nil vals -- overwrite base with patch (more complex)", func(t *testing.T) { m1 := map[string]any{"this": map[string]*int{"second": nil}, "base": nil} - m2 := map[string]any{"this": map[string]*int{"second": newInt(77)}, - "base": map[string]*int{"level": newInt(10)}, "patch": map[string]*int{"level": newInt(15)}} - expected := map[string]any{"this": map[string]*int{"second": newInt(77)}, - "base": map[string]*int{"level": newInt(10)}, "patch": map[string]*int{"level": newInt(15)}} + m2 := map[string]any{"this": map[string]*int{"second": newPointer(77)}, + "base": map[string]*int{"level": newPointer(10)}, "patch": map[string]*int{"level": newPointer(15)}} + expected := map[string]any{"this": map[string]*int{"second": newPointer(77)}, + "base": map[string]*int{"level": newPointer(10)}, "patch": map[string]*int{"level": newPointer(15)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -349,12 +350,12 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]any, pointers are not copied - changes in base do not affect merged", func(t *testing.T) { - m1 := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}} - m2 := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}} - expected := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}} + m1 := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "base": map[string]*int{"level": newPointer(10)}, "are belong": map[string]*int{"to us": newPointer(23)}} + m2 := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "base": map[string]*int{"level": newPointer(10)}, "are belong": map[string]*int{"to us": newPointer(23)}} + expected := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "base": map[string]*int{"level": newPointer(10)}, "are belong": map[string]*int{"to us": newPointer(23)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -362,11 +363,11 @@ func TestMergeWithMaps(t *testing.T) { assert.Equal(t, expected, merged) // test replacing a referenced map - m1["this"] = map[string]*int{"third": newInt(777)} + m1["this"] = map[string]*int{"third": newPointer(777)} assert.Equal(t, 99, *merged["this"].(map[string]*int)["second"]) // test replacing map entry - m1["base"].(map[string]*int)["level"] = newInt(12) + m1["base"].(map[string]*int)["level"] = newPointer(12) assert.Equal(t, 10, *merged["base"].(map[string]*int)["level"]) // test changing the map entry's referenced value @@ -375,11 +376,11 @@ func TestMergeWithMaps(t *testing.T) { }) t.Run("merge map[string]any, pointers are not copied - change in patch do not affect merged", func(t *testing.T) { - m1 := map[string]any{"base": map[string]*int{"level": newInt(15)}} - m2 := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "patch": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}} - expected := map[string]any{"this": map[string]*int{"second": newInt(99)}, - "patch": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}} + m1 := map[string]any{"base": map[string]*int{"level": newPointer(15)}} + m2 := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "patch": map[string]*int{"level": newPointer(10)}, "are belong": map[string]*int{"to us": newPointer(23)}} + expected := map[string]any{"this": map[string]*int{"second": newPointer(99)}, + "patch": map[string]*int{"level": newPointer(10)}, "are belong": map[string]*int{"to us": newPointer(23)}} merged, err := mergeInterfaceMap(m1, m2) require.NoError(t, err) @@ -387,11 +388,11 @@ func TestMergeWithMaps(t *testing.T) { assert.Equal(t, expected, merged) // test replacing a referenced map - m2["this"] = map[string]*int{"third": newInt(777)} + m2["this"] = map[string]*int{"third": newPointer(777)} assert.Equal(t, 99, *merged["this"].(map[string]*int)["second"]) // test replacing map entry - m2["patch"].(map[string]*int)["level"] = newInt(12) + m2["patch"].(map[string]*int)["level"] = newPointer(12) assert.Equal(t, 10, *merged["patch"].(map[string]*int)["level"]) // test changing the map entry's referenced value @@ -581,9 +582,9 @@ func (e *evenSimpler2) String() string { func TestMergeWithEvenSimpler(t *testing.T) { t.Run("evenSimplerStruct: base nils are overwritten by patch", func(t *testing.T) { - t1 := evenSimpler{newBool(true), &evenSimpler2{nil}} - t2 := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} - expected := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} + t1 := evenSimpler{newPointer(true), &evenSimpler2{nil}} + t2 := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} + expected := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -592,9 +593,9 @@ func TestMergeWithEvenSimpler(t *testing.T) { }) t.Run("evenSimplerStruct: patch nils are ignored", func(t *testing.T) { - t1 := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} + t1 := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} t2 := evenSimpler{nil, &evenSimpler2{nil}} - expected := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} + expected := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -614,9 +615,9 @@ func TestMergeWithEvenSimpler(t *testing.T) { }) t.Run("evenSimplerStruct: can handle both nils (ptr to ptr), merged will have nil (not zero value)", func(t *testing.T) { - t1 := evenSimpler{newBool(true), nil} - t2 := evenSimpler{newBool(true), nil} - expected := evenSimpler{newBool(true), nil} + t1 := evenSimpler{newPointer(true), nil} + t2 := evenSimpler{newPointer(true), nil} + expected := evenSimpler{newPointer(true), nil} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -625,9 +626,9 @@ func TestMergeWithEvenSimpler(t *testing.T) { }) t.Run("evenSimplerStruct: base nils (ptr to ptr) are overwritten by patch", func(t *testing.T) { - t1 := evenSimpler{newBool(true), nil} - t2 := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} - expected := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} + t1 := evenSimpler{newPointer(true), nil} + t2 := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} + expected := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -636,9 +637,9 @@ func TestMergeWithEvenSimpler(t *testing.T) { }) t.Run("evenSimplerStruct: base nils (ptr to ptr) are overwritten by patch, and not copied - changes in patch don't affect merged", func(t *testing.T) { - t1 := evenSimpler{newBool(true), nil} - t2 := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} - expected := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} + t1 := evenSimpler{newPointer(true), nil} + t2 := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} + expected := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -649,9 +650,9 @@ func TestMergeWithEvenSimpler(t *testing.T) { }) t.Run("evenSimplerStruct: patch nils (ptr to ptr) do not overwrite base, and are not copied - changes in base don't affect merged", func(t *testing.T) { - t1 := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} - t2 := evenSimpler{newBool(false), nil} - expected := evenSimpler{newBool(false), &evenSimpler2{newString("base")}} + t1 := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} + t2 := evenSimpler{newPointer(false), nil} + expected := evenSimpler{newPointer(false), &evenSimpler2{newPointer("base")}} merged, err := mergeEvenSimpler(t1, t2) require.NoError(t, err) @@ -734,7 +735,7 @@ type mapPtr struct { func TestMergeWithMapPtr(t *testing.T) { t.Run("patch nils overwrite - mapPtr - maps overwrite completely", func(t *testing.T) { - t1 := mapPtr{map[string]*evenSimpler2{"base key": {newString("base")}}} + t1 := mapPtr{map[string]*evenSimpler2{"base key": {newPointer("base")}}} t2 := mapPtr{map[string]*evenSimpler2{"base key": {nil}}} expected := mapPtr{map[string]*evenSimpler2{"base key": {nil}}} @@ -745,7 +746,7 @@ func TestMergeWithMapPtr(t *testing.T) { }) t.Run("patch nil structs are ignored - mapPtr - maps overwrite ", func(t *testing.T) { - t1 := mapPtr{map[string]*evenSimpler2{"base key": {newString("base")}}} + t1 := mapPtr{map[string]*evenSimpler2{"base key": {newPointer("base")}}} t2 := mapPtr{map[string]*evenSimpler2{"base key": nil}} expected := mapPtr{map[string]*evenSimpler2{"base key": nil}} @@ -776,18 +777,18 @@ func TestMergeWithMapPtrState(t *testing.T) { }) t.Run("merge identical structs - simple", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - expected := simple{42, 0, nil, newInt(45), newBool(true), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + expected := simple{42, 0, nil, newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -796,18 +797,18 @@ func TestMergeWithMapPtrState(t *testing.T) { }) t.Run("base nils are overwritten by patch", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), nil, + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), nil, []int{1, 2, 3}, nil, simple2{30, nil, nil}, nil} - t2 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + t2 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - expected := simple{42, 0, nil, newInt(45), newBool(true), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + expected := simple{42, 0, nil, newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -826,7 +827,7 @@ type state2 struct { func TestMergeWithMapPtrState2(t *testing.T) { t.Run("inside structs, maps overwrite completely - mapPtrState2", func(t *testing.T) { - t1 := mapPtrState2{map[string]*state2{"base key": {true, newBool(true)}}} + t1 := mapPtrState2{map[string]*state2{"base key": {true, newPointer(true)}}} t2 := mapPtrState2{map[string]*state2{"base key": {false, nil}}} expected := mapPtrState2{map[string]*state2{"base key": {false, nil}}} @@ -837,7 +838,7 @@ func TestMergeWithMapPtrState2(t *testing.T) { }) t.Run("inside structs, maps overwrite completely - mapPtrState2 2", func(t *testing.T) { - t1 := mapPtrState2{map[string]*state2{"base key": {true, newBool(true)}}} // + t1 := mapPtrState2{map[string]*state2{"base key": {true, newPointer(true)}}} // t2 := mapPtrState2{map[string]*state2{"base key": nil}} expected := mapPtrState2{map[string]*state2{"base key": nil}} @@ -868,18 +869,18 @@ type simple2 struct { func TestMergeWithSimpleStruct(t *testing.T) { t.Run("patch nils are ignored", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test base"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{42, 42.2, newFloat64(932.2), nil, nil, + simple2{30, newPointer("test base"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{42, 42.2, newPointer[float64](932.2), nil, nil, nil, nil, simple2{30, nil, nil}, &simple2{42, nil, nil}} - expected := simple{42, 0, nil, newInt(45), newBool(true), + expected := simple{42, 0, nil, newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test base"), []string{"test1", "test2"}}, - &simple2{42, newString("test2"), []string{"test3", "test4", "test5"}}} + simple2{30, newPointer("test base"), []string{"test1", "test2"}}, + &simple2{42, newPointer("test2"), []string{"test3", "test4", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -888,18 +889,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("patch nilled structs are ignored", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test base"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + simple2{30, newPointer("test base"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test base"), []string{"test1", "test2"}}, + simple2{30, newPointer("test base"), []string{"test1", "test2"}}, nil} - expected := simple{42, 0, nil, newInt(45), newBool(true), + expected := simple{42, 0, nil, newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test base"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} + simple2{30, newPointer("test base"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -908,15 +909,15 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("can handle both nils", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), nil, + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), nil, []int{1, 2, 3}, nil, simple2{30, nil, nil}, nil} - t2 := simple{42, 42.2, newFloat64(932.2), newInt(45), nil, + t2 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), nil, []int{1, 2, 3}, nil, simple2{30, nil, nil}, nil} - expected := simple{42, 0, nil, newInt(45), nil, + expected := simple{42, 0, nil, newPointer(45), nil, []int{1, 2, 3}, nil, simple2{30, nil, nil}, nil} @@ -928,18 +929,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("different base vals are overwritten by patch, and unexported fields are ignored", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(45), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(45), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{13, 53.1, newFloat64(932.2), newInt(46), newBool(false), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{13, 53.1, newPointer[float64](932.2), newPointer(46), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test99"}}, + simple2{30, newPointer("testpatch"), []string{"test1", "test99"}}, &simple2{45, nil, []string{"test3", "test123", "test5"}}} - expected := simple{13, 0, nil, newInt(46), newBool(false), + expected := simple{13, 0, nil, newPointer(46), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test99"}}, - &simple2{45, newString("test2"), []string{"test3", "test123", "test5"}}} + simple2{30, newPointer("testpatch"), []string{"test1", "test99"}}, + &simple2{45, newPointer("test2"), []string{"test3", "test123", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -949,18 +950,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("pointers are not being copied or modified", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(99), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(99), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{13, 53.1, newFloat64(932.2), nil, newBool(false), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{13, 53.1, newPointer[float64](932.2), nil, newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, &simple2{45, nil, []string{"test3", "test4", "test5"}}} - expected := simple{13, 0, nil, newInt(99), newBool(false), + expected := simple{13, 0, nil, newPointer(99), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, - &simple2{45, newString("test2"), []string{"test3", "test4", "test5"}}} + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, + &simple2{45, newPointer("test2"), []string{"test3", "test4", "test5"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -986,18 +987,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("slices are not being copied or modified", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(99), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(99), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{13, 53.1, newFloat64(932.2), nil, newBool(false), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{13, 53.1, newPointer[float64](932.2), nil, newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), nil}, + simple2{30, newPointer("testpatch"), nil}, &simple2{45, nil, []string{"test3", "test4", "test99"}}} - expected := simple{13, 0, nil, newInt(99), newBool(false), + expected := simple{13, 0, nil, newPointer(99), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, - &simple2{45, newString("test2"), []string{"test3", "test4", "test99"}}} + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, + &simple2{45, newPointer("test2"), []string{"test3", "test4", "test99"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -1019,18 +1020,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("maps are not being copied or modified: base -> merged", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(99), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(99), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{13, 53.1, newFloat64(932.2), nil, newBool(false), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{13, 53.1, newPointer[float64](932.2), nil, newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, &simple2{45, nil, []string{"test3", "test4", "test99"}}} - expected := simple{13, 0, nil, newInt(99), newBool(false), + expected := simple{13, 0, nil, newPointer(99), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, - &simple2{45, newString("test2"), []string{"test3", "test4", "test99"}}} + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, + &simple2{45, newPointer("test2"), []string{"test3", "test4", "test99"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -1047,18 +1048,18 @@ func TestMergeWithSimpleStruct(t *testing.T) { }) t.Run("patch map overwrites", func(t *testing.T) { - t1 := simple{42, 42.2, newFloat64(932.2), newInt(99), newBool(true), + t1 := simple{42, 42.2, newPointer[float64](932.2), newPointer(99), newPointer(true), []int{1, 2, 3}, map[string]int{"key1": 1, "key2": 2, "key4": 4}, - simple2{30, newString("test"), []string{"test1", "test2"}}, - &simple2{40, newString("test2"), []string{"test3", "test4", "test5"}}} - t2 := simple{13, 53.1, newFloat64(932.2), nil, newBool(false), + simple2{30, newPointer("test"), []string{"test1", "test2"}}, + &simple2{40, newPointer("test2"), []string{"test3", "test4", "test5"}}} + t2 := simple{13, 53.1, newPointer[float64](932.2), nil, newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 11, "key2": 2, "key3": 3}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, &simple2{45, nil, []string{"test3", "test4", "test99"}}} - expected := simple{13, 0, nil, newInt(99), newBool(false), + expected := simple{13, 0, nil, newPointer(99), newPointer(false), []int{1, 2, 3}, map[string]int{"key1": 11, "key2": 2, "key3": 3}, - simple2{30, newString("testpatch"), []string{"test1", "test2"}}, - &simple2{45, newString("test2"), []string{"test3", "test4", "test99"}}} + simple2{30, newPointer("testpatch"), []string{"test1", "test2"}}, + &simple2{45, newPointer("test2"), []string{"test3", "test4", "test99"}}} merged, err := mergeSimple(t1, t2) require.NoError(t, err) @@ -1093,7 +1094,7 @@ func TestMergeWithVeryComplexStruct(t *testing.T) { setupStructs(t) base.F = 1342.12 - base.Struct1.Pi = newInt(937) + base.Struct1.Pi = newPointer(937) base.Struct1p.UI = 734 base.Struct1.Struct2.Sli = []int{123123, 1243123} @@ -1174,9 +1175,9 @@ func TestMergeWithVeryComplexStruct(t *testing.T) { func TestMergeWithStructFieldFilter(t *testing.T) { t.Run("filter skips merging from patch", func(t *testing.T) { - t1 := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} - t2 := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} - expected := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} + t1 := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} + t2 := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} + expected := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} merged, err := mergeEvenSimplerWithConfig(t1, t2, &utils.MergeConfig{ StructFieldFilter: func(structField reflect.StructField, base, patch reflect.Value) bool { @@ -1189,9 +1190,9 @@ func TestMergeWithStructFieldFilter(t *testing.T) { }) t.Run("filter skips merging configured fields from patch", func(t *testing.T) { - t1 := evenSimpler{newBool(true), &evenSimpler2{newString("base")}} - t2 := evenSimpler{newBool(false), &evenSimpler2{newString("patch")}} - expected := evenSimpler{newBool(false), &evenSimpler2{newString("base")}} + t1 := evenSimpler{newPointer(true), &evenSimpler2{newPointer("base")}} + t2 := evenSimpler{newPointer(false), &evenSimpler2{newPointer("patch")}} + expected := evenSimpler{newPointer(false), &evenSimpler2{newPointer("base")}} merged, err := mergeEvenSimplerWithConfig(t1, t2, &utils.MergeConfig{ StructFieldFilter: func(structField reflect.StructField, base, patch reflect.Value) bool { @@ -1335,221 +1336,221 @@ func setupStructs(t *testing.T) { t.Helper() baseStructEmbed2A = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } baseStructEmbed2B = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } baseStructEmbed2C = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } baseStructEmbed2D = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } baseStructEmbedBaseA = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, baseStructEmbed2A, &baseStructEmbed2B, } baseStructEmbedBaseB = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, baseStructEmbed2C, &baseStructEmbed2D, } base = testStruct{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, baseStructEmbedBaseA, &baseStructEmbedBaseB, } patchStructEmbed2A = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } patchStructEmbed2B = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } patchStructEmbed2C = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } patchStructEmbed2D = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } patchStructEmbedBaseA = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, patchStructEmbed2A, &patchStructEmbed2B, } patchStructEmbedBaseB = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, patchStructEmbed2C, &patchStructEmbed2D, } patch = testStruct{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, patchStructEmbedBaseA, &patchStructEmbedBaseB, } mergeStructEmbed2A = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } mergeStructEmbed2B = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } mergeStructEmbed2C = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } mergeStructEmbed2D = testStructEmbed2{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, } mergeStructEmbedBaseA = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, mergeStructEmbed2A, &mergeStructEmbed2B, } mergeStructEmbedBaseB = testStructEmbed{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, mergeStructEmbed2C, &mergeStructEmbed2D, } expectedMerged = testStruct{1, 2, 3, 4, 5, 1.1, 2.2, "test", 10, 11, 12, 12, 13, - newInt(14), newInt8(15), newInt16(16), newInt32(17), newInt64(18), - newFloat64(19.9), newFloat32(20.1), newString("test pointer"), - newUint(21), newUint8(22), newUint16(23), newUint32(24), newUint64(25), + newPointer(14), newPointer[int8](15), newPointer[int16](16), newPointer[int32](17), newPointer[int64](18), + newPointer[float64](19.9), newPointer[float32](20.1), newPointer("test pointer"), + newPointer[uint](21), newPointer[uint8](22), newPointer[uint16](23), newPointer[uint32](24), newPointer[uint64](25), []string{"test", "slice", "strings"}, []int{1, 2, 3, 4}, []float64{1.1, 2.2, 3.3}, map[string]int{"this": 1, "is": 2, "a": 3, "map": 4}, map[int]string{1: "this", 2: "is", 3: "another"}, - map[string]*int{"wow": newInt(1), "a map": newInt(2), "of pointers!": newInt(3)}, - map[int]*string{1: newString("Another"), 2: newString("map of"), 3: newString("pointers, wow!")}, + map[string]*int{"wow": newPointer(1), "a map": newPointer(2), "of pointers!": newPointer(3)}, + map[int]*string{1: newPointer("Another"), 2: newPointer("map of"), 3: newPointer("pointers, wow!")}, mergeStructEmbedBaseA, &mergeStructEmbedBaseB, } } @@ -1654,17 +1655,6 @@ func mergeTestStructsPtrs(base, patch *testStruct) (*testStruct, error) { return utils.Merge(base, patch, nil) } -func newBool(b bool) *bool { return &b } -func newInt(n int) *int { return &n } -func newInt64(n int64) *int64 { return &n } -func newString(s string) *string { return &s } -func newInt8(n int8) *int8 { return &n } -func newInt16(n int16) *int16 { return &n } -func newInt32(n int32) *int32 { return &n } -func newFloat64(f float64) *float64 { return &f } -func newFloat32(f float32) *float32 { return &f } -func newUint(n uint) *uint { return &n } -func newUint8(n uint8) *uint8 { return &n } -func newUint16(n uint16) *uint16 { return &n } -func newUint32(n uint32) *uint32 { return &n } -func newUint64(n uint64) *uint64 { return &n } +func newPointer[T any](t T) *T { + return model.NewPointer(t) +} diff --git a/server/channels/utils/subpath_test.go b/server/channels/utils/subpath_test.go index 885606ff226..5074c8aff18 100644 --- a/server/channels/utils/subpath_test.go +++ b/server/channels/utils/subpath_test.go @@ -214,13 +214,13 @@ func TestGetSubpathFromConfig(t *testing.T) { }{ { "empty SiteURL", - sToP(""), + model.NewPointer(""), false, "/", }, { "invalid SiteURL", - sToP("cache_object:foo/bar"), + model.NewPointer("cache_object:foo/bar"), true, "", }, @@ -232,25 +232,25 @@ func TestGetSubpathFromConfig(t *testing.T) { }, { "no trailing slash", - sToP("http://localhost:8065"), + model.NewPointer("http://localhost:8065"), false, "/", }, { "trailing slash", - sToP("http://localhost:8065/"), + model.NewPointer("http://localhost:8065/"), false, "/", }, { "subpath, no trailing slash", - sToP("http://localhost:8065/subpath"), + model.NewPointer("http://localhost:8065/subpath"), false, "/subpath", }, { "trailing slash", - sToP("http://localhost:8065/subpath/"), + model.NewPointer("http://localhost:8065/subpath/"), false, "/subpath", }, @@ -276,10 +276,6 @@ func TestGetSubpathFromConfig(t *testing.T) { } } -func sToP(s string) *string { - return &s -} - const contentSecurityPolicyNotFoundHTML = ` Mattermost <

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const contentSecurityPolicyNotFound2HTML = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` diff --git a/server/platform/services/awsmeter/awsmeter_test.go b/server/platform/services/awsmeter/awsmeter_test.go index c9b20a6f037..7b01e967df9 100644 --- a/server/platform/services/awsmeter/awsmeter_test.go +++ b/server/platform/services/awsmeter/awsmeter_test.go @@ -24,7 +24,7 @@ type mockMarketplaceMeteringClient struct { func (m *mockMarketplaceMeteringClient) MeterUsage(input *marketplacemetering.MeterUsageInput) (*marketplacemetering.MeterUsageOutput, error) { return &marketplacemetering.MeterUsageOutput{ - MeteringRecordId: String("1"), + MeteringRecordId: model.NewPointer("1"), }, nil } @@ -36,9 +36,6 @@ func (m *mockMarketplaceMeteringClientWithError) MeterUsage(input *marketplaceme return nil, errors.New("error") } -func String(i string) *string { - return &i -} func TestAwsMeterUsage(t *testing.T) { startTime := time.Now() endTime := time.Now() diff --git a/server/public/model/bot_test.go b/server/public/model/bot_test.go index 8245db218f3..08b5b87602f 100644 --- a/server/public/model/bot_test.go +++ b/server/public/model/bot_test.go @@ -368,10 +368,6 @@ func TestBotEtag(t *testing.T) { }) } -func sToP(s string) *string { - return &s -} - func TestBotPatch(t *testing.T) { userId1 := NewId() creatorId1 := NewId() @@ -422,9 +418,9 @@ func TestBotPatch(t *testing.T) { DeleteAt: 4, }, &BotPatch{ - Username: sToP("new_username"), + Username: NewPointer("new_username"), DisplayName: nil, - Description: sToP("new description"), + Description: NewPointer("new description"), }, &Bot{ UserId: userId1, @@ -452,9 +448,9 @@ func TestBotPatch(t *testing.T) { DeleteAt: 4, }, &BotPatch{ - Username: sToP("new_username"), - DisplayName: sToP("new display name"), - Description: sToP("new description"), + Username: NewPointer("new_username"), + DisplayName: NewPointer("new display name"), + Description: NewPointer("new description"), }, &Bot{ UserId: userId1,