Skip to content

Commit 93b4f3f

Browse files
committed
fix test
1 parent ec47430 commit 93b4f3f

File tree

3 files changed

+83
-54
lines changed

3 files changed

+83
-54
lines changed

models/webhook_test.go

-54
Original file line numberDiff line numberDiff line change
@@ -253,57 +253,3 @@ func TestUpdateHookTask(t *testing.T) {
253253
assert.NoError(t, UpdateHookTask(hook))
254254
AssertExistsAndLoadBean(t, hook)
255255
}
256-
257-
func TestPrepareWebhooks(t *testing.T) {
258-
assert.NoError(t, PrepareTestDatabase())
259-
260-
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
261-
hookTasks := []*HookTask{
262-
{RepoID: repo.ID, HookID: 1, EventType: HookEventPush},
263-
}
264-
for _, hookTask := range hookTasks {
265-
AssertNotExistsBean(t, hookTask)
266-
}
267-
assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{}))
268-
for _, hookTask := range hookTasks {
269-
AssertExistsAndLoadBean(t, hookTask)
270-
}
271-
}
272-
273-
func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
274-
assert.NoError(t, PrepareTestDatabase())
275-
276-
repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
277-
hookTasks := []*HookTask{
278-
{RepoID: repo.ID, HookID: 4, EventType: HookEventPush},
279-
}
280-
for _, hookTask := range hookTasks {
281-
AssertNotExistsBean(t, hookTask)
282-
}
283-
// this test also ensures that * doesn't handle / in any special way (like shell would)
284-
assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791"}))
285-
for _, hookTask := range hookTasks {
286-
AssertExistsAndLoadBean(t, hookTask)
287-
}
288-
}
289-
290-
func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
291-
assert.NoError(t, PrepareTestDatabase())
292-
293-
repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
294-
hookTasks := []*HookTask{
295-
{RepoID: repo.ID, HookID: 4, EventType: HookEventPush},
296-
}
297-
for _, hookTask := range hookTasks {
298-
AssertNotExistsBean(t, hookTask)
299-
}
300-
assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
301-
302-
for _, hookTask := range hookTasks {
303-
AssertNotExistsBean(t, hookTask)
304-
}
305-
}
306-
307-
// TODO TestHookTask_deliver
308-
309-
// TODO TestDeliverHooks

modules/webhook/main_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package webhook
6+
7+
import (
8+
"path/filepath"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models"
12+
)
13+
14+
func TestMain(m *testing.M) {
15+
models.MainTest(m, filepath.Join("..", ".."))
16+
}

modules/webhook/webhook_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package webhook
6+
7+
import (
8+
"testing"
9+
10+
"code.gitea.io/gitea/models"
11+
api "code.gitea.io/gitea/modules/structs"
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestPrepareWebhooks(t *testing.T) {
16+
assert.NoError(t, models.PrepareTestDatabase())
17+
18+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
19+
hookTasks := []*models.HookTask{
20+
{RepoID: repo.ID, HookID: 1, EventType: models.HookEventPush},
21+
}
22+
for _, hookTask := range hookTasks {
23+
models.AssertNotExistsBean(t, hookTask)
24+
}
25+
assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{}))
26+
for _, hookTask := range hookTasks {
27+
models.AssertExistsAndLoadBean(t, hookTask)
28+
}
29+
}
30+
31+
func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
32+
assert.NoError(t, models.PrepareTestDatabase())
33+
34+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
35+
hookTasks := []*models.HookTask{
36+
{RepoID: repo.ID, HookID: 4, EventType: models.HookEventPush},
37+
}
38+
for _, hookTask := range hookTasks {
39+
models.AssertNotExistsBean(t, hookTask)
40+
}
41+
// this test also ensures that * doesn't handle / in any special way (like shell would)
42+
assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791"}))
43+
for _, hookTask := range hookTasks {
44+
models.AssertExistsAndLoadBean(t, hookTask)
45+
}
46+
}
47+
48+
func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
49+
assert.NoError(t, models.PrepareTestDatabase())
50+
51+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
52+
hookTasks := []*models.HookTask{
53+
{RepoID: repo.ID, HookID: 4, EventType: models.HookEventPush},
54+
}
55+
for _, hookTask := range hookTasks {
56+
models.AssertNotExistsBean(t, hookTask)
57+
}
58+
assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
59+
60+
for _, hookTask := range hookTasks {
61+
models.AssertNotExistsBean(t, hookTask)
62+
}
63+
}
64+
65+
// TODO TestHookTask_deliver
66+
67+
// TODO TestDeliverHooks

0 commit comments

Comments
 (0)