MM-15276: Migrate Team.Update to sync by default (#10693)

* MM-15276: Migrate Team.Update to sync by default

* MM-15276: Addressing review comments and change Update func signature similar to other interface Update method

* update store mocks for update fn

* addressing review comments
Этот коммит содержится в:
Puneeth Reddy
2019-04-25 06:29:02 -07:00
коммит произвёл Jesús Espino
родитель b24013d54c
Коммит ec95793b90
17 изменённых файлов: 109 добавлений и 111 удалений

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

@@ -13,7 +13,7 @@ var mainHelper *testlib.MainHelper
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var options = testlib.HelperOptions{ var options = testlib.HelperOptions{
EnableStore: true, EnableStore: true,
EnableResources: true, EnableResources: true,
} }

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

@@ -602,7 +602,6 @@ func TestUpdatePost(t *testing.T) {
assert.NotEqual(t, rpost3.EditAt, rrupost3.EditAt) assert.NotEqual(t, rpost3.EditAt, rrupost3.EditAt)
assert.NotEqual(t, rpost3.Attachments(), rrupost3.Attachments()) assert.NotEqual(t, rpost3.Attachments(), rrupost3.Attachments())
Client.Logout() Client.Logout()
_, resp = Client.UpdatePost(rpost.Id, rpost) _, resp = Client.UpdatePost(rpost.Id, rpost)
CheckUnauthorizedStatus(t, resp) CheckUnauthorizedStatus(t, resp)

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

@@ -304,9 +304,8 @@ func TestGetTeamsForScheme(t *testing.T) {
assert.Zero(t, len(l2)) assert.Zero(t, len(l2))
team1.SchemeId = &scheme1.Id team1.SchemeId = &scheme1.Id
result2 := <-th.App.Srv.Store.Team().Update(team1) team1, err := th.App.Srv.Store.Team().Update(team1)
assert.Nil(t, result2.Err) assert.Nil(t, err)
team1 = result2.Data.(*model.Team)
l3, r3 := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100) l3, r3 := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
CheckNoError(t, r3) CheckNoError(t, r3)

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

@@ -136,12 +136,7 @@ func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
} }
func (a *App) updateTeamUnsanitized(team *model.Team) (*model.Team, *model.AppError) { func (a *App) updateTeamUnsanitized(team *model.Team) (*model.Team, *model.AppError) {
result := <-a.Srv.Store.Team().Update(team) return a.Srv.Store.Team().Update(team)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Team), nil
} }
// RenameTeam is used to rename the team Name and the DisplayName fields // RenameTeam is used to rename the team Name and the DisplayName fields
@@ -180,8 +175,8 @@ func (a *App) UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
oldTeam.SchemeId = team.SchemeId oldTeam.SchemeId = team.SchemeId
if result := <-a.Srv.Store.Team().Update(oldTeam); result.Err != nil { if oldTeam, err = a.Srv.Store.Team().Update(oldTeam); err != nil {
return nil, result.Err return nil, err
} }
a.sendTeamEvent(oldTeam, model.WEBSOCKET_EVENT_UPDATE_TEAM) a.sendTeamEvent(oldTeam, model.WEBSOCKET_EVENT_UPDATE_TEAM)
@@ -1051,8 +1046,8 @@ func (a *App) PermanentDeleteTeamId(teamId string) *model.AppError {
func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError { func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
team.DeleteAt = model.GetMillis() team.DeleteAt = model.GetMillis()
if result := <-a.Srv.Store.Team().Update(team); result.Err != nil { if _, err := a.Srv.Store.Team().Update(team); err != nil {
return result.Err return err
} }
if result := <-a.Srv.Store.Channel().GetTeamChannels(team.Id); result.Err != nil { if result := <-a.Srv.Store.Channel().GetTeamChannels(team.Id); result.Err != nil {
@@ -1090,8 +1085,8 @@ func (a *App) SoftDeleteTeam(teamId string) *model.AppError {
} }
team.DeleteAt = model.GetMillis() team.DeleteAt = model.GetMillis()
if result := <-a.Srv.Store.Team().Update(team); result.Err != nil { if team, err = a.Srv.Store.Team().Update(team); err != nil {
return result.Err return err
} }
a.sendTeamEvent(team, model.WEBSOCKET_EVENT_DELETE_TEAM) a.sendTeamEvent(team, model.WEBSOCKET_EVENT_DELETE_TEAM)
@@ -1104,11 +1099,12 @@ func (a *App) RestoreTeam(teamId string) *model.AppError {
if err != nil { if err != nil {
return err return err
} }
team.DeleteAt = 0 team.DeleteAt = 0
result := <-a.Srv.Store.Team().Update(team) if team, err = a.Srv.Store.Team().Update(team); err != nil {
if result.Err != nil { return err
return result.Err
} }
a.sendTeamEvent(team, model.WEBSOCKET_EVENT_RESTORE_TEAM) a.sendTeamEvent(team, model.WEBSOCKET_EVENT_RESTORE_TEAM)
return nil return nil
} }

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

@@ -303,7 +303,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.DisplayName, testVal) assert.Equal(t, cmd.DisplayName, testVal)
}) })
t.Run("description nil error", func(t *testing.T) { t.Run("description nil error", func(t *testing.T) {
testVal := "test description" testVal := "test description"
args := []string{"command", "modify", command.Id, "--description", testVal} args := []string{"command", "modify", command.Id, "--description", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -312,7 +312,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.Description, testVal) assert.Equal(t, cmd.Description, testVal)
}) })
t.Run("trigger nil error", func(t *testing.T) { t.Run("trigger nil error", func(t *testing.T) {
testVal := "testtrigger" testVal := "testtrigger"
args := []string{"command", "modify", command.Id, "--trigger-word", testVal} args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -321,21 +321,21 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.Trigger, testVal) assert.Equal(t, cmd.Trigger, testVal)
}) })
t.Run("trigger with space", func(t *testing.T) { t.Run("trigger with space", func(t *testing.T) {
testVal := "bad trigger" testVal := "bad trigger"
args := []string{"command", "modify", command.Id, "--trigger-word", testVal} args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
assert.Contains(t, string(output), "Error: a trigger word must not contain spaces") assert.Contains(t, string(output), "Error: a trigger word must not contain spaces")
}) })
t.Run("trigger with leading /", func(t *testing.T) { t.Run("trigger with leading /", func(t *testing.T) {
testVal := "/bad-trigger" testVal := "/bad-trigger"
args := []string{"command", "modify", command.Id, "--trigger-word", testVal} args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
assert.Contains(t, string(output), "Error: a trigger word cannot begin with a /") assert.Contains(t, string(output), "Error: a trigger word cannot begin with a /")
}) })
t.Run("blank trigger", func(t *testing.T) { t.Run("blank trigger", func(t *testing.T) {
cmd_unmodified, _ := th.App.GetCommand(command.Id) cmd_unmodified, _ := th.App.GetCommand(command.Id)
args := []string{"command", "modify", command.Id, "--trigger-word", ""} args := []string{"command", "modify", command.Id, "--trigger-word", ""}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -347,7 +347,7 @@ func TestModifyCommand(t *testing.T) {
}) })
//url case //url case
t.Run("url nil error", func(t *testing.T) { t.Run("url nil error", func(t *testing.T) {
testVal := "http://localhost:8000/modify-command" testVal := "http://localhost:8000/modify-command"
args := []string{"command", "modify", command.Id, "--url", testVal} args := []string{"command", "modify", command.Id, "--url", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -356,7 +356,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.URL, testVal) assert.Equal(t, cmd.URL, testVal)
}) })
t.Run("blank url", func(t *testing.T) { t.Run("blank url", func(t *testing.T) {
cmd_unmodified, _ := th.App.GetCommand(command.Id) cmd_unmodified, _ := th.App.GetCommand(command.Id)
args := []string{"command", "modify", command.Id, "--url", ""} args := []string{"command", "modify", command.Id, "--url", ""}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -367,7 +367,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd_unmodified.URL, cmd_modified.URL) assert.Equal(t, cmd_unmodified.URL, cmd_modified.URL)
}) })
t.Run("icon url nil error", func(t *testing.T) { t.Run("icon url nil error", func(t *testing.T) {
testVal := "http://localhost:8000/testicon.png" testVal := "http://localhost:8000/testicon.png"
args := []string{"command", "modify", command.Id, "--icon", testVal} args := []string{"command", "modify", command.Id, "--icon", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -376,7 +376,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.IconURL, testVal) assert.Equal(t, cmd.IconURL, testVal)
}) })
t.Run("creator nil error", func(t *testing.T) { t.Run("creator nil error", func(t *testing.T) {
testVal := adminUser testVal := adminUser
args := []string{"command", "modify", command.Id, "--creator", testVal.Username} args := []string{"command", "modify", command.Id, "--creator", testVal.Username}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -385,21 +385,21 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.CreatorId, testVal.Id) assert.Equal(t, cmd.CreatorId, testVal.Id)
}) })
t.Run("creator not found", func(t *testing.T) { t.Run("creator not found", func(t *testing.T) {
testVal := "fakeuser" testVal := "fakeuser"
args := []string{"command", "modify", command.Id, "--creator", testVal} args := []string{"command", "modify", command.Id, "--creator", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
assert.Contains(t, string(output), "unable to find user") assert.Contains(t, string(output), "unable to find user")
}) })
t.Run("creator not admin user", func(t *testing.T) { t.Run("creator not admin user", func(t *testing.T) {
testVal := user.Username testVal := user.Username
args := []string{"command", "modify", command.Id, "--creator", testVal} args := []string{"command", "modify", command.Id, "--creator", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
assert.Contains(t, string(output), "the creator must be a user who has permissions to manage slash commands") assert.Contains(t, string(output), "the creator must be a user who has permissions to manage slash commands")
}) })
t.Run("response username nil error", func(t *testing.T) { t.Run("response username nil error", func(t *testing.T) {
testVal := "response-test" testVal := "response-test"
args := []string{"command", "modify", command.Id, "--response-username", testVal} args := []string{"command", "modify", command.Id, "--response-username", testVal}
output, _ := th.RunCommandWithOutput(t, args...) output, _ := th.RunCommandWithOutput(t, args...)
@@ -408,7 +408,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd.Username, testVal) assert.Equal(t, cmd.Username, testVal)
}) })
t.Run("post set and unset", func(t *testing.T) { t.Run("post set and unset", func(t *testing.T) {
args_set := []string{"command", "modify", command.Id, "--post", ""} args_set := []string{"command", "modify", command.Id, "--post", ""}
args_unset := []string{"command", "modify", command.Id, "", ""} args_unset := []string{"command", "modify", command.Id, "", ""}
@@ -425,7 +425,7 @@ func TestModifyCommand(t *testing.T) {
assert.Equal(t, cmd_unset.Method, "G") assert.Equal(t, cmd_unset.Method, "G")
}) })
t.Run("autocomplete set and unset", func(t *testing.T) { t.Run("autocomplete set and unset", func(t *testing.T) {
args_set := []string{"command", "modify", command.Id, "--autocomplete", ""} args_set := []string{"command", "modify", command.Id, "--autocomplete", ""}
args_unset := []string{"command", "modify", command.Id, "", ""} args_unset := []string{"command", "modify", command.Id, "", ""}

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

@@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
} }
var options = testlib.HelperOptions{ var options = testlib.HelperOptions{
EnableStore: true, EnableStore: true,
EnableResources: true, EnableResources: true,
} }

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

@@ -13,7 +13,7 @@ var mainHelper *testlib.MainHelper
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var options = testlib.HelperOptions{ var options = testlib.HelperOptions{
EnableStore: true, EnableStore: true,
EnableResources: true, EnableResources: true,
} }

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

@@ -181,14 +181,12 @@ func TestPostSanitizeProps(t *testing.T) {
} }
func TestPost_AttachmentsEqual(t *testing.T) { func TestPost_AttachmentsEqual(t *testing.T) {
post1 := &Post { post1 := &Post{}
} post2 := &Post{}
post2 := &Post {
}
for name, tc := range map[string]struct { for name, tc := range map[string]struct {
Attachments1 []*SlackAttachment Attachments1 []*SlackAttachment
Attachments2 []*SlackAttachment Attachments2 []*SlackAttachment
Expected bool Expected bool
}{ }{
"Empty": { "Empty": {
nil, nil,
@@ -233,7 +231,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
"DifferentColor": { "DifferentColor": {
[]*SlackAttachment{ []*SlackAttachment{
{ {
Text: "Hello World", Text: "Hello World",
Color: "#152313", Color: "#152313",
}, },
}, },
@@ -247,7 +245,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
"EqualFields": { "EqualFields": {
[]*SlackAttachment{ []*SlackAttachment{
{ {
Fields: []*SlackAttachmentField { Fields: []*SlackAttachmentField{
{ {
Title: "Hello World", Title: "Hello World",
Value: "FooBar", Value: "FooBar",
@@ -261,7 +259,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
}, },
[]*SlackAttachment{ []*SlackAttachment{
{ {
Fields: []*SlackAttachmentField { Fields: []*SlackAttachmentField{
{ {
Title: "Hello World", Title: "Hello World",
Value: "FooBar", Value: "FooBar",
@@ -278,7 +276,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
"DifferentFields": { "DifferentFields": {
[]*SlackAttachment{ []*SlackAttachment{
{ {
Fields: []*SlackAttachmentField { Fields: []*SlackAttachmentField{
{ {
Title: "Hello World", Title: "Hello World",
Value: "FooBar", Value: "FooBar",
@@ -288,7 +286,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
}, },
[]*SlackAttachment{ []*SlackAttachment{
{ {
Fields: []*SlackAttachmentField { Fields: []*SlackAttachmentField{
{ {
Title: "Hello World", Title: "Hello World",
Value: "FooBar", Value: "FooBar",
@@ -310,9 +308,9 @@ func TestPost_AttachmentsEqual(t *testing.T) {
Actions: []*PostAction{ Actions: []*PostAction{
{ {
Name: "FooBar", Name: "FooBar",
Options: []*PostActionOptions { Options: []*PostActionOptions{
{ {
Text: "abcdef", Text: "abcdef",
Value: "abcdef", Value: "abcdef",
}, },
}, },
@@ -320,7 +318,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
URL: "http://localhost", URL: "http://localhost",
Context: map[string]interface{}{ Context: map[string]interface{}{
"context": "foobar", "context": "foobar",
"test": 123, "test": 123,
}, },
}, },
}, },
@@ -332,9 +330,9 @@ func TestPost_AttachmentsEqual(t *testing.T) {
Actions: []*PostAction{ Actions: []*PostAction{
{ {
Name: "FooBar", Name: "FooBar",
Options: []*PostActionOptions { Options: []*PostActionOptions{
{ {
Text: "abcdef", Text: "abcdef",
Value: "abcdef", Value: "abcdef",
}, },
}, },
@@ -342,7 +340,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
URL: "http://localhost", URL: "http://localhost",
Context: map[string]interface{}{ Context: map[string]interface{}{
"context": "foobar", "context": "foobar",
"test": 123, "test": 123,
}, },
}, },
}, },
@@ -357,9 +355,9 @@ func TestPost_AttachmentsEqual(t *testing.T) {
Actions: []*PostAction{ Actions: []*PostAction{
{ {
Name: "FooBar", Name: "FooBar",
Options: []*PostActionOptions { Options: []*PostActionOptions{
{ {
Text: "abcdef", Text: "abcdef",
Value: "abcdef", Value: "abcdef",
}, },
}, },
@@ -367,7 +365,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
URL: "http://localhost", URL: "http://localhost",
Context: map[string]interface{}{ Context: map[string]interface{}{
"context": "foobar", "context": "foobar",
"test": "mattermost", "test": "mattermost",
}, },
}, },
}, },
@@ -379,9 +377,9 @@ func TestPost_AttachmentsEqual(t *testing.T) {
Actions: []*PostAction{ Actions: []*PostAction{
{ {
Name: "FooBar", Name: "FooBar",
Options: []*PostActionOptions { Options: []*PostActionOptions{
{ {
Text: "abcdef", Text: "abcdef",
Value: "abcdef", Value: "abcdef",
}, },
}, },
@@ -389,7 +387,7 @@ func TestPost_AttachmentsEqual(t *testing.T) {
URL: "http://localhost", URL: "http://localhost",
Context: map[string]interface{}{ Context: map[string]interface{}{
"context": "foobar", "context": "foobar",
"test": 123, "test": 123,
}, },
}, },
}, },

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

@@ -252,8 +252,8 @@ var hashtags = map[string]string{
func TestStringArray_Equal(t *testing.T) { func TestStringArray_Equal(t *testing.T) {
for name, tc := range map[string]struct { for name, tc := range map[string]struct {
Array1 StringArray Array1 StringArray
Array2 StringArray Array2 StringArray
Expected bool Expected bool
}{ }{
"Empty": { "Empty": {

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

@@ -149,7 +149,7 @@ func NewHTTPClient(transport http.RoundTripper) *http.Client {
func TestIsReservedIP(t *testing.T) { func TestIsReservedIP(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
ip net.IP ip net.IP
want bool want bool
}{ }{
{"127.8.3.5", net.IPv4(127, 8, 3, 5), true}, {"127.8.3.5", net.IPv4(127, 8, 3, 5), true},
@@ -171,7 +171,7 @@ func TestIsReservedIP(t *testing.T) {
func TestIsOwnIP(t *testing.T) { func TestIsOwnIP(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
ip net.IP ip net.IP
want bool want bool
}{ }{
{"127.0.0.1", net.IPv4(127, 0, 0, 1), true}, {"127.0.0.1", net.IPv4(127, 0, 0, 1), true},
@@ -181,7 +181,7 @@ func TestIsOwnIP(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got, _ := IsOwnIP(tt.ip); got != tt.want { if got, _ := IsOwnIP(tt.ip); got != tt.want {
t.Errorf("IsOwnIP() = %v, want %v", got, tt.want) t.Errorf("IsOwnIP() = %v, want %v", got, tt.want)
t.Errorf(tt.ip.String()); t.Errorf(tt.ip.String())
} }
}) })
} }

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

@@ -194,41 +194,37 @@ func (s SqlTeamStore) Save(team *model.Team) store.StoreChannel {
}) })
} }
func (s SqlTeamStore) Update(team *model.Team) store.StoreChannel { func (s SqlTeamStore) Update(team *model.Team) (*model.Team, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
team.PreUpdate()
if result.Err = team.IsValid(); result.Err != nil { team.PreUpdate()
return
}
oldResult, err := s.GetMaster().Get(model.Team{}, team.Id) if err := team.IsValid(); err != nil {
if err != nil { return nil, err
result.Err = model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.finding.app_error", nil, "id="+team.Id+", "+err.Error(), http.StatusInternalServerError) }
return
}
if oldResult == nil { oldResult, err := s.GetMaster().Get(model.Team{}, team.Id)
result.Err = model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.find.app_error", nil, "id="+team.Id, http.StatusBadRequest) if err != nil {
return return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.finding.app_error", nil, "id="+team.Id+", "+err.Error(), http.StatusInternalServerError)
}
oldTeam := oldResult.(*model.Team) }
team.CreateAt = oldTeam.CreateAt
team.UpdateAt = model.GetMillis()
count, err := s.GetMaster().Update(team) if oldResult == nil {
if err != nil { return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.find.app_error", nil, "id="+team.Id, http.StatusBadRequest)
result.Err = model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.updating.app_error", nil, "id="+team.Id+", "+err.Error(), http.StatusInternalServerError) }
return
}
if count != 1 {
result.Err = model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.app_error", nil, "id="+team.Id, http.StatusInternalServerError)
return
}
result.Data = team oldTeam := oldResult.(*model.Team)
}) team.CreateAt = oldTeam.CreateAt
team.UpdateAt = model.GetMillis()
count, err := s.GetMaster().Update(team)
if err != nil {
return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.updating.app_error", nil, "id="+team.Id+", "+err.Error(), http.StatusInternalServerError)
}
if count != 1 {
return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.app_error", nil, "id="+team.Id, http.StatusInternalServerError)
}
return team, nil
} }
func (s SqlTeamStore) UpdateDisplayName(name string, teamId string) store.StoreChannel { func (s SqlTeamStore) UpdateDisplayName(name string, teamId string) store.StoreChannel {

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

@@ -82,7 +82,7 @@ type Store interface {
type TeamStore interface { type TeamStore interface {
Save(team *model.Team) StoreChannel Save(team *model.Team) StoreChannel
Update(team *model.Team) StoreChannel Update(team *model.Team) (*model.Team, *model.AppError)
UpdateDisplayName(name string, teamId string) StoreChannel UpdateDisplayName(name string, teamId string) StoreChannel
Get(id string) StoreChannel Get(id string) StoreChannel
GetByName(name string) StoreChannel GetByName(name string) StoreChannel

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

@@ -1011,16 +1011,16 @@ func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
// No result if Team deleted // No result if Team deleted
team.DeleteAt = model.GetMillis() team.DeleteAt = model.GetMillis()
res = <-ss.Team().Update(team) team, err := ss.Team().Update(team)
require.Nil(t, res.Err) require.Nil(t, err)
res = <-ss.Group().TeamMembersToAdd(0) res = <-ss.Group().TeamMembersToAdd(0)
require.Nil(t, res.Err) require.Nil(t, res.Err)
require.Len(t, res.Data, 0) require.Len(t, res.Data, 0)
// reset state of team and verify // reset state of team and verify
team.DeleteAt = 0 team.DeleteAt = 0
res = <-ss.Team().Update(team) team, err = ss.Team().Update(team)
require.Nil(t, res.Err) require.Nil(t, err)
res = <-ss.Group().TeamMembersToAdd(0) res = <-ss.Group().TeamMembersToAdd(0)
require.Nil(t, res.Err) require.Nil(t, res.Err)
require.Len(t, res.Data, 1) require.Len(t, res.Data, 1)

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

@@ -606,19 +606,28 @@ func (_m *TeamStore) SearchPrivate(term string) store.StoreChannel {
} }
// Update provides a mock function with given fields: team // Update provides a mock function with given fields: team
func (_m *TeamStore) Update(team *model.Team) store.StoreChannel { func (_m *TeamStore) Update(team *model.Team) (*model.Team, *model.AppError) {
ret := _m.Called(team) ret := _m.Called(team)
var r0 store.StoreChannel var r0 *model.Team
if rf, ok := ret.Get(0).(func(*model.Team) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(*model.Team) *model.Team); ok {
r0 = rf(team) r0 = rf(team)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.Team)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.Team) *model.AppError); ok {
r1 = rf(team)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// UpdateDisplayName provides a mock function with given fields: name, teamId // UpdateDisplayName provides a mock function with given fields: name, teamId

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

@@ -27,7 +27,7 @@ func TestTeamStore(t *testing.T, ss store.Store) {
t.Run("SearchAll", func(t *testing.T) { testTeamStoreSearchAll(t, ss) }) t.Run("SearchAll", func(t *testing.T) { testTeamStoreSearchAll(t, ss) })
t.Run("SearchOpen", func(t *testing.T) { testTeamStoreSearchOpen(t, ss) }) t.Run("SearchOpen", func(t *testing.T) { testTeamStoreSearchOpen(t, ss) })
t.Run("SearchPrivate", func(t *testing.T) { testTeamStoreSearchPrivate(t, ss) }) t.Run("SearchPrivate", func(t *testing.T) { testTeamStoreSearchPrivate(t, ss) })
t.Run("GetByIniviteId", func(t *testing.T) { testTeamStoreGetByIniviteId(t, ss) }) t.Run("GetByInviteId", func(t *testing.T) { testTeamStoreGetByInviteId(t, ss) })
t.Run("ByUserId", func(t *testing.T) { testTeamStoreByUserId(t, ss) }) t.Run("ByUserId", func(t *testing.T) { testTeamStoreByUserId(t, ss) })
t.Run("GetAllTeamListing", func(t *testing.T) { testGetAllTeamListing(t, ss) }) t.Run("GetAllTeamListing", func(t *testing.T) { testGetAllTeamListing(t, ss) })
t.Run("GetAllTeamPageListing", func(t *testing.T) { testGetAllTeamPageListing(t, ss) }) t.Run("GetAllTeamPageListing", func(t *testing.T) { testGetAllTeamPageListing(t, ss) })
@@ -86,17 +86,17 @@ func testTeamStoreUpdate(t *testing.T, ss store.Store) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if err := (<-ss.Team().Update(&o1)).Err; err != nil { if _, err := ss.Team().Update(&o1); err != nil {
t.Fatal(err) t.Fatal(err)
} }
o1.Id = "missing" o1.Id = "missing"
if err := (<-ss.Team().Update(&o1)).Err; err == nil { if _, err := ss.Team().Update(&o1); err == nil {
t.Fatal("Update should have failed because of missing key") t.Fatal("Update should have failed because of missing key")
} }
o1.Id = model.NewId() o1.Id = model.NewId()
if err := (<-ss.Team().Update(&o1)).Err; err == nil { if _, err := ss.Team().Update(&o1); err == nil {
t.Fatal("Update should have faile because id change") t.Fatal("Update should have faile because id change")
} }
} }
@@ -385,7 +385,7 @@ func testTeamStoreSearchPrivate(t *testing.T, ss store.Store) {
} }
} }
func testTeamStoreGetByIniviteId(t *testing.T, ss store.Store) { func testTeamStoreGetByInviteId(t *testing.T, ss store.Store) {
o1 := model.Team{} o1 := model.Team{}
o1.DisplayName = "DisplayName" o1.DisplayName = "DisplayName"
o1.Name = "z-z-z" + model.NewId() + "b" o1.Name = "z-z-z" + model.NewId() + "b"
@@ -416,7 +416,8 @@ func testTeamStoreGetByIniviteId(t *testing.T, ss store.Store) {
} }
o2.InviteId = "" o2.InviteId = ""
<-ss.Team().Update(&o2) _, err := ss.Team().Update(&o2)
require.Nil(t, err)
if r1 := <-ss.Team().GetByInviteId(o2.Id); r1.Err != nil { if r1 := <-ss.Team().GetByInviteId(o2.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)

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

@@ -3513,8 +3513,8 @@ func testUserStoreGetTeamGroupUsers(t *testing.T, ss store.Store) {
// update team to be group-constrained // update team to be group-constrained
team.GroupConstrained = model.NewBool(true) team.GroupConstrained = model.NewBool(true)
res = <-ss.Team().Update(team) team, err := ss.Team().Update(team)
require.Nil(t, res.Err) require.Nil(t, err)
// still returns user (being group-constrained has no effect) // still returns user (being group-constrained has no effect)
requireNUsers(1) requireNUsers(1)

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

@@ -13,7 +13,7 @@ var mainHelper *testlib.MainHelper
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var options = testlib.HelperOptions{ var options = testlib.HelperOptions{
EnableStore: true, EnableStore: true,
EnableResources: true, EnableResources: true,
} }