diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-16 16:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 16:53:21 +0800 |
commit | 81926d61db3dac223a75ea49eab893b25a089587 (patch) | |
tree | 627d2f19a008089f3a688e9a94a2cc8d2017afe2 /models/webhook | |
parent | 23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff) | |
download | gitea-81926d61db3dac223a75ea49eab893b25a089587.tar.gz gitea-81926d61db3dac223a75ea49eab893b25a089587.zip |
Decouple unit test, remove intermediate `unittestbridge` package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/webhook')
-rw-r--r-- | models/webhook/webhook_test.go | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/models/webhook/webhook_test.go b/models/webhook/webhook_test.go index 6d7957ba64..d1a76795fd 100644 --- a/models/webhook/webhook_test.go +++ b/models/webhook/webhook_test.go @@ -31,14 +31,14 @@ func TestIsValidHookContentType(t *testing.T) { func TestWebhook_History(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - webhook := db.AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) + webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) tasks, err := webhook.History(0) assert.NoError(t, err) if assert.Len(t, tasks, 1) { assert.Equal(t, int64(1), tasks[0].ID) } - webhook = db.AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) + webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) tasks, err = webhook.History(0) assert.NoError(t, err) assert.Len(t, tasks, 0) @@ -46,7 +46,7 @@ func TestWebhook_History(t *testing.T) { func TestWebhook_UpdateEvent(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - webhook := db.AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) + webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) hookEvent := &HookEvent{ PushOnly: true, SendEverything: false, @@ -92,9 +92,9 @@ func TestCreateWebhook(t *testing.T) { ContentType: ContentTypeJSON, Events: `{"push_only":false,"send_everything":false,"choose_events":false,"events":{"create":false,"push":true,"pull_request":true}}`, } - db.AssertNotExistsBean(t, hook) + unittest.AssertNotExistsBean(t, hook) assert.NoError(t, CreateWebhook(db.DefaultContext, hook)) - db.AssertExistsAndLoadBean(t, hook) + unittest.AssertExistsAndLoadBean(t, hook) } func TestGetWebhookByRepoID(t *testing.T) { @@ -103,7 +103,7 @@ func TestGetWebhookByRepoID(t *testing.T) { assert.NoError(t, err) assert.Equal(t, int64(1), hook.ID) - _, err = GetWebhookByRepoID(db.NonexistentID, db.NonexistentID) + _, err = GetWebhookByRepoID(unittest.NonexistentID, unittest.NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } @@ -114,7 +114,7 @@ func TestGetWebhookByOrgID(t *testing.T) { assert.NoError(t, err) assert.Equal(t, int64(3), hook.ID) - _, err = GetWebhookByOrgID(db.NonexistentID, db.NonexistentID) + _, err = GetWebhookByOrgID(unittest.NonexistentID, unittest.NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } @@ -161,32 +161,32 @@ func TestGetWebhooksByOrgID(t *testing.T) { func TestUpdateWebhook(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - hook := db.AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) + hook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) hook.IsActive = true hook.ContentType = ContentTypeForm - db.AssertNotExistsBean(t, hook) + unittest.AssertNotExistsBean(t, hook) assert.NoError(t, UpdateWebhook(hook)) - db.AssertExistsAndLoadBean(t, hook) + unittest.AssertExistsAndLoadBean(t, hook) } func TestDeleteWebhookByRepoID(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - db.AssertExistsAndLoadBean(t, &Webhook{ID: 2, RepoID: 1}) + unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2, RepoID: 1}) assert.NoError(t, DeleteWebhookByRepoID(1, 2)) - db.AssertNotExistsBean(t, &Webhook{ID: 2, RepoID: 1}) + unittest.AssertNotExistsBean(t, &Webhook{ID: 2, RepoID: 1}) - err := DeleteWebhookByRepoID(db.NonexistentID, db.NonexistentID) + err := DeleteWebhookByRepoID(unittest.NonexistentID, unittest.NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } func TestDeleteWebhookByOrgID(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - db.AssertExistsAndLoadBean(t, &Webhook{ID: 3, OrgID: 3}) + unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 3, OrgID: 3}) assert.NoError(t, DeleteWebhookByOrgID(3, 3)) - db.AssertNotExistsBean(t, &Webhook{ID: 3, OrgID: 3}) + unittest.AssertNotExistsBean(t, &Webhook{ID: 3, OrgID: 3}) - err := DeleteWebhookByOrgID(db.NonexistentID, db.NonexistentID) + err := DeleteWebhookByOrgID(unittest.NonexistentID, unittest.NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } @@ -199,7 +199,7 @@ func TestHookTasks(t *testing.T) { assert.Equal(t, int64(1), hookTasks[0].ID) } - hookTasks, err = HookTasks(db.NonexistentID, 1) + hookTasks, err = HookTasks(unittest.NonexistentID, 1) assert.NoError(t, err) assert.Len(t, hookTasks, 0) } @@ -211,21 +211,21 @@ func TestCreateHookTask(t *testing.T) { HookID: 3, Payloader: &api.PushPayload{}, } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) } func TestUpdateHookTask(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - hook := db.AssertExistsAndLoadBean(t, &HookTask{ID: 1}).(*HookTask) + hook := unittest.AssertExistsAndLoadBean(t, &HookTask{ID: 1}).(*HookTask) hook.PayloadContent = "new payload content" hook.DeliveredString = "new delivered string" hook.IsDelivered = true - db.AssertNotExistsBean(t, hook) + unittest.AssertNotExistsBean(t, hook) assert.NoError(t, UpdateHookTask(hook)) - db.AssertExistsAndLoadBean(t, hook) + unittest.AssertExistsAndLoadBean(t, hook) } func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) { @@ -237,12 +237,12 @@ func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) { IsDelivered: true, Delivered: time.Now().UnixNano(), } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0)) - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) } func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) { @@ -253,12 +253,12 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) { Payloader: &api.PushPayload{}, IsDelivered: false, } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) } func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) { @@ -270,12 +270,12 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) { IsDelivered: true, Delivered: time.Now().UnixNano(), } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 1)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) } func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) { @@ -287,12 +287,12 @@ func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) { IsDelivered: true, Delivered: time.Now().AddDate(0, 0, -8).UnixNano(), } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0)) - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) } func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) { @@ -303,12 +303,12 @@ func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) { Payloader: &api.PushPayload{}, IsDelivered: false, } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) } func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *testing.T) { @@ -320,10 +320,10 @@ func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *test IsDelivered: true, Delivered: time.Now().AddDate(0, 0, -6).UnixNano(), } - db.AssertNotExistsBean(t, hookTask) + unittest.AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0)) - db.AssertExistsAndLoadBean(t, hookTask) + unittest.AssertExistsAndLoadBean(t, hookTask) } |