summaryrefslogtreecommitdiffstats
path: root/store/sql_file_info_store_test.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-08-25 15:38:13 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2017-08-25 10:38:13 -0400
commit50fc6e1e9e8d286fd6a406cef75e48a28f9427ad (patch)
tree0689de640729194b9a123ec8bfef36cbecd8cefd /store/sql_file_info_store_test.go
parent99acf6106833a2186c0f7e07985feac5d9c25de1 (diff)
downloadchat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.tar.gz
chat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.tar.bz2
chat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.zip
PLT-???? Prepare file upload infrastructure for Data Retention. (#7266)
* Prepare file upload infrastructure for Data Retention. This commit prepares the file upload infrastructure for the data retention feature that is under construction. Changes are: * Move file management code to utils to allow access to it from jobs. * From now on, store all file uploads in a top level folder which is the date of the day on which they were uploaded. This commit is based on Harrison Healey's branch, but updated to work with the latest master. * Use NewAppError
Diffstat (limited to 'store/sql_file_info_store_test.go')
-rw-r--r--store/sql_file_info_store_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/store/sql_file_info_store_test.go b/store/sql_file_info_store_test.go
index daec06269..fecd862c0 100644
--- a/store/sql_file_info_store_test.go
+++ b/store/sql_file_info_store_test.go
@@ -25,6 +25,9 @@ func TestFileInfoSaveGet(t *testing.T) {
} else {
info = returned
}
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info.Id)
+ }()
if result := <-store.FileInfo().Get(info.Id); result.Err != nil {
t.Fatal(result.Err)
@@ -43,6 +46,9 @@ func TestFileInfoSaveGet(t *testing.T) {
if result := <-store.FileInfo().Get(info2.Id); result.Err == nil {
t.Fatal("shouldn't have gotten deleted file")
}
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info2.Id)
+ }()
}
func TestFileInfoSaveGetByPath(t *testing.T) {
@@ -60,6 +66,9 @@ func TestFileInfoSaveGetByPath(t *testing.T) {
} else {
info = returned
}
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info.Id)
+ }()
if result := <-store.FileInfo().GetByPath(info.Path); result.Err != nil {
t.Fatal(result.Err)
@@ -78,6 +87,9 @@ func TestFileInfoSaveGetByPath(t *testing.T) {
if result := <-store.FileInfo().GetByPath(info2.Id); result.Err == nil {
t.Fatal("shouldn't have gotten deleted file")
}
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info2.Id)
+ }()
}
func TestFileInfoGetForPost(t *testing.T) {
@@ -112,6 +124,9 @@ func TestFileInfoGetForPost(t *testing.T) {
for i, info := range infos {
infos[i] = Must(store.FileInfo().Save(info)).(*model.FileInfo)
+ defer func(id string) {
+ <-store.FileInfo().PermanentDelete(id)
+ }(infos[i].Id)
}
if result := <-store.FileInfo().GetForPost(postId, true, false); result.Err != nil {
@@ -143,6 +158,9 @@ func TestFileInfoAttachToPost(t *testing.T) {
CreatorId: userId,
Path: "file.txt",
})).(*model.FileInfo)
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info1.Id)
+ }()
if len(info1.PostId) != 0 {
t.Fatal("file shouldn't have a PostId")
@@ -162,6 +180,9 @@ func TestFileInfoAttachToPost(t *testing.T) {
CreatorId: userId,
Path: "file.txt",
})).(*model.FileInfo)
+ defer func() {
+ <-store.FileInfo().PermanentDelete(info2.Id)
+ }()
if result := <-store.FileInfo().AttachToPost(info2.Id, postId); result.Err != nil {
t.Fatal(result.Err)
@@ -208,6 +229,9 @@ func TestFileInfoDeleteForPost(t *testing.T) {
for i, info := range infos {
infos[i] = Must(store.FileInfo().Save(info)).(*model.FileInfo)
+ defer func(id string) {
+ <-store.FileInfo().PermanentDelete(id)
+ }(infos[i].Id)
}
if result := <-store.FileInfo().DeleteForPost(postId); result.Err != nil {
@@ -218,3 +242,17 @@ func TestFileInfoDeleteForPost(t *testing.T) {
t.Fatal("shouldn't have returned any file infos")
}
}
+
+func TestFileInfoPermanentDelete(t *testing.T) {
+ Setup()
+
+ info := Must(store.FileInfo().Save(&model.FileInfo{
+ PostId: model.NewId(),
+ CreatorId: model.NewId(),
+ Path: "file.txt",
+ })).(*model.FileInfo)
+
+ if result := <-store.FileInfo().PermanentDelete(info.Id); result.Err != nil {
+ t.Fatal(result.Err)
+ }
+}