From ef11df753227f3082d5c2226c0e7525e14ed47c7 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 08:44:05 -0600 Subject: PLT-7 adding loc db calls for webhooks table --- store/sql_webhook_store.go | 29 ++++++++------- store/sql_webhook_store_test.go | 81 +++++++++++++++++++++-------------------- store/store.go | 28 +++++++------- 3 files changed, 70 insertions(+), 68 deletions(-) (limited to 'store') diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go index b7bf0615f..8b1e8136b 100644 --- a/store/sql_webhook_store.go +++ b/store/sql_webhook_store.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) type SqlWebhookStore struct { @@ -43,7 +44,7 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() { s.CreateIndexIfNotExists("idx_outgoing_webhook_team_id", "OutgoingWebhooks", "TeamId") } -func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChannel { +func (s SqlWebhookStore) SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -77,7 +78,7 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChann return storeChannel } -func (s SqlWebhookStore) GetIncoming(id string) StoreChannel { +func (s SqlWebhookStore) GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -98,7 +99,7 @@ func (s SqlWebhookStore) GetIncoming(id string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChannel { +func (s SqlWebhookStore) DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -116,7 +117,7 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChann return storeChannel } -func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChannel { +func (s SqlWebhookStore) PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -134,7 +135,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChann return storeChannel } -func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel { +func (s SqlWebhookStore) GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -155,7 +156,7 @@ func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel { +func (s SqlWebhookStore) GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -176,7 +177,7 @@ func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel { +func (s SqlWebhookStore) SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -210,7 +211,7 @@ func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChann return storeChannel } -func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel { +func (s SqlWebhookStore) GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -231,7 +232,7 @@ func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel { +func (s SqlWebhookStore) GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -252,7 +253,7 @@ func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel { +func (s SqlWebhookStore) GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -273,7 +274,7 @@ func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel { +func (s SqlWebhookStore) GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -294,7 +295,7 @@ func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel { return storeChannel } -func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChannel { +func (s SqlWebhookStore) DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -312,7 +313,7 @@ func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChann return storeChannel } -func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChannel { +func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -330,7 +331,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChann return storeChannel } -func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel { +func (s SqlWebhookStore) UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel { storeChannel := make(StoreChannel) go func() { diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go index 1a9d5be3b..c5bd95af7 100644 --- a/store/sql_webhook_store_test.go +++ b/store/sql_webhook_store_test.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" "testing" ) @@ -16,11 +17,11 @@ func TestWebhookStoreSaveIncoming(t *testing.T) { o1.UserId = model.NewId() o1.TeamId = model.NewId() - if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err != nil { + if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err != nil { t.Fatal("couldn't save item", err) } - if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err == nil { + if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err == nil { t.Fatal("shouldn't be able to update from save") } } @@ -33,9 +34,9 @@ func TestWebhookStoreGetIncoming(t *testing.T) { o1.UserId = model.NewId() o1.TeamId = model.NewId() - o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook) - if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { @@ -43,7 +44,7 @@ func TestWebhookStoreGetIncoming(t *testing.T) { } } - if err := (<-store.Webhook().GetIncoming("123")).Err; err == nil { + if err := (<-store.Webhook().GetIncoming(utils.T, "123")).Err; err == nil { t.Fatal("Missing id should have failed") } } @@ -56,9 +57,9 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) { o1.UserId = model.NewId() o1.TeamId = model.NewId() - o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook) - if r1 := <-store.Webhook().GetIncomingByUser(o1.UserId); r1.Err != nil { + if r1 := <-store.Webhook().GetIncomingByUser(utils.T, o1.UserId); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt { @@ -66,7 +67,7 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) { } } - if result := <-store.Webhook().GetIncomingByUser("123"); result.Err != nil { + if result := <-store.Webhook().GetIncomingByUser(utils.T, "123"); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.IncomingWebhook)) != 0 { @@ -83,9 +84,9 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) { o1.UserId = model.NewId() o1.TeamId = model.NewId() - o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook) - if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { @@ -93,11 +94,11 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) { } } - if r2 := <-store.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); r2.Err != nil { + if r2 := <-store.Webhook().DeleteIncoming(utils.T, o1.Id, model.GetMillis()); r2.Err != nil { t.Fatal(r2.Err) } - if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil { + if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil { t.Log(r3.Data) t.Fatal("Missing id should have failed") } @@ -111,9 +112,9 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) { o1.UserId = model.NewId() o1.TeamId = model.NewId() - o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook) - if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { @@ -121,11 +122,11 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) { } } - if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(o1.UserId); r2.Err != nil { + if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(utils.T, o1.UserId); r2.Err != nil { t.Fatal(r2.Err) } - if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil { + if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil { t.Log(r3.Data) t.Fatal("Missing id should have failed") } @@ -140,11 +141,11 @@ func TestWebhookStoreSaveOutgoing(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err != nil { + if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err != nil { t.Fatal("couldn't save item", err) } - if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err == nil { + if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err == nil { t.Fatal("shouldn't be able to update from save") } } @@ -158,9 +159,9 @@ func TestWebhookStoreGetOutgoing(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { @@ -168,7 +169,7 @@ func TestWebhookStoreGetOutgoing(t *testing.T) { } } - if err := (<-store.Webhook().GetOutgoing("123")).Err; err == nil { + if err := (<-store.Webhook().GetOutgoing(utils.T, "123")).Err; err == nil { t.Fatal("Missing id should have failed") } } @@ -182,9 +183,9 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoingByChannel(utils.T, o1.ChannelId); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { @@ -192,7 +193,7 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) { } } - if result := <-store.Webhook().GetOutgoingByChannel("123"); result.Err != nil { + if result := <-store.Webhook().GetOutgoingByChannel(utils.T, "123"); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.OutgoingWebhook)) != 0 { @@ -210,9 +211,9 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoingByCreator(o1.CreatorId); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoingByCreator(utils.T, o1.CreatorId); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { @@ -220,7 +221,7 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) { } } - if result := <-store.Webhook().GetOutgoingByCreator("123"); result.Err != nil { + if result := <-store.Webhook().GetOutgoingByCreator(utils.T, "123"); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.OutgoingWebhook)) != 0 { @@ -238,9 +239,9 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoingByTeam(utils.T, o1.TeamId); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { @@ -248,7 +249,7 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) { } } - if result := <-store.Webhook().GetOutgoingByTeam("123"); result.Err != nil { + if result := <-store.Webhook().GetOutgoingByTeam(utils.T, "123"); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.OutgoingWebhook)) != 0 { @@ -266,9 +267,9 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { @@ -276,11 +277,11 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) { } } - if r2 := <-store.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil { + if r2 := <-store.Webhook().DeleteOutgoing(utils.T, o1.Id, model.GetMillis()); r2.Err != nil { t.Fatal(r2.Err) } - if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { + if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil { t.Log(r3.Data) t.Fatal("Missing id should have failed") } @@ -295,9 +296,9 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { @@ -305,11 +306,11 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) { } } - if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil { + if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(utils.T, o1.CreatorId); r2.Err != nil { t.Fatal(r2.Err) } - if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { + if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil { t.Log(r3.Data) t.Fatal("Missing id should have failed") } @@ -324,11 +325,11 @@ func TestWebhookStoreUpdateOutgoing(t *testing.T) { o1.TeamId = model.NewId() o1.CallbackURLs = []string{"http://nowhere.com/"} - o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) + o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook) o1.Token = model.NewId() - if r2 := <-store.Webhook().UpdateOutgoing(o1); r2.Err != nil { + if r2 := <-store.Webhook().UpdateOutgoing(utils.T, o1); r2.Err != nil { t.Fatal(r2.Err) } } diff --git a/store/store.go b/store/store.go index 58a9e0478..5b711fdc7 100644 --- a/store/store.go +++ b/store/store.go @@ -168,20 +168,20 @@ type SystemStore interface { } type WebhookStore interface { - SaveIncoming(webhook *model.IncomingWebhook) StoreChannel - GetIncoming(id string) StoreChannel - GetIncomingByUser(userId string) StoreChannel - GetIncomingByChannel(channelId string) StoreChannel - DeleteIncoming(webhookId string, time int64) StoreChannel - PermanentDeleteIncomingByUser(userId string) StoreChannel - SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel - GetOutgoing(id string) StoreChannel - GetOutgoingByCreator(userId string) StoreChannel - GetOutgoingByChannel(channelId string) StoreChannel - GetOutgoingByTeam(teamId string) StoreChannel - DeleteOutgoing(webhookId string, time int64) StoreChannel - PermanentDeleteOutgoingByUser(userId string) StoreChannel - UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel + SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel + GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel + GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel + GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel + DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel + PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel + SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel + GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel + GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel + GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel + GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel + DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel + PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel + UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel } type PreferenceStore interface { -- cgit v1.2.3-1-g7c22