diff options
Diffstat (limited to 'models/webhook/webhook_test.go')
-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) } |