Remove remaining t.Fatal from the codebase (#13876)
* Remove remaining t.Fatal from the codebase * Fix job_store test * Address review comments * Remove comments
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
17523fa5d9
Коммит
84f45634a8
@@ -206,21 +206,20 @@ func testEmojiGetList(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}()
|
||||
|
||||
if result, err := ss.Emoji().GetList(0, 100, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
for _, emoji := range emojis {
|
||||
found := false
|
||||
result, err := ss.Emoji().GetList(0, 100, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
for _, savedEmoji := range result {
|
||||
if emoji.Id == savedEmoji.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
for _, emoji := range emojis {
|
||||
found := false
|
||||
|
||||
for _, savedEmoji := range result {
|
||||
if emoji.Id == savedEmoji.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
||||
require.Truef(t, found, "failed to get emoji with id %v", emoji.Id)
|
||||
}
|
||||
|
||||
require.Truef(t, found, "failed to get emoji with id %v", emoji.Id)
|
||||
}
|
||||
|
||||
remojis, err := ss.Emoji().GetList(0, 3, model.EMOJI_SORT_BY_NAME)
|
||||
|
||||
@@ -44,13 +44,10 @@ func testJobSaveGet(t *testing.T, ss store.Store) {
|
||||
|
||||
defer ss.Job().Delete(job.Id)
|
||||
|
||||
if received, err := ss.Job().Get(job.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if received.Id != job.Id {
|
||||
t.Fatal("received incorrect job after save")
|
||||
} else if received.Data["Total"] != "12345" {
|
||||
t.Fatal("data field was not retrieved successfully:", received.Data)
|
||||
}
|
||||
received, err := ss.Job().Get(job.Id)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, job.Id, received.Id, "received incorrect job after save")
|
||||
require.Equal(t, "12345", received.Data["Total"])
|
||||
}
|
||||
|
||||
func testJobGetAllByType(t *testing.T, ss store.Store) {
|
||||
@@ -77,15 +74,10 @@ func testJobGetAllByType(t *testing.T, ss store.Store) {
|
||||
defer ss.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
if received, err := ss.Job().GetAllByType(jobType); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[0].Id && received[1].Id != jobs[0].Id {
|
||||
t.Fatal("should've received first jobs")
|
||||
} else if received[0].Id != jobs[1].Id && received[1].Id != jobs[1].Id {
|
||||
t.Fatal("should've received second jobs")
|
||||
}
|
||||
received, err := ss.Job().GetAllByType(jobType)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2)
|
||||
require.ElementsMatch(t, []string{jobs[0].Id, jobs[1].Id}, []string{received[0].Id, received[1].Id})
|
||||
}
|
||||
|
||||
func testJobGetAllByTypePage(t *testing.T, ss store.Store) {
|
||||
@@ -120,23 +112,16 @@ func testJobGetAllByTypePage(t *testing.T, ss store.Store) {
|
||||
defer ss.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
if received, err := ss.Job().GetAllByTypePage(jobType, 0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[2].Id {
|
||||
t.Fatal("should've received newest job first")
|
||||
} else if received[1].Id != jobs[0].Id {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
received, err := ss.Job().GetAllByTypePage(jobType, 0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2)
|
||||
require.Equal(t, received[0].Id, jobs[2].Id, "should've received newest job first")
|
||||
require.Equal(t, received[1].Id, jobs[0].Id, "should've received second newest job second")
|
||||
|
||||
if received, err := ss.Job().GetAllByTypePage(jobType, 2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[1].Id {
|
||||
t.Fatal("should've received oldest job last")
|
||||
}
|
||||
received, err = ss.Job().GetAllByTypePage(jobType, 2, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 1)
|
||||
require.Equal(t, received[0].Id, jobs[1].Id, "should've received oldest job last")
|
||||
}
|
||||
|
||||
func testJobGetAllPage(t *testing.T, ss store.Store) {
|
||||
@@ -167,23 +152,16 @@ func testJobGetAllPage(t *testing.T, ss store.Store) {
|
||||
defer ss.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
if received, err := ss.Job().GetAllPage(0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[2].Id {
|
||||
t.Fatal("should've received newest job first")
|
||||
} else if received[1].Id != jobs[0].Id {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
received, err := ss.Job().GetAllPage(0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2)
|
||||
require.Equal(t, received[0].Id, jobs[2].Id, "should've received newest job first")
|
||||
require.Equal(t, received[1].Id, jobs[0].Id, "should've received second newest job second")
|
||||
|
||||
if received, err := ss.Job().GetAllPage(2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) < 1 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[1].Id {
|
||||
t.Fatal("should've received oldest job last")
|
||||
}
|
||||
received, err = ss.Job().GetAllPage(2, 2)
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, received)
|
||||
require.Equal(t, received[0].Id, jobs[1].Id, "should've received oldest job last")
|
||||
}
|
||||
|
||||
func testJobGetAllByStatus(t *testing.T, ss store.Store) {
|
||||
@@ -226,15 +204,13 @@ func testJobGetAllByStatus(t *testing.T, ss store.Store) {
|
||||
defer ss.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
if received, err := ss.Job().GetAllByStatus(status); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 3 {
|
||||
t.Fatal("received wrong number of jobs")
|
||||
} else if received[0].Id != jobs[1].Id || received[1].Id != jobs[0].Id || received[2].Id != jobs[2].Id {
|
||||
t.Fatal("should've received jobs ordered by CreateAt time")
|
||||
} else if received[1].Data["test"] != "data" {
|
||||
t.Fatal("should've received job data field back as saved")
|
||||
}
|
||||
received, err := ss.Job().GetAllByStatus(status)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 3)
|
||||
require.Equal(t, received[0].Id, jobs[1].Id)
|
||||
require.Equal(t, received[1].Id, jobs[0].Id)
|
||||
require.Equal(t, received[2].Id, jobs[2].Id)
|
||||
require.Equal(t, "data", received[1].Data["test"], "should've received job data field back as saved")
|
||||
}
|
||||
|
||||
func testJobStoreGetNewestJobByStatusAndType(t *testing.T, ss store.Store) {
|
||||
@@ -360,24 +336,24 @@ func testJobUpdateOptimistically(t *testing.T, ss store.Store) {
|
||||
"Foo": "Bar",
|
||||
}
|
||||
|
||||
if updated, err2 := ss.Job().UpdateOptimistically(job, model.JOB_STATUS_SUCCESS); err2 != nil {
|
||||
if updated {
|
||||
t.Fatal("should have failed due to incorrect old status")
|
||||
}
|
||||
}
|
||||
updated, err := ss.Job().UpdateOptimistically(job, model.JOB_STATUS_SUCCESS)
|
||||
require.False(t, err != nil && updated)
|
||||
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
updated, err := ss.Job().UpdateOptimistically(job, model.JOB_STATUS_PENDING)
|
||||
updated, err = ss.Job().UpdateOptimistically(job, model.JOB_STATUS_PENDING)
|
||||
require.Nil(t, err)
|
||||
require.True(t, updated)
|
||||
|
||||
updatedJob, err := ss.Job().Get(job.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
if updatedJob.Type != job.Type || updatedJob.CreateAt != job.CreateAt || updatedJob.Status != job.Status || updatedJob.LastActivityAt <= job.LastActivityAt || updatedJob.Progress != job.Progress || updatedJob.Data["Foo"] != job.Data["Foo"] {
|
||||
t.Fatal("Some update property was not as expected")
|
||||
}
|
||||
require.Equal(t, updatedJob.Type, job.Type)
|
||||
require.Equal(t, updatedJob.CreateAt, job.CreateAt)
|
||||
require.Equal(t, updatedJob.Status, job.Status)
|
||||
require.Greater(t, updatedJob.LastActivityAt, job.LastActivityAt)
|
||||
require.Equal(t, updatedJob.Progress, job.Progress)
|
||||
require.Equal(t, updatedJob.Data["Foo"], job.Data["Foo"])
|
||||
}
|
||||
|
||||
func testJobUpdateStatusUpdateStatusOptimistically(t *testing.T, ss store.Store) {
|
||||
@@ -400,12 +376,8 @@ func testJobUpdateStatusUpdateStatusOptimistically(t *testing.T, ss store.Store)
|
||||
received, err = ss.Job().UpdateStatus(job.Id, model.JOB_STATUS_PENDING)
|
||||
require.Nil(t, err)
|
||||
|
||||
if received.Status != model.JOB_STATUS_PENDING {
|
||||
t.Fatal("status wasn't updated")
|
||||
}
|
||||
if received.LastActivityAt <= lastUpdateAt {
|
||||
t.Fatal("lastActivityAt wasn't updated")
|
||||
}
|
||||
require.Equal(t, model.JOB_STATUS_PENDING, received.Status)
|
||||
require.Greater(t, received.LastActivityAt, lastUpdateAt)
|
||||
lastUpdateAt = received.LastActivityAt
|
||||
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
@@ -417,12 +389,8 @@ func testJobUpdateStatusUpdateStatusOptimistically(t *testing.T, ss store.Store)
|
||||
received, err = ss.Job().Get(job.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
if received.Status != model.JOB_STATUS_PENDING {
|
||||
t.Fatal("should still be pending")
|
||||
}
|
||||
if received.LastActivityAt != lastUpdateAt {
|
||||
t.Fatal("last activity at shouldn't have changed")
|
||||
}
|
||||
require.Equal(t, model.JOB_STATUS_PENDING, received.Status)
|
||||
require.Equal(t, received.LastActivityAt, lastUpdateAt)
|
||||
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
@@ -433,15 +401,9 @@ func testJobUpdateStatusUpdateStatusOptimistically(t *testing.T, ss store.Store)
|
||||
var startAtSet int64
|
||||
received, err = ss.Job().Get(job.Id)
|
||||
require.Nil(t, err)
|
||||
if received.Status != model.JOB_STATUS_IN_PROGRESS {
|
||||
t.Fatal("should be in progress")
|
||||
}
|
||||
if received.StartAt == 0 {
|
||||
t.Fatal("received should have start at set")
|
||||
}
|
||||
if received.LastActivityAt <= lastUpdateAt {
|
||||
t.Fatal("lastActivityAt wasn't updated")
|
||||
}
|
||||
require.Equal(t, model.JOB_STATUS_IN_PROGRESS, received.Status)
|
||||
require.NotEqual(t, 0, received.StartAt)
|
||||
require.Greater(t, received.LastActivityAt, lastUpdateAt)
|
||||
lastUpdateAt = received.LastActivityAt
|
||||
startAtSet = received.StartAt
|
||||
|
||||
@@ -453,15 +415,9 @@ func testJobUpdateStatusUpdateStatusOptimistically(t *testing.T, ss store.Store)
|
||||
|
||||
received, err = ss.Job().Get(job.Id)
|
||||
require.Nil(t, err)
|
||||
if received.Status != model.JOB_STATUS_SUCCESS {
|
||||
t.Fatal("should be success status")
|
||||
}
|
||||
if received.StartAt != startAtSet {
|
||||
t.Fatal("startAt should not have changed")
|
||||
}
|
||||
if received.LastActivityAt <= lastUpdateAt {
|
||||
t.Fatal("lastActivityAt wasn't updated")
|
||||
}
|
||||
require.Equal(t, model.JOB_STATUS_SUCCESS, received.Status)
|
||||
require.Equal(t, startAtSet, received.StartAt)
|
||||
require.Greater(t, received.LastActivityAt, lastUpdateAt)
|
||||
}
|
||||
|
||||
func testJobDelete(t *testing.T, ss store.Store) {
|
||||
|
||||
Ссылка в новой задаче
Block a user