коммит произвёл
GitHub
родитель
5ddf8d4099
Коммит
48f0b7fd76
@@ -2421,7 +2421,7 @@ func (s *OpenTracingLayerClusterDiscoveryStore) SetLastPingAt(discovery *model.C
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.AnalyticsCommandCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2439,7 +2439,7 @@ func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) *model.AppError {
|
||||
func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Delete")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2457,7 +2457,7 @@ func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) *mod
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2475,7 +2475,7 @@ func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, *model.Ap
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTeam")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2493,7 +2493,7 @@ func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Comman
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTrigger")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2511,7 +2511,7 @@ func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger strin
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByTeam")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2529,7 +2529,7 @@ func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) *mod
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2547,7 +2547,7 @@ func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) *mod
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Command, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Save")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2565,7 +2565,7 @@ func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Comm
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerCommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s *OpenTracingLayerCommandStore) Update(hook *model.Command) (*model.Command, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Update")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"database/sql"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SqlCommandStore struct {
|
||||
@@ -51,9 +52,9 @@ func (s SqlCommandStore) createIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_command_delete_at", "Commands", "DeleteAt")
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s SqlCommandStore) Save(command *model.Command) (*model.Command, error) {
|
||||
if len(command.Id) > 0 {
|
||||
return nil, model.NewAppError("SqlCommandStore.Save", "store.sql_command.save.saving_overwrite.app_error", nil, "id="+command.Id, http.StatusBadRequest)
|
||||
return nil, store.NewErrInvalidInput("Command", "CommandId", command.Id)
|
||||
}
|
||||
|
||||
command.PreSave()
|
||||
@@ -62,42 +63,45 @@ func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.Ap
|
||||
}
|
||||
|
||||
if err := s.GetMaster().Insert(command); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.Save", "store.sql_command.save.saving.app_error", nil, "id="+command.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "insert: command_id=%s", command.Id)
|
||||
}
|
||||
|
||||
return command, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||
func (s SqlCommandStore) Get(id string) (*model.Command, error) {
|
||||
var command model.Command
|
||||
|
||||
sql, args, err := s.commandsQuery.
|
||||
query, args, err := s.commandsQuery.
|
||||
Where(sq.Eq{"Id": id, "DeleteAt": 0}).ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
if err = s.GetReplica().SelectOne(&command, sql, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.save.get.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
|
||||
if err = s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Command", id)
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrapf(err, "selectone: command_id=%s", id)
|
||||
}
|
||||
|
||||
return &command, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
|
||||
var commands []*model.Command
|
||||
|
||||
sql, args, err := s.commandsQuery.
|
||||
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0}).ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
if _, err := s.GetReplica().Select(&commands, sql, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "select: team_id=%s", teamId)
|
||||
}
|
||||
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
|
||||
var command model.Command
|
||||
var triggerStr string
|
||||
if s.DriverName() == "mysql" {
|
||||
@@ -106,66 +110,69 @@ func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Com
|
||||
triggerStr = "\"trigger\""
|
||||
}
|
||||
|
||||
sql, args, err := s.commandsQuery.
|
||||
query, args, err := s.commandsQuery.
|
||||
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0, triggerStr: trigger}).ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&command, sql, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql_command.get_by_trigger.app_error", nil, "teamId="+teamId+", trigger="+trigger+", err="+err.Error(), http.StatusInternalServerError)
|
||||
if err := s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
|
||||
errorId := "teamId=" + teamId + ", trigger=" + trigger
|
||||
return nil, store.NewErrNotFound("Command", errorId)
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrapf(err, "selectone: team_id=%s, trigger=%s", teamId, trigger)
|
||||
}
|
||||
|
||||
return &command, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) Delete(commandId string, time int64) *model.AppError {
|
||||
func (s SqlCommandStore) Delete(commandId string, time int64) error {
|
||||
sql, args, err := s.getQueryBuilder().
|
||||
Update("Commands").
|
||||
SetMap(sq.Eq{"DeleteAt": time, "UpdateAt": time}).
|
||||
Where(sq.Eq{"Id": commandId}).ToSql()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.Delete", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.Delete", "store.sql_command.save.delete.app_error", nil, "id="+commandId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
errors.Wrapf(err, "delete: command_id=%s", commandId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) error {
|
||||
sql, args, err := s.getQueryBuilder().
|
||||
Delete("Commands").
|
||||
Where(sq.Eq{"TeamId": teamId}).ToSql()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.DeleteByTeam", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.DeleteByTeam", "store.sql_command.save.delete_perm.app_error", nil, "id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "delete: team_id=%s", teamId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s SqlCommandStore) PermanentDeleteByUser(userId string) error {
|
||||
sql, args, err := s.getQueryBuilder().
|
||||
Delete("Commands").
|
||||
Where(sq.Eq{"CreatorId": userId}).ToSql()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql_command.save.delete_perm.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "delete: user_id=%s", userId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, error) {
|
||||
cmd.UpdateAt = model.GetMillis()
|
||||
|
||||
if err := cmd.IsValid(); err != nil {
|
||||
@@ -173,13 +180,13 @@ func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppE
|
||||
}
|
||||
|
||||
if _, err := s.GetMaster().Update(cmd); err != nil {
|
||||
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "update: command_id=%s", cmd.Id)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select("COUNT(*)").
|
||||
From("Commands").
|
||||
@@ -191,12 +198,12 @@ func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.App
|
||||
|
||||
sql, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
|
||||
c, err := s.GetReplica().SelectInt(sql, args...)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "unable to count the commands: team_id=%s", teamId)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -476,15 +476,15 @@ type WebhookStore interface {
|
||||
}
|
||||
|
||||
type CommandStore interface {
|
||||
Save(webhook *model.Command) (*model.Command, *model.AppError)
|
||||
GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError)
|
||||
Get(id string) (*model.Command, *model.AppError)
|
||||
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
||||
Delete(commandId string, time int64) *model.AppError
|
||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
Update(hook *model.Command) (*model.Command, *model.AppError)
|
||||
AnalyticsCommandCount(teamId string) (int64, *model.AppError)
|
||||
Save(webhook *model.Command) (*model.Command, error)
|
||||
GetByTrigger(teamId string, trigger string) (*model.Command, error)
|
||||
Get(id string) (*model.Command, error)
|
||||
GetByTeam(teamId string) ([]*model.Command, error)
|
||||
Delete(commandId string, time int64) error
|
||||
PermanentDeleteByTeam(teamId string) error
|
||||
PermanentDeleteByUser(userId string) error
|
||||
Update(hook *model.Command) (*model.Command, error)
|
||||
AnalyticsCommandCount(teamId string) (int64, error)
|
||||
}
|
||||
|
||||
type CommandWebhookStore interface {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -32,10 +33,10 @@ func testCommandStoreSave(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
_, err := ss.Command().Save(&o1)
|
||||
require.Nil(t, err, "couldn't save item")
|
||||
_, nErr := ss.Command().Save(&o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().Save(&o1)
|
||||
_, err := ss.Command().Save(&o1)
|
||||
require.NotNil(t, err, "shouldn't be able to update from save")
|
||||
}
|
||||
|
||||
@@ -47,15 +48,17 @@ func testCommandStoreGet(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
|
||||
|
||||
_, err = ss.Command().Get("123")
|
||||
require.NotNil(t, err, "Mising id should have failed")
|
||||
_, err := ss.Command().Get("123")
|
||||
require.NotNil(t, err)
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
|
||||
@@ -66,16 +69,16 @@ func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().GetByTeam(o1.TeamId)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().GetByTeam(o1.TeamId)
|
||||
require.Nil(t, nErr)
|
||||
require.NotEmpty(t, r1, "no command returned")
|
||||
require.Equal(t, r1[0].CreateAt, o1.CreateAt, "invalid returned command")
|
||||
|
||||
result, err := ss.Command().GetByTeam("123")
|
||||
require.Nil(t, err)
|
||||
result, nErr := ss.Command().GetByTeam("123")
|
||||
require.Nil(t, nErr)
|
||||
require.Empty(t, result, "no commands should have returned")
|
||||
}
|
||||
|
||||
@@ -94,22 +97,24 @@ func testCommandStoreGetByTrigger(t *testing.T, ss store.Store) {
|
||||
o2.URL = "http://nowhere.com/"
|
||||
o2.Trigger = "trigger1"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().Save(o2)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Command().Save(o2)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
var r1 *model.Command
|
||||
r1, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
|
||||
require.Nil(t, err)
|
||||
r1, nErr = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r1.Id, o1.Id, "invalid returned command")
|
||||
|
||||
err = ss.Command().Delete(o1.Id, model.GetMillis())
|
||||
require.Nil(t, err)
|
||||
nErr = ss.Command().Delete(o1.Id, model.GetMillis())
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
|
||||
require.NotNil(t, err, "no commands should have returned")
|
||||
_, err := ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
|
||||
require.NotNil(t, err)
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testCommandStoreDelete(t *testing.T, ss store.Store) {
|
||||
@@ -120,18 +125,20 @@ func testCommandStoreDelete(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
|
||||
|
||||
err = ss.Command().Delete(o1.Id, model.GetMillis())
|
||||
require.Nil(t, err)
|
||||
nErr = ss.Command().Delete(o1.Id, model.GetMillis())
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err, "Missing id should have failed")
|
||||
_, err := ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err)
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
|
||||
@@ -142,18 +149,20 @@ func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
|
||||
|
||||
err = ss.Command().PermanentDeleteByTeam(o1.TeamId)
|
||||
require.Nil(t, err)
|
||||
nErr = ss.Command().PermanentDeleteByTeam(o1.TeamId)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err, "Missing id should have failed")
|
||||
_, err := ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err)
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
|
||||
@@ -164,18 +173,20 @@ func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().Get(o1.Id)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
|
||||
|
||||
err = ss.Command().PermanentDeleteByUser(o1.CreatorId)
|
||||
require.Nil(t, err)
|
||||
nErr = ss.Command().PermanentDeleteByUser(o1.CreatorId)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
_, err = ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err, "Missing id should have failed")
|
||||
_, err := ss.Command().Get(o1.Id)
|
||||
require.NotNil(t, err)
|
||||
var nfErr *store.ErrNotFound
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
}
|
||||
|
||||
func testCommandStoreUpdate(t *testing.T, ss store.Store) {
|
||||
@@ -186,18 +197,18 @@ func testCommandStoreUpdate(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
o1.Token = model.NewId()
|
||||
|
||||
_, err = ss.Command().Update(o1)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Command().Update(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
o1.URL = "junk"
|
||||
|
||||
_, err = ss.Command().Update(o1)
|
||||
require.NotNil(t, err, "should have failed - bad URL")
|
||||
_, err := ss.Command().Update(o1)
|
||||
require.NotNil(t, err)
|
||||
}
|
||||
|
||||
func testCommandCount(t *testing.T, ss store.Store) {
|
||||
@@ -208,14 +219,14 @@ func testCommandCount(t *testing.T, ss store.Store) {
|
||||
o1.URL = "http://nowhere.com/"
|
||||
o1.Trigger = "trigger"
|
||||
|
||||
o1, err := ss.Command().Save(o1)
|
||||
require.Nil(t, err)
|
||||
o1, nErr := ss.Command().Save(o1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
r1, err := ss.Command().AnalyticsCommandCount("")
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Command().AnalyticsCommandCount("")
|
||||
require.Nil(t, nErr)
|
||||
require.NotZero(t, r1, "should be at least 1 command")
|
||||
|
||||
r2, err := ss.Command().AnalyticsCommandCount(o1.TeamId)
|
||||
require.Nil(t, err)
|
||||
r2, nErr := ss.Command().AnalyticsCommandCount(o1.TeamId)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, r2, int64(1), "should be 1 command")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type CommandStore struct {
|
||||
}
|
||||
|
||||
// AnalyticsCommandCount provides a mock function with given fields: teamId
|
||||
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 int64
|
||||
@@ -25,36 +25,32 @@ func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppE
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: commandId, time
|
||||
func (_m *CommandStore) Delete(commandId string, time int64) *model.AppError {
|
||||
func (_m *CommandStore) Delete(commandId string, time int64) error {
|
||||
ret := _m.Called(commandId, time)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, int64) error); ok {
|
||||
r0 = rf(commandId, time)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id
|
||||
func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||
func (_m *CommandStore) Get(id string) (*model.Command, error) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 *model.Command
|
||||
@@ -66,20 +62,18 @@ func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(id)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByTeam provides a mock function with given fields: teamId
|
||||
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 []*model.Command
|
||||
@@ -91,20 +85,18 @@ func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppEr
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByTrigger provides a mock function with given fields: teamId, trigger
|
||||
func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
|
||||
ret := _m.Called(teamId, trigger)
|
||||
|
||||
var r0 *model.Command
|
||||
@@ -116,52 +108,46 @@ func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Comm
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(teamId, trigger)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByTeam provides a mock function with given fields: teamId
|
||||
func (_m *CommandStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
func (_m *CommandStore) PermanentDeleteByTeam(teamId string) error {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userId
|
||||
func (_m *CommandStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (_m *CommandStore) PermanentDeleteByUser(userId string) error {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: webhook
|
||||
func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, error) {
|
||||
ret := _m.Called(webhook)
|
||||
|
||||
var r0 *model.Command
|
||||
@@ -173,20 +159,18 @@ func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, *model.App
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
|
||||
r1 = rf(webhook)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Update provides a mock function with given fields: hook
|
||||
func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (_m *CommandStore) Update(hook *model.Command) (*model.Command, error) {
|
||||
ret := _m.Called(hook)
|
||||
|
||||
var r0 *model.Command
|
||||
@@ -198,13 +182,11 @@ func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppE
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
|
||||
r1 = rf(hook)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
|
||||
@@ -2225,7 +2225,7 @@ func (s *TimerLayerClusterDiscoveryStore) SetLastPingAt(discovery *model.Cluster
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.AnalyticsCommandCount(teamId)
|
||||
@@ -2241,7 +2241,7 @@ func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *m
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) Delete(commandId string, time int64) *model.AppError {
|
||||
func (s *TimerLayerCommandStore) Delete(commandId string, time int64) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.CommandStore.Delete(commandId, time)
|
||||
@@ -2257,7 +2257,7 @@ func (s *TimerLayerCommandStore) Delete(commandId string, time int64) *model.App
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) Get(id string) (*model.Command, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) Get(id string) (*model.Command, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.Get(id)
|
||||
@@ -2273,7 +2273,7 @@ func (s *TimerLayerCommandStore) Get(id string) (*model.Command, *model.AppError
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.GetByTeam(teamId)
|
||||
@@ -2289,7 +2289,7 @@ func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *mo
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.GetByTrigger(teamId, trigger)
|
||||
@@ -2305,7 +2305,7 @@ func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*m
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.CommandStore.PermanentDeleteByTeam(teamId)
|
||||
@@ -2321,7 +2321,7 @@ func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.App
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.CommandStore.PermanentDeleteByUser(userId)
|
||||
@@ -2337,7 +2337,7 @@ func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) *model.App
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.Save(webhook)
|
||||
@@ -2353,7 +2353,7 @@ func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, *
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerCommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) {
|
||||
func (s *TimerLayerCommandStore) Update(hook *model.Command) (*model.Command, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.CommandStore.Update(hook)
|
||||
|
||||
Ссылка в новой задаче
Block a user