From ecefa6cdd1e7376046bbec82c1b47f7756fea646 Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Mon, 25 Jun 2018 18:12:59 +0200 Subject: Implementation of File Exists Function; Delete FileInfos upon Permanent User Delete (#8958) Check if file was deleted on FS Warning message if file couldnt be removed --- store/storetest/file_info_store.go | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'store/storetest/file_info_store.go') diff --git a/store/storetest/file_info_store.go b/store/storetest/file_info_store.go index 9b3388db5..50b5cf059 100644 --- a/store/storetest/file_info_store.go +++ b/store/storetest/file_info_store.go @@ -15,10 +15,12 @@ func TestFileInfoStore(t *testing.T, ss store.Store) { t.Run("FileInfoSaveGet", func(t *testing.T) { testFileInfoSaveGet(t, ss) }) t.Run("FileInfoSaveGetByPath", func(t *testing.T) { testFileInfoSaveGetByPath(t, ss) }) t.Run("FileInfoGetForPost", func(t *testing.T) { testFileInfoGetForPost(t, ss) }) + t.Run("FileInfoGetForUser", func(t *testing.T) { testFileInfoGetForUser(t, ss) }) t.Run("FileInfoAttachToPost", func(t *testing.T) { testFileInfoAttachToPost(t, ss) }) t.Run("FileInfoDeleteForPost", func(t *testing.T) { testFileInfoDeleteForPost(t, ss) }) t.Run("FileInfoPermanentDelete", func(t *testing.T) { testFileInfoPermanentDelete(t, ss) }) t.Run("FileInfoPermanentDeleteBatch", func(t *testing.T) { testFileInfoPermanentDeleteBatch(t, ss) }) + t.Run("FileInfoPermanentDeleteByUser", func(t *testing.T) { testFileInfoPermanentDeleteByUser(t, ss) }) } func testFileInfoSaveGet(t *testing.T, ss store.Store) { @@ -153,6 +155,54 @@ func testFileInfoGetForPost(t *testing.T, ss store.Store) { } } +func testFileInfoGetForUser(t *testing.T, ss store.Store) { + userId := model.NewId() + userId2 := model.NewId() + postId := model.NewId() + + infos := []*model.FileInfo{ + { + PostId: postId, + CreatorId: userId, + Path: "file.txt", + }, + { + PostId: postId, + CreatorId: userId, + Path: "file.txt", + }, + { + PostId: postId, + CreatorId: userId, + Path: "file.txt", + }, + { + PostId: model.NewId(), + CreatorId: userId2, + Path: "file.txt", + }, + } + + for i, info := range infos { + infos[i] = store.Must(ss.FileInfo().Save(info)).(*model.FileInfo) + defer func(id string) { + <-ss.FileInfo().PermanentDelete(id) + }(infos[i].Id) + } + + if result := <-ss.FileInfo().GetForUser(userId); result.Err != nil { + t.Fatal(result.Err) + } else if returned := result.Data.([]*model.FileInfo); len(returned) != 3 { + t.Fatal("should've returned exactly 3 file infos") + } + + if result := <-ss.FileInfo().GetForUser(userId2); result.Err != nil { + t.Fatal(result.Err) + } else if returned := result.Data.([]*model.FileInfo); len(returned) != 1 { + t.Fatal("should've returned exactly 1 file infos") + } +} + func testFileInfoAttachToPost(t *testing.T, ss store.Store) { userId := model.NewId() postId := model.NewId() @@ -294,3 +344,18 @@ func testFileInfoPermanentDeleteBatch(t *testing.T, ss store.Store) { t.Fatal("Expected 3 fileInfos") } } + +func testFileInfoPermanentDeleteByUser(t *testing.T, ss store.Store) { + userId := model.NewId() + postId := model.NewId() + + store.Must(ss.FileInfo().Save(&model.FileInfo{ + PostId: postId, + CreatorId: userId, + Path: "file.txt", + })) + + if result := <-ss.FileInfo().PermanentDeleteByUser(userId); result.Err != nil { + t.Fatal(result.Err) + } +} -- cgit v1.2.3-1-g7c22