focalboard/server/services/store/storetests/files.go
Miguel de la Cruz 08c0b7a2fd
Refactor error usage from the store level up and add API helpers (#3792)
* Refactor error usage from the store level up and add API helpers

* Complete API tests

* Fix merge errorResponse calls

* Remove ensure helpers to allow for custom messages on permission errors

* Fix bad import and call

* Remove bad user check on auth that was added as part of the main merge

* Fix empty list test

* Replace deprecated proxy calls to ioutil.ReadAll with io.ReadAll

* Add information to the NotFound errors

* Add context to all remaining errors and address review comments

* Fix linter

* Adapt the new card API endpoints to the error refactor

* Remove almost all customErrorResponse calls

* Add request entity too large to errorResponse and remove customErrorResponse

* Fix linter
2022-09-13 12:18:40 +02:00

48 lines
1.4 KiB
Go

package storetests
import (
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/mattermost/focalboard/server/utils"
mmModel "github.com/mattermost/mattermost-server/v6/model"
"github.com/stretchr/testify/require"
)
func StoreTestFileStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
sqlStore, tearDown := setup(t)
defer tearDown()
t.Run("should save and retrieve fileinfo", func(t *testing.T) {
fileInfo := &mmModel.FileInfo{
Id: "file_info_1",
CreateAt: utils.GetMillis(),
Name: "Dunder Mifflin Sales Report 2022",
Extension: ".sales",
Size: 112233,
DeleteAt: 0,
}
err := sqlStore.SaveFileInfo(fileInfo)
require.NoError(t, err)
retrievedFileInfo, err := sqlStore.GetFileInfo("file_info_1")
require.NoError(t, err)
require.Equal(t, "file_info_1", retrievedFileInfo.Id)
require.Equal(t, "Dunder Mifflin Sales Report 2022", retrievedFileInfo.Name)
require.Equal(t, ".sales", retrievedFileInfo.Extension)
require.Equal(t, int64(112233), retrievedFileInfo.Size)
require.Equal(t, int64(0), retrievedFileInfo.DeleteAt)
require.False(t, retrievedFileInfo.Archived)
})
t.Run("should return an error on not found", func(t *testing.T) {
fileInfo, err := sqlStore.GetFileInfo("nonexistent")
require.Error(t, err)
var nf *model.ErrNotFound
require.ErrorAs(t, err, &nf)
require.Nil(t, fileInfo)
})
}