fix: migrate the test to testify (#12158)
- convert all t.Fatal to testify require or assert
Этот коммит содержится в:
коммит произвёл
Miguel de la Cruz
родитель
890a7c6985
Коммит
43a068543c
105
app/file_test.go
105
app/file_test.go
@@ -27,17 +27,12 @@ func TestGeneratePublicLinkHash(t *testing.T) {
|
||||
hash2 := GeneratePublicLinkHash(filename2, salt1)
|
||||
hash3 := GeneratePublicLinkHash(filename1, salt2)
|
||||
|
||||
if hash1 != GeneratePublicLinkHash(filename1, salt1) {
|
||||
t.Fatal("hash should be equal for the same file name and salt")
|
||||
}
|
||||
hash := GeneratePublicLinkHash(filename1, salt1)
|
||||
assert.Equal(t, hash, hash1, "hash should be equal for the same file name and salt")
|
||||
|
||||
if hash1 == hash2 {
|
||||
t.Fatal("hashes for different files should not be equal")
|
||||
}
|
||||
assert.NotEqual(t, hash1, hash2, "hashes for different files should not be equal")
|
||||
|
||||
if hash1 == hash3 {
|
||||
t.Fatal("hashes for the same file with different salts should not be equal")
|
||||
}
|
||||
assert.NotEqual(t, hash1, hash3, "hashes for the same file with different salts should not be equal")
|
||||
}
|
||||
|
||||
func TestDoUploadFile(t *testing.T) {
|
||||
@@ -51,60 +46,44 @@ func TestDoUploadFile(t *testing.T) {
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := th.App.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() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
}
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.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)
|
||||
}
|
||||
value := fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info1.Id, filename)
|
||||
assert.Equal(t, value, info1.Path, "stored file at incorrect path" )
|
||||
|
||||
info2, err := th.App.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() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.RemoveFile(info2.Path)
|
||||
}()
|
||||
}
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.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)
|
||||
}
|
||||
value = fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info2.Id, filename)
|
||||
assert.Equal(t, value, info2.Path, "stored file at incorrect path")
|
||||
|
||||
info3, err := th.App.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() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
th.App.RemoveFile(info3.Path)
|
||||
}()
|
||||
}
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
th.App.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)
|
||||
}
|
||||
value = fmt.Sprintf("20080305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info3.Id, filename)
|
||||
assert.Equal(t, value, info3.Path, "stored file at incorrect path")
|
||||
|
||||
info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamId, "../../"+channelId, "../../"+userId, "../../"+filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info4.Id)
|
||||
th.App.RemoveFile(info4.Path)
|
||||
}()
|
||||
}
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info4.Id)
|
||||
th.App.RemoveFile(info4.Path)
|
||||
}()
|
||||
|
||||
if info4.Path != fmt.Sprintf("20090305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info4.Id, filename) {
|
||||
t.Fatal("stored file at incorrect path", info4.Path)
|
||||
}
|
||||
value = fmt.Sprintf("20090305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info4.Id, filename)
|
||||
assert.Equal(t, value, info4.Path, "stored file at incorrect path")
|
||||
}
|
||||
|
||||
func TestUploadFile(t *testing.T) {
|
||||
@@ -116,19 +95,15 @@ func TestUploadFile(t *testing.T) {
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := th.App.UploadFile(data, channelId, filename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
}
|
||||
require.Nil(t, err, "UploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
|
||||
if info1.Path != fmt.Sprintf("%v/teams/noteam/channels/%v/users/nouser/%v/%v",
|
||||
time.Now().Format("20060102"), channelId, info1.Id, filename) {
|
||||
t.Fatal("stored file at incorrect path", info1.Path)
|
||||
}
|
||||
value := fmt.Sprintf("%v/teams/noteam/channels/%v/users/nouser/%v/%v",
|
||||
time.Now().Format("20060102"), channelId, info1.Id, filename)
|
||||
assert.Equal(t, value, info1.Path, "Stored file at incorrect path")
|
||||
}
|
||||
|
||||
func TestGetInfoForFilename(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user