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)
|
hash2 := GeneratePublicLinkHash(filename2, salt1)
|
||||||
hash3 := GeneratePublicLinkHash(filename1, salt2)
|
hash3 := GeneratePublicLinkHash(filename1, salt2)
|
||||||
|
|
||||||
if hash1 != GeneratePublicLinkHash(filename1, salt1) {
|
hash := GeneratePublicLinkHash(filename1, salt1)
|
||||||
t.Fatal("hash should be equal for the same file name and salt")
|
assert.Equal(t, hash, hash1, "hash should be equal for the same file name and salt")
|
||||||
}
|
|
||||||
|
|
||||||
if hash1 == hash2 {
|
assert.NotEqual(t, hash1, hash2, "hashes for different files should not be equal")
|
||||||
t.Fatal("hashes for different files should not be equal")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hash1 == hash3 {
|
assert.NotEqual(t, hash1, hash3, "hashes for the same file with different salts should not be equal")
|
||||||
t.Fatal("hashes for the same file with different salts should not be equal")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoUploadFile(t *testing.T) {
|
func TestDoUploadFile(t *testing.T) {
|
||||||
@@ -51,60 +46,44 @@ func TestDoUploadFile(t *testing.T) {
|
|||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||||
if err != nil {
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info1.Path)
|
||||||
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) {
|
value := 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)
|
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)
|
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||||
if err != nil {
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info2.Path)
|
||||||
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) {
|
value = 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)
|
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)
|
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||||
if err != nil {
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info3.Path)
|
||||||
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) {
|
value = 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)
|
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)
|
info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamId, "../../"+channelId, "../../"+userId, "../../"+filename, data)
|
||||||
if err != nil {
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info4.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info4.Path)
|
||||||
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) {
|
value = 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)
|
assert.Equal(t, value, info4.Path, "stored file at incorrect path")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUploadFile(t *testing.T) {
|
func TestUploadFile(t *testing.T) {
|
||||||
@@ -116,19 +95,15 @@ func TestUploadFile(t *testing.T) {
|
|||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.UploadFile(data, channelId, filename)
|
info1, err := th.App.UploadFile(data, channelId, filename)
|
||||||
if err != nil {
|
require.Nil(t, err, "UploadFile should succeed with valid data")
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info1.Path)
|
||||||
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",
|
value := fmt.Sprintf("%v/teams/noteam/channels/%v/users/nouser/%v/%v",
|
||||||
time.Now().Format("20060102"), channelId, info1.Id, filename) {
|
time.Now().Format("20060102"), channelId, info1.Id, filename)
|
||||||
t.Fatal("stored file at incorrect path", info1.Path)
|
assert.Equal(t, value, info1.Path, "Stored file at incorrect path")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInfoForFilename(t *testing.T) {
|
func TestGetInfoForFilename(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user