diff options
author | Joram Wilander <jwawilander@gmail.com> | 2018-05-16 13:43:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 13:43:22 -0400 |
commit | 1f6c271b3bedd6656ae7155714423b1b39a669c1 (patch) | |
tree | 9ce6390c237cc5f7c16d63addb4372033807cff8 /app/file_test.go | |
parent | 02f8c18f40cd0e973e4c75b751e8fcbbbd019728 (diff) | |
download | chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.gz chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.bz2 chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.zip |
MM-8708 Remove api package (#8784)
* Remove api package
* Remove api dependency from cmd package
* Remove EnableAPIv3 setting
* Update web tests
* Add more websocket tests
* Move some ws and oauth tests to api4 package
* Move command tests into api4 package
* Test fixes
* Fix msg command test
* Add some app file tests
Diffstat (limited to 'app/file_test.go')
-rw-r--r-- | app/file_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/file_test.go b/app/file_test.go index 204113782..23750ad6e 100644 --- a/app/file_test.go +++ b/app/file_test.go @@ -5,10 +5,16 @@ package app import ( "fmt" + "os" + "path/filepath" "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" ) func TestGeneratePublicLinkHash(t *testing.T) { @@ -100,3 +106,58 @@ func TestDoUploadFile(t *testing.T) { t.Fatal("stored file at incorrect path", info4.Path) } } + +func TestGetInfoForFilename(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + post := th.BasicPost + teamId := th.BasicTeam.Id + + info := th.App.GetInfoForFilename(post, teamId, "sometestfile") + assert.Nil(t, info, "Test bad filename") + + info = th.App.GetInfoForFilename(post, teamId, "/somechannel/someuser/someid/somefile.png") + assert.Nil(t, info, "Test non-existent file") +} + +func TestFindTeamIdForFilename(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + teamId := th.App.FindTeamIdForFilename(th.BasicPost, fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")) + assert.Equal(t, th.BasicTeam.Id, teamId) + + _, err := th.App.CreateTeamWithUser(&model.Team{Email: th.BasicUser.Email, Name: "zz" + model.NewId(), DisplayName: "Joram's Test Team", Type: model.TEAM_OPEN}, th.BasicUser.Id) + require.Nil(t, err) + + teamId = th.App.FindTeamIdForFilename(th.BasicPost, fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")) + assert.Equal(t, "", teamId) +} + +func TestMigrateFilenamesToFileInfos(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + post := th.BasicPost + infos := th.App.MigrateFilenamesToFileInfos(post) + assert.Equal(t, 0, len(infos)) + + post.Filenames = []string{fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")} + infos = th.App.MigrateFilenamesToFileInfos(post) + assert.Equal(t, 0, len(infos)) + + path, _ := utils.FindDir("tests") + file, fileErr := os.Open(filepath.Join(path, "test.png")) + require.Nil(t, fileErr) + defer file.Close() + + fpath := fmt.Sprintf("/teams/%v/channels/%v/users/%v/%v/test.png", th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, "someid") + _, err := th.App.WriteFile(file, fpath) + require.Nil(t, err) + rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")}}, th.BasicChannel, false) + require.Nil(t, err) + + infos = th.App.MigrateFilenamesToFileInfos(rpost) + assert.Equal(t, 1, len(infos)) +} |