forked from forgejo/forgejo
parent
ae419fa494
commit
76a85a4ce9
64 changed files with 250 additions and 242 deletions
|
@ -33,14 +33,14 @@ func TestIsValidHookContentType(t *testing.T) {
|
|||
func TestWebhook_History(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1})
|
||||
tasks, err := webhook.History(0)
|
||||
tasks, err := webhook.History(db.DefaultContext, 0)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, tasks, 1) {
|
||||
assert.Equal(t, int64(1), tasks[0].ID)
|
||||
}
|
||||
|
||||
webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2})
|
||||
tasks, err = webhook.History(0)
|
||||
tasks, err = webhook.History(db.DefaultContext, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, tasks, 0)
|
||||
}
|
||||
|
@ -101,22 +101,22 @@ func TestCreateWebhook(t *testing.T) {
|
|||
|
||||
func TestGetWebhookByRepoID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
hook, err := GetWebhookByRepoID(1, 1)
|
||||
hook, err := GetWebhookByRepoID(db.DefaultContext, 1, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(1), hook.ID)
|
||||
|
||||
_, err = GetWebhookByRepoID(unittest.NonexistentID, unittest.NonexistentID)
|
||||
_, err = GetWebhookByRepoID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrWebhookNotExist(err))
|
||||
}
|
||||
|
||||
func TestGetWebhookByOwnerID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
hook, err := GetWebhookByOwnerID(3, 3)
|
||||
hook, err := GetWebhookByOwnerID(db.DefaultContext, 3, 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(3), hook.ID)
|
||||
|
||||
_, err = GetWebhookByOwnerID(unittest.NonexistentID, unittest.NonexistentID)
|
||||
_, err = GetWebhookByOwnerID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrWebhookNotExist(err))
|
||||
}
|
||||
|
@ -167,17 +167,17 @@ func TestUpdateWebhook(t *testing.T) {
|
|||
hook.IsActive = true
|
||||
hook.ContentType = ContentTypeForm
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
assert.NoError(t, UpdateWebhook(hook))
|
||||
assert.NoError(t, UpdateWebhook(db.DefaultContext, hook))
|
||||
unittest.AssertExistsAndLoadBean(t, hook)
|
||||
}
|
||||
|
||||
func TestDeleteWebhookByRepoID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2, RepoID: 1})
|
||||
assert.NoError(t, DeleteWebhookByRepoID(1, 2))
|
||||
assert.NoError(t, DeleteWebhookByRepoID(db.DefaultContext, 1, 2))
|
||||
unittest.AssertNotExistsBean(t, &Webhook{ID: 2, RepoID: 1})
|
||||
|
||||
err := DeleteWebhookByRepoID(unittest.NonexistentID, unittest.NonexistentID)
|
||||
err := DeleteWebhookByRepoID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrWebhookNotExist(err))
|
||||
}
|
||||
|
@ -185,23 +185,23 @@ func TestDeleteWebhookByRepoID(t *testing.T) {
|
|||
func TestDeleteWebhookByOwnerID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 3, OwnerID: 3})
|
||||
assert.NoError(t, DeleteWebhookByOwnerID(3, 3))
|
||||
assert.NoError(t, DeleteWebhookByOwnerID(db.DefaultContext, 3, 3))
|
||||
unittest.AssertNotExistsBean(t, &Webhook{ID: 3, OwnerID: 3})
|
||||
|
||||
err := DeleteWebhookByOwnerID(unittest.NonexistentID, unittest.NonexistentID)
|
||||
err := DeleteWebhookByOwnerID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrWebhookNotExist(err))
|
||||
}
|
||||
|
||||
func TestHookTasks(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
hookTasks, err := HookTasks(1, 1)
|
||||
hookTasks, err := HookTasks(db.DefaultContext, 1, 1)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, hookTasks, 1) {
|
||||
assert.Equal(t, int64(1), hookTasks[0].ID)
|
||||
}
|
||||
|
||||
hookTasks, err = HookTasks(unittest.NonexistentID, 1)
|
||||
hookTasks, err = HookTasks(db.DefaultContext, unittest.NonexistentID, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hookTasks, 0)
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ func TestUpdateHookTask(t *testing.T) {
|
|||
hook.PayloadContent = "new payload content"
|
||||
hook.IsDelivered = true
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
assert.NoError(t, UpdateHookTask(hook))
|
||||
assert.NoError(t, UpdateHookTask(db.DefaultContext, hook))
|
||||
unittest.AssertExistsAndLoadBean(t, hook)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue