From 1f6c271b3bedd6656ae7155714423b1b39a669c1 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 16 May 2018 13:43:22 -0400 Subject: 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 --- app/file_test.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'app/file_test.go') 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)) +} -- cgit v1.2.3-1-g7c22