diff options
author | George Goldberg <george@gberg.me> | 2017-08-25 15:38:13 +0100 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-08-25 10:38:13 -0400 |
commit | 50fc6e1e9e8d286fd6a406cef75e48a28f9427ad (patch) | |
tree | 0689de640729194b9a123ec8bfef36cbecd8cefd /app/file_test.go | |
parent | 99acf6106833a2186c0f7e07985feac5d9c25de1 (diff) | |
download | chat-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 'app/file_test.go')
-rw-r--r-- | app/file_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/file_test.go b/app/file_test.go index 683b574b8..962661039 100644 --- a/app/file_test.go +++ b/app/file_test.go @@ -4,9 +4,12 @@ package app import ( + "fmt" "testing" + "time" "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" ) func TestGeneratePublicLinkHash(t *testing.T) { @@ -31,3 +34,55 @@ func TestGeneratePublicLinkHash(t *testing.T) { t.Fatal("hashes for the same file with different salts should not be equal") } } + +func TestDoUploadFile(t *testing.T) { + Setup() + + teamId := model.NewId() + channelId := model.NewId() + userId := model.NewId() + filename := "test" + data := []byte("abcd") + + info1, err := DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data) + if err != nil { + t.Fatal(err) + } else { + defer func() { + <-Srv.Store.FileInfo().PermanentDelete(info1.Id) + utils.RemoveFile(info1.Path) + }() + } + + if info1.Path != fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info1.Id, filename) { + t.Fatal("stored file at incorrect path", info1.Path) + } + + info2, err := DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data) + if err != nil { + t.Fatal(err) + } else { + defer func() { + <-Srv.Store.FileInfo().PermanentDelete(info2.Id) + utils.RemoveFile(info2.Path) + }() + } + + if info2.Path != fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info2.Id, filename) { + t.Fatal("stored file at incorrect path", info2.Path) + } + + info3, err := DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data) + if err != nil { + t.Fatal(err) + } else { + defer func() { + <-Srv.Store.FileInfo().PermanentDelete(info3.Id) + utils.RemoveFile(info3.Path) + }() + } + + if info3.Path != fmt.Sprintf("20080305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info3.Id, filename) { + t.Fatal("stored file at incorrect path", info3.Path) + } +} |