Add testifylint to lint checks (#4535)
go-require lint is ignored for now Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4535 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
parent
94933470cd
commit
4de909747b
504 changed files with 5028 additions and 4680 deletions
|
@ -58,7 +58,7 @@ func TestGiteaPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test", body.Ref) // short ref
|
||||
})
|
||||
|
||||
|
@ -87,7 +87,7 @@ func TestGiteaPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "refs/heads/test", body.Ref) // full ref
|
||||
})
|
||||
|
||||
|
@ -116,7 +116,7 @@ func TestGiteaPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test", body.Ref) // short ref
|
||||
})
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ func TestForgejoPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "refs/heads/test", body.Ref) // full ref
|
||||
})
|
||||
|
||||
|
@ -190,7 +190,7 @@ func TestForgejoPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "refs/heads/test", body.Ref) // full ref
|
||||
})
|
||||
|
||||
|
@ -219,7 +219,7 @@ func TestForgejoPayload(t *testing.T) {
|
|||
Ref string `json:"ref"`
|
||||
}
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "refs/heads/test", body.Ref) // full ref
|
||||
})
|
||||
}
|
||||
|
@ -245,9 +245,9 @@ func TestOpenProjectPayload(t *testing.T) {
|
|||
assert.Equal(t, "test/repo", j.Get("base", "repo", "full_name").MustBeValid().ToString())
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", j.Get("base", "repo", "html_url").MustBeValid().ToString())
|
||||
|
||||
assert.Equal(t, false, j.Get("draft").MustBeValid().ToBool())
|
||||
assert.False(t, j.Get("draft").MustBeValid().ToBool())
|
||||
assert.Equal(t, jsoniter.NilValue, j.Get("merge_commit_sha").ValueType())
|
||||
assert.Equal(t, false, j.Get("merged").MustBeValid().ToBool())
|
||||
assert.False(t, j.Get("merged").MustBeValid().ToBool())
|
||||
assert.Equal(t, jsoniter.NilValue, j.Get("merged_by").ValueType())
|
||||
assert.Equal(t, jsoniter.NilValue, j.Get("merged_at").ValueType())
|
||||
assert.Equal(t, 0, j.Get("comments").MustBeValid().ToInt())
|
||||
|
|
|
@ -76,11 +76,11 @@ func TestWebhookProxy(t *testing.T) {
|
|||
|
||||
u, err := webhookProxy(allowedHostMatcher)(req)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
got := ""
|
||||
if u != nil {
|
||||
|
@ -92,7 +92,7 @@ func TestWebhookProxy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
done := make(chan struct{}, 1)
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -111,8 +111,8 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
|||
Type: webhook_module.GITEA,
|
||||
}
|
||||
err := hook.SetHeaderAuthorization("Bearer s3cr3t-t0ken")
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
|
@ -121,10 +121,10 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
|||
}
|
||||
|
||||
hookTask, err = webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
|
@ -136,7 +136,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
done := make(chan struct{}, 1)
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -147,14 +147,14 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
assert.Equal(t, "push", r.Header.Get("X-GitHub-Event"))
|
||||
assert.Equal(t, "", r.Header.Get("Content-Type"))
|
||||
body, err := io.ReadAll(r.Body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, `{"data": 42}`, string(body))
|
||||
|
||||
case "/webhook/6db5dc1e282529a8c162c7fe93dd2667494eeb51":
|
||||
// Version 2
|
||||
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
|
||||
body, err := io.ReadAll(r.Body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, body, 2147)
|
||||
|
||||
default:
|
||||
|
@ -176,7 +176,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
ContentType: webhook_model.ContentTypeJSON,
|
||||
Meta: `{"message_type":0}`, // text
|
||||
}
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
require.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
|
||||
t.Run("Version 1", func(t *testing.T) {
|
||||
hookTask := &webhook_model.HookTask{
|
||||
|
@ -187,10 +187,10 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
}
|
||||
|
||||
hookTask, err := webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
|
@ -203,7 +203,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
t.Run("Version 2", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
|
@ -213,10 +213,10 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
}
|
||||
|
||||
hookTask, err = webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
|
@ -228,7 +228,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
type hookCase struct {
|
||||
gotBody chan []byte
|
||||
|
@ -280,7 +280,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
|||
|
||||
require.NotNil(t, hc.gotBody, r.URL.Path)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
w.WriteHeader(200)
|
||||
hc.gotBody <- body
|
||||
}))
|
||||
|
@ -288,7 +288,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
|||
|
||||
p := pushTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for typ, hc := range cases {
|
||||
typ := typ
|
||||
|
@ -304,7 +304,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
|||
ContentType: 0, // set to 0 so that falling back to default request fails with "invalid content type"
|
||||
Meta: "{}",
|
||||
}
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
require.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
|
@ -314,10 +314,10 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
|||
}
|
||||
|
||||
hookTask, err := webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
||||
select {
|
||||
case gotBody := <-hc.gotBody:
|
||||
assert.NotEqual(t, string(data), string(gotBody), "request body must be different from the event payload")
|
||||
|
|
|
@ -247,6 +247,6 @@ func TestDingTalkJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body DingtalkPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\r\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", body.ActionCard.Text)
|
||||
}
|
||||
|
|
|
@ -286,6 +286,6 @@ func TestDiscordJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body DiscordPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", body.Embeds[0].Description)
|
||||
}
|
||||
|
|
|
@ -188,6 +188,6 @@ func TestFeishuJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body FeishuPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[test/repo:test] \r\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\r\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", body.Content.Text)
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ func TestMatrixJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body MatrixPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] user1 pushed 2 commits to [test](http://localhost:3000/test/repo/src/branch/test):\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778): commit message - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778): commit message - user1", body.Body)
|
||||
}
|
||||
|
||||
|
|
|
@ -450,6 +450,6 @@ func TestMSTeamsJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body MSTeamsPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", body.Summary)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestPackagistPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body PackagistPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://packagist.org/packages/example", body.PackagistRepository.URL)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ func TestSlackJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body SlackPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by user1", body.Text)
|
||||
}
|
||||
|
||||
|
@ -217,11 +217,12 @@ func TestSlackMetadata(t *testing.T) {
|
|||
Meta: `{"channel": "foo", "username": "username", "color": "blue"}`,
|
||||
}
|
||||
slackHook := slackHandler{}.Metadata(w)
|
||||
assert.Equal(t, *slackHook.(*SlackMeta), SlackMeta{
|
||||
assert.Equal(t, SlackMeta{
|
||||
Channel: "foo",
|
||||
Username: "username",
|
||||
Color: "blue",
|
||||
})
|
||||
},
|
||||
*slackHook.(*SlackMeta))
|
||||
}
|
||||
|
||||
func TestSlackToHook(t *testing.T) {
|
||||
|
@ -242,9 +243,9 @@ func TestSlackToHook(t *testing.T) {
|
|||
},
|
||||
}
|
||||
h, err := ToHook("repoLink", w)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, h.Config, map[string]string{
|
||||
assert.Equal(t, map[string]string{
|
||||
"url": "https://slack.example.com",
|
||||
"content_type": "json",
|
||||
|
||||
|
@ -252,13 +253,13 @@ func TestSlackToHook(t *testing.T) {
|
|||
"color": "blue",
|
||||
"icon_url": "",
|
||||
"username": "username",
|
||||
})
|
||||
assert.Equal(t, h.URL, "https://slack.example.com")
|
||||
assert.Equal(t, h.ContentType, "json")
|
||||
assert.Equal(t, h.Metadata, &SlackMeta{
|
||||
}, h.Config)
|
||||
assert.Equal(t, "https://slack.example.com", h.URL)
|
||||
assert.Equal(t, "json", h.ContentType)
|
||||
assert.Equal(t, &SlackMeta{
|
||||
Channel: "foo",
|
||||
Username: "username",
|
||||
IconURL: "",
|
||||
Color: "blue",
|
||||
})
|
||||
}, h.Metadata)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func gitInit(t testing.TB) {
|
|||
return
|
||||
}
|
||||
t.Cleanup(test.MockVariableValue(&setting.Git.HomePath, t.TempDir()))
|
||||
assert.NoError(t, git.InitSimple(context.Background()))
|
||||
require.NoError(t, git.InitSimple(context.Background()))
|
||||
}
|
||||
|
||||
func TestSourcehutBuildsPayload(t *testing.T) {
|
||||
|
@ -129,16 +129,16 @@ tasks:
|
|||
p := &api.DeletePayload{}
|
||||
|
||||
pl, err := pc.Delete(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
p := &api.ForkPayload{}
|
||||
|
||||
pl, err := pc.Fork(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Push/simple", func(t *testing.T) {
|
||||
|
@ -250,29 +250,29 @@ triggers:
|
|||
|
||||
p.Action = api.HookIssueOpened
|
||||
pl, err := pc.Issue(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = pc.Issue(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
p := &api.IssueCommentPayload{}
|
||||
|
||||
pl, err := pc.IssueComment(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
p := &api.PullRequestPayload{}
|
||||
|
||||
pl, err := pc.PullRequest(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
|
@ -281,8 +281,8 @@ triggers:
|
|||
}
|
||||
|
||||
pl, err := pc.IssueComment(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
|
@ -290,24 +290,24 @@ triggers:
|
|||
p.Action = api.HookIssueReviewed
|
||||
|
||||
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
p := &api.RepositoryPayload{}
|
||||
|
||||
pl, err := pc.Repository(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
p := &api.PackagePayload{}
|
||||
|
||||
pl, err := pc.Package(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
|
@ -315,26 +315,26 @@ triggers:
|
|||
|
||||
p.Action = api.HookWikiCreated
|
||||
pl, err := pc.Wiki(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = pc.Wiki(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = pc.Wiki(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
p := &api.ReleasePayload{}
|
||||
|
||||
pl, err := pc.Release(p)
|
||||
require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
|
||||
require.Equal(t, pl, graphqlPayload[buildsVariables]{})
|
||||
require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
|
||||
require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ func TestSourcehutJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body graphqlPayload[buildsVariables]
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "json test", body.Variables.Note)
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
|
|||
Readme: "Default",
|
||||
DefaultBranch: "main",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, repo)
|
||||
t.Cleanup(func() {
|
||||
repo_service.DeleteRepository(db.DefaultContext, owner, repo, false)
|
||||
|
@ -421,7 +421,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
|
|||
}
|
||||
|
||||
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, units, disabledUnits)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
var sha string
|
||||
|
@ -444,7 +444,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
|
|||
Committer: time.Now(),
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, resp)
|
||||
|
||||
sha = resp.Commit.SHA
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestTelegramPayload(t *testing.T) {
|
|||
p := createTelegramPayload("testMsg ")
|
||||
|
||||
assert.Equal(t, "HTML", p.ParseMode)
|
||||
assert.Equal(t, true, p.DisableWebPreview)
|
||||
assert.True(t, p.DisableWebPreview)
|
||||
assert.Equal(t, "testMsg", p.Message)
|
||||
})
|
||||
|
||||
|
@ -205,7 +205,7 @@ func TestTelegramJSONPayload(t *testing.T) {
|
|||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body TelegramPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>:<a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a>] 2 new commits
|
||||
[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1
|
||||
[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1`, body.Message)
|
||||
|
|
|
@ -15,17 +15,18 @@ import (
|
|||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func activateWebhook(t *testing.T, hookID int64) {
|
||||
t.Helper()
|
||||
updated, err := db.GetEngine(db.DefaultContext).ID(hookID).Cols("is_active").Update(webhook_model.Webhook{IsActive: true})
|
||||
assert.Equal(t, int64(1), updated)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestPrepareWebhooks(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
activateWebhook(t, 1)
|
||||
|
@ -36,7 +37,7 @@ func TestPrepareWebhooks(t *testing.T) {
|
|||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertNotExistsBean(t, hookTask)
|
||||
}
|
||||
assert.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
|
||||
require.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ func eventType(p api.Payloader) webhook_module.HookEventType {
|
|||
}
|
||||
|
||||
func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// branch_filter: {master,feature*}
|
||||
w := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{ID: 4})
|
||||
|
@ -69,7 +70,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
|
|||
t.Run(fmt.Sprintf("%T", p), func(t *testing.T) {
|
||||
db.DeleteBeans(db.DefaultContext, webhook_model.HookTask{HookID: w.ID})
|
||||
typ := eventType(p)
|
||||
assert.NoError(t, PrepareWebhook(db.DefaultContext, w, typ, p))
|
||||
require.NoError(t, PrepareWebhook(db.DefaultContext, w, typ, p))
|
||||
unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{
|
||||
HookID: w.ID,
|
||||
EventType: typ,
|
||||
|
@ -79,7 +80,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// branch_filter: {master,feature*}
|
||||
w := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{ID: 4})
|
||||
|
@ -92,7 +93,7 @@ func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
|
|||
} {
|
||||
t.Run(fmt.Sprintf("%T", p), func(t *testing.T) {
|
||||
db.DeleteBeans(db.DefaultContext, webhook_model.HookTask{HookID: w.ID})
|
||||
assert.NoError(t, PrepareWebhook(db.DefaultContext, w, eventType(p), p))
|
||||
require.NoError(t, PrepareWebhook(db.DefaultContext, w, eventType(p), p))
|
||||
unittest.AssertNotExistsBean(t, &webhook_model.HookTask{HookID: w.ID})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue