PLT-4938 Add app package and move logic over from api package (#4931)

* Add app package and move logic over from api package

* Change app package functions to return errors

* Move non-api tests into app package

* Fix merge
Этот коммит содержится в:
Joram Wilander
2017-01-13 13:53:37 -05:00
коммит произвёл GitHub
родитель 07bad4d6d5
Коммит 97558f6a6e
85 изменённых файлов: 3368 добавлений и 2997 удалений

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

@@ -14,6 +14,7 @@ import (
"testing"
"time"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
@@ -59,7 +60,7 @@ func TestUploadFile(t *testing.T) {
}
var info *model.FileInfo
if result := <-Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil {
if result := <-app.Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil {
t.Fatal(result.Err)
} else {
info = result.Data.(*model.FileInfo)
@@ -154,7 +155,7 @@ func TestGetFileInfo(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// Other user shouldn't be able to get file info for this file if they're not in the channel for it
if _, err := Client.GetFileInfo(fileId); err == nil {
@@ -170,7 +171,7 @@ func TestGetFileInfo(t *testing.T) {
t.Fatal("other user got incorrect file")
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -223,7 +224,7 @@ func TestGetFile(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// Other user shouldn't be able to get file for this file if they're not in the channel for it
if _, err := Client.GetFile(fileId); err == nil {
@@ -252,7 +253,7 @@ func TestGetFile(t *testing.T) {
body.Close()
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -292,7 +293,7 @@ func TestGetFileThumbnail(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// Other user shouldn't be able to get thumbnail for this file if they're not in the channel for it
if _, err := Client.GetFileThumbnail(fileId); err == nil {
@@ -308,7 +309,7 @@ func TestGetFileThumbnail(t *testing.T) {
body.Close()
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -348,7 +349,7 @@ func TestGetFilePreview(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// Other user shouldn't be able to get preview for this file if they're not in the channel for it
if _, err := Client.GetFilePreview(fileId); err == nil {
@@ -364,7 +365,7 @@ func TestGetFilePreview(t *testing.T) {
body.Close()
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -397,7 +398,7 @@ func TestGetPublicFile(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
link := Client.MustGeneric(Client.GetPublicLink(fileId)).(string)
@@ -430,7 +431,7 @@ func TestGetPublicFile(t *testing.T) {
t.Fatal("should've failed to get image with public link after salt changed")
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -463,7 +464,7 @@ func TestGetPublicFileOld(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// reconstruct old style of link
siteURL := *utils.Cfg.ServiceSettings.SiteURL
@@ -501,7 +502,7 @@ func TestGetPublicFileOld(t *testing.T) {
t.Fatal("should've failed to get image with public link after salt changed")
}
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -540,7 +541,7 @@ func TestGetPublicLink(t *testing.T) {
}
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
utils.Cfg.FileSettings.EnablePublicLink = false
@@ -575,7 +576,7 @@ func TestGetPublicLink(t *testing.T) {
// Wait a bit for files to ready
time.Sleep(2 * time.Second)
if err := cleanupTestFile(store.Must(Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
}
@@ -631,7 +632,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
}
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
post1 := store.Must(Srv.Store.Post().Save(&model.Post{
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
UserId: user1.Id,
ChannelId: channel1.Id,
Message: "test",
@@ -732,7 +733,7 @@ func TestFindTeamIdForFilename(t *testing.T) {
}
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
post1 := store.Must(Srv.Store.Post().Save(&model.Post{
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
UserId: user1.Id,
ChannelId: channel1.Id,
Message: "test",
@@ -744,7 +745,7 @@ func TestFindTeamIdForFilename(t *testing.T) {
}
Client.SetTeamId(team2.Id)
post2 := store.Must(Srv.Store.Post().Save(&model.Post{
post2 := store.Must(app.Srv.Store.Post().Save(&model.Post{
UserId: user1.Id,
ChannelId: channel2.Id,
Message: "test",
@@ -781,13 +782,13 @@ func TestGetInfoForFilename(t *testing.T) {
t.Fatal(err)
} else {
fileId1 = Client.MustGeneric(Client.UploadPostAttachment(data, channel1.Id, "test.png")).(*model.FileUploadResponse).FileInfos[0].Id
path = store.Must(Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path
thumbnailPath = store.Must(Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath
previewPath = store.Must(Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath
path = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path
thumbnailPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath
previewPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath
}
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
post1 := store.Must(Srv.Store.Post().Save(&model.Post{
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
UserId: user1.Id,
ChannelId: channel1.Id,
Message: "test",