mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: consolidate Go tests (#39962)
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -157,55 +157,38 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
}
|
||||
assert.NoError(t, webhook_model.CreateWebhook(t.Context(), hook))
|
||||
|
||||
t.Run("Version 1", func(t *testing.T) {
|
||||
testVersion = 1
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: webhook_module.HookEventPush,
|
||||
PayloadContent: `{"data": 42}`,
|
||||
PayloadVersion: 1,
|
||||
}
|
||||
for version, name := range []string{"Version 1", "Version 2"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
payloadContent := `{"data": 42}`
|
||||
if version == 1 {
|
||||
p := pushTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
assert.NoError(t, err)
|
||||
payloadContent = string(data)
|
||||
}
|
||||
|
||||
hookTask, err := webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
testVersion = version + 1
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: webhook_module.HookEventPush,
|
||||
PayloadContent: payloadContent,
|
||||
PayloadVersion: testVersion,
|
||||
}
|
||||
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("waited to long for request to happen")
|
||||
}
|
||||
hookTask, err := webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.True(t, hookTask.IsSucceed)
|
||||
})
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("waited to long for request to happen")
|
||||
}
|
||||
|
||||
t.Run("Version 2", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
assert.NoError(t, err)
|
||||
|
||||
testVersion = 2
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: webhook_module.HookEventPush,
|
||||
PayloadContent: string(data),
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
hookTask, err = webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("waited to long for request to happen")
|
||||
}
|
||||
|
||||
assert.True(t, hookTask.IsSucceed)
|
||||
})
|
||||
assert.True(t, hookTask.IsSucceed)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||
|
||||
@@ -27,6 +27,12 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
return ""
|
||||
}
|
||||
dc := dingtalkConvertor{}
|
||||
assertPayload := func(t *testing.T, pl DingtalkPayload, text, title, singleTitle, singleURL string) {
|
||||
assert.Equal(t, text, pl.ActionCard.Text)
|
||||
assert.Equal(t, title, pl.ActionCard.Title)
|
||||
assert.Equal(t, singleTitle, pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, singleURL, parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
}
|
||||
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
@@ -34,10 +40,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] branch test created", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] branch test created", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view ref test", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] branch test created", "[test/repo] branch test created", "view ref test", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
@@ -46,10 +49,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] branch test deleted", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] branch test deleted", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view ref test", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] branch test deleted", "[test/repo] branch test deleted", "view ref test", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
@@ -58,10 +58,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test/repo2 is forked to test/repo", pl.ActionCard.Text)
|
||||
assert.Equal(t, "test/repo2 is forked to test/repo", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view forked repo test/repo", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "test/repo2 is forked to test/repo", "test/repo2 is forked to test/repo", "view forked repo test/repo", "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
@@ -70,10 +67,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Push(p)
|
||||
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", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view commits", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\r\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", "[test/repo:test] 2 new commits", "view commits", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
@@ -83,19 +77,13 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue opened: #2 crash by user1\r\n\r\nissue body", pl.ActionCard.Text)
|
||||
assert.Equal(t, "#2 crash", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view issue", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Issue opened: #2 crash by user1\r\n\r\nissue body", "#2 crash", "view issue", "http://localhost:3000/test/repo/issues/2")
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = dc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue closed: #2 crash by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "#2 crash", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view issue", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Issue closed: #2 crash by user1", "#2 crash", "view issue", "http://localhost:3000/test/repo/issues/2")
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
@@ -104,10 +92,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on issue #2 crash by user1\r\n\r\nmore info needed", pl.ActionCard.Text)
|
||||
assert.Equal(t, "#2 crash", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view issue comment", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2#issuecomment-4", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] New comment on issue #2 crash by user1\r\n\r\nmore info needed", "#2 crash", "view issue comment", "http://localhost:3000/test/repo/issues/2#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
@@ -116,10 +101,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request opened: #12 Fix bug by user1\r\n\r\nfixes bug #2", pl.ActionCard.Text)
|
||||
assert.Equal(t, "#12 Fix bug", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view pull request", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Pull request opened: #12 Fix bug by user1\r\n\r\nfixes bug #2", "#12 Fix bug", "view pull request", "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
@@ -128,10 +110,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on pull request #12 Fix bug by user1\r\n\r\nchanges requested", pl.ActionCard.Text)
|
||||
assert.Equal(t, "#12 Fix bug", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view issue comment", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12#issuecomment-4", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] New comment on pull request #12 Fix bug by user1\r\n\r\nchanges requested", "#12 Fix bug", "view issue comment", "http://localhost:3000/test/repo/pulls/12#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
@@ -141,10 +120,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request review approved : #12 Fix bug\r\n\r\ngood job", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] Pull request review approved : #12 Fix bug", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view pull request", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Pull request review approved : #12 Fix bug\r\n\r\ngood job", "[test/repo] Pull request review approved : #12 Fix bug", "view pull request", "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
@@ -153,10 +129,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view repository", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Repository created", "[test/repo] Repository created", "view repository", "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
@@ -165,10 +138,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest by user1", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view package", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "Package created: GiteaContainer:latest by user1", "Package created: GiteaContainer:latest by user1", "view package", "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest")
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
@@ -178,28 +148,19 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New wiki page 'index' (Wiki change comment) by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] New wiki page 'index' (Wiki change comment) by user1", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view wiki", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] New wiki page 'index' (Wiki change comment) by user1", "[test/repo] New wiki page 'index' (Wiki change comment) by user1", "view wiki", "http://localhost:3000/test/repo/wiki/index")
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' edited (Wiki change comment) by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' edited (Wiki change comment) by user1", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view wiki", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Wiki page 'index' edited (Wiki change comment) by user1", "[test/repo] Wiki page 'index' edited (Wiki change comment) by user1", "view wiki", "http://localhost:3000/test/repo/wiki/index")
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted by user1", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view wiki", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Wiki page 'index' deleted by user1", "[test/repo] Wiki page 'index' deleted by user1", "view wiki", "http://localhost:3000/test/repo/wiki/index")
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
@@ -208,10 +169,7 @@ func TestDingTalkPayload(t *testing.T) {
|
||||
pl, err := dc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.ActionCard.Text)
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.ActionCard.Title)
|
||||
assert.Equal(t, "view release", pl.ActionCard.SingleTitle)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", parseRealSingleURL(pl.ActionCard.SingleURL))
|
||||
assertPayload(t, pl, "[test/repo] Release created: v1.0 by user1", "[test/repo] Release created: v1.0 by user1", "view release", "http://localhost:3000/test/repo/releases/tag/v1.0")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,21 @@ import (
|
||||
|
||||
func TestDiscordPayload(t *testing.T) {
|
||||
dc := discordConvertor{}
|
||||
assertPayload := func(t *testing.T, pl DiscordPayload, sender *api.User, title, description, link string) {
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, title, pl.Embeds[0].Title)
|
||||
if description == "" {
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
} else {
|
||||
assert.Equal(t, description, pl.Embeds[0].Description)
|
||||
}
|
||||
if link != "" {
|
||||
assert.Equal(t, link, pl.Embeds[0].URL)
|
||||
}
|
||||
assert.Equal(t, sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
}
|
||||
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
@@ -25,13 +40,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] branch test created", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] branch test created", "", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
@@ -40,13 +49,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] branch test deleted", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] branch test deleted", "", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
@@ -55,13 +58,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "test/repo2 is forked to test/repo", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "test/repo2 is forked to test/repo", "", "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
@@ -70,13 +67,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
|
||||
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", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo:test] 2 new commits", "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("PushWithMultilineCommitMessage", func(t *testing.T) {
|
||||
@@ -85,12 +76,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1", pl.Embeds[0].Description)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo:test] 2 new commits", "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1", "")
|
||||
})
|
||||
|
||||
t.Run("PushWithLongCommitSummary", func(t *testing.T) {
|
||||
@@ -99,12 +85,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1", pl.Embeds[0].Description)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo:test] 2 new commits", "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1", "")
|
||||
})
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
@@ -114,25 +95,13 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Issue opened: #2 crash", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "issue body", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Issue opened: #2 crash", "issue body", "http://localhost:3000/test/repo/issues/2")
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = dc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Issue closed: #2 crash", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Issue closed: #2 crash", "", "http://localhost:3000/test/repo/issues/2")
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
@@ -141,13 +110,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] New comment on issue #2 crash", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "more info needed", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2#issuecomment-4", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] New comment on issue #2 crash", "more info needed", "http://localhost:3000/test/repo/issues/2#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
@@ -156,13 +119,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Pull request opened: #12 Fix bug", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "fixes bug #2", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Pull request opened: #12 Fix bug", "fixes bug #2", "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
@@ -171,13 +128,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] New comment on pull request #12 Fix bug", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "changes requested", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12#issuecomment-4", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] New comment on pull request #12 Fix bug", "changes requested", "http://localhost:3000/test/repo/pulls/12#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
@@ -187,13 +138,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Pull request review approved: #12 Fix bug", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "good job", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Pull request review approved: #12 Fix bug", "good job", "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
@@ -202,13 +147,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Repository created", "", "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
@@ -217,13 +156,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "Package created: GiteaContainer:latest", "", "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest")
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
@@ -233,37 +166,19 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] New wiki page 'index' (Wiki change comment)", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "Wiki change comment", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] New wiki page 'index' (Wiki change comment)", "Wiki change comment", "http://localhost:3000/test/repo/wiki/index")
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' edited (Wiki change comment)", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "Wiki change comment", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Wiki page 'index' edited (Wiki change comment)", "Wiki change comment", "http://localhost:3000/test/repo/wiki/index")
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = dc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted", pl.Embeds[0].Title)
|
||||
assert.Empty(t, pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Wiki page 'index' deleted", "", "http://localhost:3000/test/repo/wiki/index")
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
@@ -272,13 +187,7 @@ func TestDiscordPayload(t *testing.T) {
|
||||
pl, err := dc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, pl.Embeds, 1)
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0", pl.Embeds[0].Title)
|
||||
assert.Equal(t, "Note of first stable release", pl.Embeds[0].Description)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", pl.Embeds[0].URL)
|
||||
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
|
||||
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
|
||||
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
|
||||
assertPayload(t, pl, p.Sender, "[test/repo] Release created: v1.0", "Note of first stable release", "http://localhost:3000/test/repo/releases/tag/v1.0")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,41 +17,68 @@ import (
|
||||
|
||||
func TestFeishuPayload(t *testing.T) {
|
||||
fc := feishuConvertor{}
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
|
||||
pl, err := fc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[test/repo] branch test created`, pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
p := deleteTestPayload()
|
||||
|
||||
pl, err := fc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[test/repo] branch test deleted`, pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
p := forkTestPayload()
|
||||
|
||||
pl, err := fc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `test/repo2 is forked to test/repo`, pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
|
||||
pl, err := fc.Push(p)
|
||||
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", pl.Content.Text)
|
||||
})
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
convert func() (FeishuPayload, error)
|
||||
text string
|
||||
}{
|
||||
{
|
||||
"Create",
|
||||
func() (FeishuPayload, error) { return fc.Create(createTestPayload()) },
|
||||
`[test/repo] branch test created`,
|
||||
},
|
||||
{
|
||||
"Delete",
|
||||
func() (FeishuPayload, error) { return fc.Delete(deleteTestPayload()) },
|
||||
`[test/repo] branch test deleted`,
|
||||
},
|
||||
{
|
||||
"Fork",
|
||||
func() (FeishuPayload, error) { return fc.Fork(forkTestPayload()) },
|
||||
`test/repo2 is forked to test/repo`,
|
||||
},
|
||||
{
|
||||
"Push",
|
||||
func() (FeishuPayload, error) { return fc.Push(pushTestPayload()) },
|
||||
"[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",
|
||||
},
|
||||
{
|
||||
"IssueComment",
|
||||
func() (FeishuPayload, error) { return fc.IssueComment(issueCommentTestPayload()) },
|
||||
"[Comment-test/repo #2]: created\ncrash\nhttp://localhost:3000/test/repo/issues/2\nIssue by user1\nOperator: user1\n\nmore info needed",
|
||||
},
|
||||
{
|
||||
"PullRequest",
|
||||
func() (FeishuPayload, error) { return fc.PullRequest(pullRequestTestPayload()) },
|
||||
"[PullRequest-test/repo #12]: opened\nFix bug\nhttp://localhost:3000/test/repo/pulls/12\nPullRequest by user1\nOperator: user1\nAssignees: user1\n\nfixes bug #2",
|
||||
},
|
||||
{
|
||||
"PullRequestComment",
|
||||
func() (FeishuPayload, error) { return fc.IssueComment(pullRequestCommentTestPayload()) },
|
||||
"[Comment-test/repo #12]: created\nFix bug\nhttp://localhost:3000/test/repo/pulls/12\nPullRequest by user1\nOperator: user1\n\nchanges requested",
|
||||
},
|
||||
{
|
||||
"Repository",
|
||||
func() (FeishuPayload, error) { return fc.Repository(repositoryTestPayload()) },
|
||||
"[test/repo] Repository created",
|
||||
},
|
||||
{
|
||||
"Package",
|
||||
func() (FeishuPayload, error) { return fc.Package(packageTestPayload()) },
|
||||
"Package created: GiteaContainer:latest by user1",
|
||||
},
|
||||
{
|
||||
"Release",
|
||||
func() (FeishuPayload, error) { return fc.Release(pullReleaseTestPayload()) },
|
||||
"[test/repo] Release created: v1.0 by user1",
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
pl, err := test.convert()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.text, pl.Content.Text)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
p := issueTestPayload()
|
||||
@@ -69,33 +96,6 @@ func TestFeishuPayload(t *testing.T) {
|
||||
assert.Equal(t, "[Issue-test/repo #2]: closed\ncrash\nhttp://localhost:3000/test/repo/issues/2\nIssue by user1\nOperator: user1\nAssignees: user1\n\nissue body", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
p := issueCommentTestPayload()
|
||||
|
||||
pl, err := fc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[Comment-test/repo #2]: created\ncrash\nhttp://localhost:3000/test/repo/issues/2\nIssue by user1\nOperator: user1\n\nmore info needed", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
|
||||
pl, err := fc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[PullRequest-test/repo #12]: opened\nFix bug\nhttp://localhost:3000/test/repo/pulls/12\nPullRequest by user1\nOperator: user1\nAssignees: user1\n\nfixes bug #2", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
p := pullRequestCommentTestPayload()
|
||||
|
||||
pl, err := fc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[Comment-test/repo #12]: created\nFix bug\nhttp://localhost:3000/test/repo/pulls/12\nPullRequest by user1\nOperator: user1\n\nchanges requested", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
@@ -106,24 +106,6 @@ func TestFeishuPayload(t *testing.T) {
|
||||
assert.Equal(t, "[test/repo] Pull request review approved : #12 Fix bug\r\n\r\ngood job", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
p := repositoryTestPayload()
|
||||
|
||||
pl, err := fc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
p := packageTestPayload()
|
||||
|
||||
pl, err := fc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest by user1", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
p := wikiTestPayload()
|
||||
|
||||
@@ -145,15 +127,6 @@ func TestFeishuPayload(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted by user1", pl.Content.Text)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
p := pullReleaseTestPayload()
|
||||
|
||||
pl, err := fc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.Content.Text)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFeishuJSONPayload(t *testing.T) {
|
||||
|
||||
@@ -383,202 +383,113 @@ func packageTestPayload() *api.PackagePayload {
|
||||
}
|
||||
|
||||
func TestGetIssuesPayloadInfo(t *testing.T) {
|
||||
p := issueTestPayload()
|
||||
p.Changes = &api.ChangesPayload{AddedAssignees: p.Issue.Assignees}
|
||||
issue := issueTestPayload()
|
||||
issue.Changes = &api.ChangesPayload{AddedAssignees: issue.Issue.Assignees}
|
||||
pull := pullRequestTestPayload()
|
||||
pull.Changes = &api.ChangesPayload{AddedAssignees: pull.PullRequest.Assignees}
|
||||
|
||||
cases := []struct {
|
||||
action api.HookIssueAction
|
||||
text string
|
||||
issueTitle string
|
||||
attachmentText string
|
||||
color int
|
||||
action api.HookIssueAction
|
||||
issueText string
|
||||
pullRequestText string
|
||||
issueMarkdown string
|
||||
pullRequestMarkdown string
|
||||
issueColor int
|
||||
pullRequestColor int
|
||||
}{
|
||||
{
|
||||
api.HookIssueOpened,
|
||||
"[test/repo] Issue opened: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"issue body",
|
||||
orangeColor,
|
||||
"[test/repo] Pull request opened: #12 Fix bug by user1",
|
||||
"issue body", "fixes bug #2",
|
||||
orangeColor, greenColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueClosed,
|
||||
"[test/repo] Issue closed: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
redColor,
|
||||
"[test/repo] Pull request closed: #12 Fix bug by user1",
|
||||
"", "",
|
||||
redColor, redColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueReOpened,
|
||||
"[test/repo] Issue re-opened: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request re-opened: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueEdited,
|
||||
"[test/repo] Issue edited: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"issue body",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request edited: #12 Fix bug by user1",
|
||||
"issue body", "fixes bug #2",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueAssigned,
|
||||
"[test/repo] Issue assigned to user1: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
greenColor,
|
||||
"[test/repo] Pull request assigned to user1: #12 Fix bug by user1",
|
||||
"", "",
|
||||
greenColor, greenColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueUnassigned,
|
||||
"[test/repo] Issue unassigned: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request unassigned: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueLabelUpdated,
|
||||
"[test/repo] Issue labels updated: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request labels updated: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueLabelCleared,
|
||||
"[test/repo] Issue labels cleared: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request labels cleared: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueSynchronized,
|
||||
"[test/repo] Issue synchronized: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request synchronized: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueMilestoned,
|
||||
"[test/repo] Issue milestoned to Milestone Title: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
"[test/repo] Pull request milestoned to Milestone Title: #12 Fix bug by user1",
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueDemilestoned,
|
||||
"[test/repo] Issue milestone cleared: #2 crash by user1",
|
||||
"#2 crash",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, issueTitle, extraMarkdown, color := getIssuesPayloadInfo(p, noneLinkFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.issueTitle, issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.attachmentText, extraMarkdown, "case %d", i)
|
||||
assert.Equal(t, c.color, color, "case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPullRequestPayloadInfo(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Changes = &api.ChangesPayload{AddedAssignees: p.PullRequest.Assignees}
|
||||
|
||||
cases := []struct {
|
||||
action api.HookIssueAction
|
||||
text string
|
||||
issueTitle string
|
||||
attachmentText string
|
||||
color int
|
||||
}{
|
||||
{
|
||||
api.HookIssueOpened,
|
||||
"[test/repo] Pull request opened: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"fixes bug #2",
|
||||
greenColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueClosed,
|
||||
"[test/repo] Pull request closed: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
redColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueReOpened,
|
||||
"[test/repo] Pull request re-opened: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueEdited,
|
||||
"[test/repo] Pull request edited: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"fixes bug #2",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueAssigned,
|
||||
"[test/repo] Pull request assigned to user1: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
greenColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueUnassigned,
|
||||
"[test/repo] Pull request unassigned: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueLabelUpdated,
|
||||
"[test/repo] Pull request labels updated: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueLabelCleared,
|
||||
"[test/repo] Pull request labels cleared: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueSynchronized,
|
||||
"[test/repo] Pull request synchronized: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueMilestoned,
|
||||
"[test/repo] Pull request milestoned to Milestone Title: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
},
|
||||
{
|
||||
api.HookIssueDemilestoned,
|
||||
"[test/repo] Pull request milestone cleared: #12 Fix bug by user1",
|
||||
"#12 Fix bug",
|
||||
"",
|
||||
yellowColor,
|
||||
"", "",
|
||||
yellowColor, yellowColor,
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, issueTitle, extraMarkdown, color := getPullRequestPayloadInfo(p, noneLinkFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.issueTitle, issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.attachmentText, extraMarkdown, "case %d", i)
|
||||
assert.Equal(t, c.color, color, "case %d", i)
|
||||
issue.Action = c.action
|
||||
text, issueTitle, extraMarkdown, color := getIssuesPayloadInfo(issue, noneLinkFormatter, true)
|
||||
assert.Equal(t, c.issueText, text, "case %d", i)
|
||||
assert.Equal(t, "#2 crash", issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.issueMarkdown, extraMarkdown, "case %d", i)
|
||||
assert.Equal(t, c.issueColor, color, "case %d", i)
|
||||
|
||||
pull.Action = c.action
|
||||
text, issueTitle, extraMarkdown, color = getPullRequestPayloadInfo(pull, noneLinkFormatter, true)
|
||||
assert.Equal(t, c.pullRequestText, text, "case %d", i)
|
||||
assert.Equal(t, "#12 Fix bug", issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.pullRequestMarkdown, extraMarkdown, "case %d", i)
|
||||
assert.Equal(t, c.pullRequestColor, color, "case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,30 +229,12 @@ func TestMatrixJSONPayload(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_getTxnID(t *testing.T) {
|
||||
type args struct {
|
||||
payload []byte
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "dummy payload",
|
||||
args: args{payload: []byte("Hello World")},
|
||||
want: "0a4d55a8d778e5022fab701977c5d840bbc486d0",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getMatrixTxnID(tt.args.payload)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getMatrixTxnID() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
t.Run("dummy payload", func(t *testing.T) {
|
||||
got, err := getMatrixTxnID([]byte("Hello World"))
|
||||
if err != nil {
|
||||
t.Errorf("getMatrixTxnID() error = %v, wantErr %v", err, false)
|
||||
return
|
||||
}
|
||||
assert.Equal(t, "0a4d55a8d778e5022fab701977c5d840bbc486d0", got)
|
||||
})
|
||||
}
|
||||
@@ -18,30 +18,42 @@ import (
|
||||
|
||||
func TestMSTeamsPayload(t *testing.T) {
|
||||
mc := msteamsConvertor{}
|
||||
|
||||
checkPayload := func(t *testing.T, pl MSTeamsPayload, title, text string, facts map[string]string) {
|
||||
assert.Equal(t, title, pl.Title)
|
||||
assert.Equal(t, title, pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
if text == "" {
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
} else {
|
||||
assert.Equal(t, text, pl.Sections[0].Text)
|
||||
}
|
||||
assert.Len(t, pl.Sections[0].Facts, len(facts))
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if expected, ok := facts[fact.Name]; ok {
|
||||
assert.Equal(t, expected, fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
checkAction := func(t *testing.T, pl MSTeamsPayload, target string) {
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, target, pl.PotentialAction[0].Targets[0].URI)
|
||||
}
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
|
||||
pl, err := mc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] branch test created", pl.Title)
|
||||
assert.Equal(t, "[test/repo] branch test created", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "branch:" {
|
||||
assert.Equal(t, "test", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] branch test created", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL),
|
||||
"branch:": "test",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
@@ -50,24 +62,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] branch test deleted", pl.Title)
|
||||
assert.Equal(t, "[test/repo] branch test deleted", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "branch:" {
|
||||
assert.Equal(t, "test", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] branch test deleted", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL),
|
||||
"branch:": "test",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
@@ -76,24 +75,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test/repo2 is forked to test/repo", pl.Title)
|
||||
assert.Equal(t, "test/repo2 is forked to test/repo", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Forkee:" {
|
||||
assert.Equal(t, p.Forkee.FullName, fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "test/repo2 is forked to test/repo", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL),
|
||||
"Forkee:": p.Forkee.FullName,
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
@@ -102,24 +88,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Title)
|
||||
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\n\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Commit count:" {
|
||||
assert.Equal(t, "2", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/src/test", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo:test] 2 new commits", "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\n\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repo.FullName, p.Repo.HTMLURL),
|
||||
"Commit count:": "2",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/src/test")
|
||||
})
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
@@ -129,47 +102,21 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue opened: #2 crash", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Issue opened: #2 crash", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "issue body", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Issue #:" {
|
||||
assert.Equal(t, "2", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Issue opened: #2 crash", "issue body", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Issue #:": "2",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/issues/2")
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = mc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue closed: #2 crash", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Issue closed: #2 crash", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Issue #:" {
|
||||
assert.Equal(t, "2", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Issue closed: #2 crash", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Issue #:": "2",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/issues/2")
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
@@ -178,24 +125,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on issue #2 crash", pl.Title)
|
||||
assert.Equal(t, "[test/repo] New comment on issue #2 crash", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "more info needed", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Issue #:" {
|
||||
assert.Equal(t, "2", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/issues/2#issuecomment-4", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] New comment on issue #2 crash", "more info needed", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Issue #:": "2",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/issues/2#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
@@ -204,24 +138,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request opened: #12 Fix bug", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Pull request opened: #12 Fix bug", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "fixes bug #2", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Pull request:" {
|
||||
assert.Equal(t, fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Pull request opened: #12 Fix bug", "fixes bug #2", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Pull request:": fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL),
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("PullRequestReviewRequest", func(t *testing.T) {
|
||||
@@ -258,24 +179,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on pull request #12 Fix bug", pl.Title)
|
||||
assert.Equal(t, "[test/repo] New comment on pull request #12 Fix bug", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "changes requested", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Issue #:" {
|
||||
assert.Equal(t, "12", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12#issuecomment-4", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] New comment on pull request #12 Fix bug", "changes requested", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Issue #:": "12",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/pulls/12#issuecomment-4")
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
@@ -285,24 +193,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request review approved: #12 Fix bug", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Pull request review approved: #12 Fix bug", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Equal(t, "good job", pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Pull request:" {
|
||||
assert.Equal(t, fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Pull request review approved: #12 Fix bug", "good job", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Pull request:": fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL),
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/pulls/12")
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
@@ -311,22 +206,10 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Repository created", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 1)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Repository created", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo")
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
@@ -335,22 +218,10 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest", pl.Title)
|
||||
assert.Equal(t, "Package created: GiteaContainer:latest", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 1)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Package:" {
|
||||
assert.Equal(t, p.Package.Name, fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "Package created: GiteaContainer:latest", "", map[string]string{
|
||||
"Package:": p.Package.Name,
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/user1/-/packages/container/GiteaContainer/latest")
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
@@ -360,61 +231,27 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New wiki page 'index' (Wiki change comment)", pl.Title)
|
||||
assert.Equal(t, "[test/repo] New wiki page 'index' (Wiki change comment)", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 1)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
checkPayload(t, pl, "[test/repo] New wiki page 'index' (Wiki change comment)", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
})
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = mc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' edited (Wiki change comment)", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' edited (Wiki change comment)", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 1)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Wiki page 'index' edited (Wiki change comment)", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/wiki/index")
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = mc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Wiki page 'index' deleted", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 1)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/wiki/index", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Wiki page 'index' deleted", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/wiki/index")
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
@@ -423,24 +260,11 @@ func TestMSTeamsPayload(t *testing.T) {
|
||||
pl, err := mc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0", pl.Title)
|
||||
assert.Equal(t, "[test/repo] Release created: v1.0", pl.Summary)
|
||||
assert.Len(t, pl.Sections, 1)
|
||||
assert.Equal(t, "user1", pl.Sections[0].ActivitySubtitle)
|
||||
assert.Empty(t, pl.Sections[0].Text)
|
||||
assert.Len(t, pl.Sections[0].Facts, 2)
|
||||
for _, fact := range pl.Sections[0].Facts {
|
||||
if fact.Name == "Repository:" {
|
||||
assert.Equal(t, fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL), fact.Value)
|
||||
} else if fact.Name == "Tag:" {
|
||||
assert.Equal(t, "v1.0", fact.Value)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
assert.Len(t, pl.PotentialAction, 1)
|
||||
assert.Len(t, pl.PotentialAction[0].Targets, 1)
|
||||
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", pl.PotentialAction[0].Targets[0].URI)
|
||||
checkPayload(t, pl, "[test/repo] Release created: v1.0", "", map[string]string{
|
||||
"Repository:": fmt.Sprintf("[%s](%s)", p.Repository.FullName, p.Repository.HTMLURL),
|
||||
"Tag:": "v1.0",
|
||||
})
|
||||
checkAction(t, pl, "http://localhost:3000/test/repo/releases/tag/v1.0")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -19,29 +19,31 @@ func TestPackagistPayload(t *testing.T) {
|
||||
pc := packagistConvertor{
|
||||
PackageURL: "https://packagist.org/packages/example",
|
||||
}
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
|
||||
pl, err := pc.Create(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
p := deleteTestPayload()
|
||||
|
||||
pl, err := pc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
p := forkTestPayload()
|
||||
|
||||
pl, err := pc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
call func() (PackagistPayload, error)
|
||||
}{
|
||||
{"Create", func() (PackagistPayload, error) { return pc.Create(createTestPayload()) }},
|
||||
{"Delete", func() (PackagistPayload, error) { return pc.Delete(deleteTestPayload()) }},
|
||||
{"Fork", func() (PackagistPayload, error) { return pc.Fork(forkTestPayload()) }},
|
||||
{"IssueComment", func() (PackagistPayload, error) { return pc.IssueComment(issueCommentTestPayload()) }},
|
||||
{"PullRequest", func() (PackagistPayload, error) { return pc.PullRequest(pullRequestTestPayload()) }},
|
||||
{"PullRequestComment", func() (PackagistPayload, error) { return pc.IssueComment(pullRequestCommentTestPayload()) }},
|
||||
{"Review", func() (PackagistPayload, error) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
return pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
}},
|
||||
{"Repository", func() (PackagistPayload, error) { return pc.Repository(repositoryTestPayload()) }},
|
||||
{"Package", func() (PackagistPayload, error) { return pc.Package(packageTestPayload()) }},
|
||||
{"Release", func() (PackagistPayload, error) { return pc.Release(pullReleaseTestPayload()) }},
|
||||
} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
pl, err := testCase.call()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
@@ -54,161 +56,69 @@ func TestPackagistPayload(t *testing.T) {
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
p := issueTestPayload()
|
||||
|
||||
p.Action = api.HookIssueOpened
|
||||
pl, err := pc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = pc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
p := issueCommentTestPayload()
|
||||
|
||||
pl, err := pc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
|
||||
pl, err := pc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
p := pullRequestCommentTestPayload()
|
||||
|
||||
pl, err := pc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
|
||||
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
p := repositoryTestPayload()
|
||||
|
||||
pl, err := pc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
p := packageTestPayload()
|
||||
|
||||
pl, err := pc.Package(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
for _, action := range []api.HookIssueAction{api.HookIssueOpened, api.HookIssueClosed} {
|
||||
p.Action = action
|
||||
pl, err := pc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
p := wikiTestPayload()
|
||||
|
||||
p.Action = api.HookWikiCreated
|
||||
pl, err := pc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = pc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = pc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
p := pullReleaseTestPayload()
|
||||
|
||||
pl, err := pc.Release(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
for _, action := range []api.HookWikiAction{api.HookWikiCreated, api.HookWikiEdited, api.HookWikiDeleted} {
|
||||
p.Action = action
|
||||
pl, err := pc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PackagistPayload{}, pl)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestPackagistJSONPayload(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
require.NoError(t, err)
|
||||
for _, testCase := range []struct {
|
||||
event webhook_module.HookEventType
|
||||
payload func() api.Payloader
|
||||
}{
|
||||
{webhook_module.HookEventPush, func() api.Payloader { return pushTestPayload() }},
|
||||
{webhook_module.HookEventCreate, func() api.Payloader { return createTestPayload() }},
|
||||
} {
|
||||
t.Run(string(testCase.event), func(t *testing.T) {
|
||||
data, err := testCase.payload().JSONPayload()
|
||||
require.NoError(t, err)
|
||||
|
||||
hook := &webhook_model.Webhook{
|
||||
RepoID: 3,
|
||||
IsActive: true,
|
||||
Type: webhook_module.PACKAGIST,
|
||||
URL: "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN",
|
||||
Meta: `{"package_url":"https://packagist.org/packages/example"}`,
|
||||
HTTPMethod: "POST",
|
||||
hook := &webhook_model.Webhook{
|
||||
RepoID: 3,
|
||||
IsActive: true,
|
||||
Type: webhook_module.PACKAGIST,
|
||||
URL: "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN",
|
||||
Meta: `{"package_url":"https://packagist.org/packages/example"}`,
|
||||
HTTPMethod: "POST",
|
||||
}
|
||||
task := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: testCase.event,
|
||||
PayloadContent: string(data),
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "POST", req.Method)
|
||||
assert.Equal(t, "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN", req.URL.String())
|
||||
assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256"))
|
||||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body PackagistPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
if testCase.event == webhook_module.HookEventPush {
|
||||
assert.Equal(t, "https://packagist.org/packages/example", body.PackagistRepository.URL)
|
||||
} else {
|
||||
assert.Empty(t, body.PackagistRepository.URL)
|
||||
}
|
||||
})
|
||||
}
|
||||
task := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: webhook_module.HookEventPush,
|
||||
PayloadContent: string(data),
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "POST", req.Method)
|
||||
assert.Equal(t, "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN", req.URL.String())
|
||||
assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256"))
|
||||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body PackagistPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://packagist.org/packages/example", body.PackagistRepository.URL)
|
||||
}
|
||||
|
||||
func TestPackagistEmptyPayload(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
data, err := p.JSONPayload()
|
||||
require.NoError(t, err)
|
||||
|
||||
hook := &webhook_model.Webhook{
|
||||
RepoID: 3,
|
||||
IsActive: true,
|
||||
Type: webhook_module.PACKAGIST,
|
||||
URL: "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN",
|
||||
Meta: `{"package_url":"https://packagist.org/packages/example"}`,
|
||||
HTTPMethod: "POST",
|
||||
}
|
||||
task := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
EventType: webhook_module.HookEventCreate,
|
||||
PayloadContent: string(data),
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "POST", req.Method)
|
||||
assert.Equal(t, "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN", req.URL.String())
|
||||
assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256"))
|
||||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body PackagistPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, body.PackagistRepository.URL)
|
||||
}
|
||||
+76
-120
@@ -18,45 +18,69 @@ import (
|
||||
func TestSlackPayload(t *testing.T) {
|
||||
sc := slackConvertor{}
|
||||
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
|
||||
pl, err := sc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>:<http://localhost:3000/test/repo/src/branch/test|test>] branch created by user1", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
p := deleteTestPayload()
|
||||
|
||||
pl, err := sc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>:test] branch deleted by user1", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
p := forkTestPayload()
|
||||
|
||||
pl, err := sc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "<http://localhost:3000/test/repo2|test/repo2> is forked to <http://localhost:3000/test/repo|test/repo>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
|
||||
pl, err := sc.Push(p)
|
||||
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", pl.Text)
|
||||
require.Len(t, pl.Attachments, 1)
|
||||
assert.Equal(t, "user1", pl.Attachments[0].AuthorName)
|
||||
assert.Equal(t, "http://localhost:3000/user1/avatar", pl.Attachments[0].AuthorIcon)
|
||||
assert.Equal(t, "http://localhost:3000/user1", pl.Attachments[0].AuthorLink)
|
||||
})
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
call func() (SlackPayload, error)
|
||||
text string
|
||||
attachments bool
|
||||
}{
|
||||
{
|
||||
"Create", func() (SlackPayload, error) { return sc.Create(createTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>:<http://localhost:3000/test/repo/src/branch/test|test>] branch created by user1", false,
|
||||
},
|
||||
{
|
||||
"Delete", func() (SlackPayload, error) { return sc.Delete(deleteTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>:test] branch deleted by user1", false,
|
||||
},
|
||||
{
|
||||
"Fork", func() (SlackPayload, error) { return sc.Fork(forkTestPayload()) },
|
||||
"<http://localhost:3000/test/repo2|test/repo2> is forked to <http://localhost:3000/test/repo|test/repo>", false,
|
||||
},
|
||||
{
|
||||
"Push", func() (SlackPayload, error) { return sc.Push(pushTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by user1", true,
|
||||
},
|
||||
{
|
||||
"IssueComment", func() (SlackPayload, error) { return sc.IssueComment(issueCommentTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", true,
|
||||
},
|
||||
{
|
||||
"PullRequest", func() (SlackPayload, error) { return sc.PullRequest(pullRequestTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by <https://try.gitea.io/user1|user1>", true,
|
||||
},
|
||||
{
|
||||
"PullRequestComment", func() (SlackPayload, error) { return sc.IssueComment(pullRequestCommentTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by <https://try.gitea.io/user1|user1>", false,
|
||||
},
|
||||
{
|
||||
"Review", func() (SlackPayload, error) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
return sc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
},
|
||||
"[<http://localhost:3000/test/repo|test/repo>] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by <https://try.gitea.io/user1|user1>", false,
|
||||
},
|
||||
{
|
||||
"Package", func() (SlackPayload, error) { return sc.Package(packageTestPayload()) },
|
||||
"Package created: <http://localhost:3000/user1/-/packages/container/GiteaContainer/latest|GiteaContainer:latest> by <https://try.gitea.io/user1|user1>", false,
|
||||
},
|
||||
{
|
||||
"Release", func() (SlackPayload, error) { return sc.Release(pullReleaseTestPayload()) },
|
||||
"[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/releases/tag/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", false,
|
||||
},
|
||||
} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
pl, err := testCase.call()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.text, pl.Text)
|
||||
if testCase.attachments {
|
||||
require.Len(t, pl.Attachments, 1)
|
||||
assert.Equal(t, "user1", pl.Attachments[0].AuthorName)
|
||||
assert.Equal(t, "http://localhost:3000/user1/avatar", pl.Attachments[0].AuthorIcon)
|
||||
assert.Equal(t, "http://localhost:3000/user1", pl.Attachments[0].AuthorLink)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
p := issueTestPayload()
|
||||
@@ -78,51 +102,6 @@ func TestSlackPayload(t *testing.T) {
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Issue closed: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
p := issueCommentTestPayload()
|
||||
|
||||
pl, err := sc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
require.Len(t, pl.Attachments, 1)
|
||||
assert.Equal(t, "user1", pl.Attachments[0].AuthorName)
|
||||
assert.Equal(t, "http://localhost:3000/user1/avatar", pl.Attachments[0].AuthorIcon)
|
||||
assert.Equal(t, "http://localhost:3000/user1", pl.Attachments[0].AuthorLink)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
|
||||
pl, err := sc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
require.Len(t, pl.Attachments, 1)
|
||||
assert.Equal(t, "user1", pl.Attachments[0].AuthorName)
|
||||
assert.Equal(t, "http://localhost:3000/user1/avatar", pl.Attachments[0].AuthorIcon)
|
||||
assert.Equal(t, "http://localhost:3000/user1", pl.Attachments[0].AuthorLink)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
p := pullRequestCommentTestPayload()
|
||||
|
||||
pl, err := sc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
|
||||
pl, err := sc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
p := repositoryTestPayload()
|
||||
|
||||
@@ -138,44 +117,21 @@ func TestSlackPayload(t *testing.T) {
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Repository renamed from old-repo by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
p := packageTestPayload()
|
||||
|
||||
pl, err := sc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Package created: <http://localhost:3000/user1/-/packages/container/GiteaContainer/latest|GiteaContainer:latest> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
p := wikiTestPayload()
|
||||
|
||||
p.Action = api.HookWikiCreated
|
||||
pl, err := sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New wiki page '<http://localhost:3000/test/repo/wiki/index|index>' (Wiki change comment) by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' edited (Wiki change comment) by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' deleted by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
p := pullReleaseTestPayload()
|
||||
|
||||
pl, err := sc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/releases/tag/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.Text)
|
||||
for _, testCase := range []struct {
|
||||
action api.HookWikiAction
|
||||
text string
|
||||
}{
|
||||
{api.HookWikiCreated, "[<http://localhost:3000/test/repo|test/repo>] New wiki page '<http://localhost:3000/test/repo/wiki/index|index>' (Wiki change comment) by <https://try.gitea.io/user1|user1>"},
|
||||
{api.HookWikiEdited, "[<http://localhost:3000/test/repo|test/repo>] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' edited (Wiki change comment) by <https://try.gitea.io/user1|user1>"},
|
||||
{api.HookWikiDeleted, "[<http://localhost:3000/test/repo|test/repo>] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' deleted by <https://try.gitea.io/user1|user1>"},
|
||||
} {
|
||||
p.Action = testCase.action
|
||||
pl, err := sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.text, pl.Text)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -33,142 +33,98 @@ func TestTelegramPayload(t *testing.T) {
|
||||
assert.Equal(t, "first line<br>second line<br>third line", p.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Create", func(t *testing.T) {
|
||||
p := createTestPayload()
|
||||
|
||||
pl, err := tc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> created`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
p := deleteTestPayload()
|
||||
|
||||
pl, err := tc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> deleted`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
p := forkTestPayload()
|
||||
|
||||
pl, err := tc.Fork(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `test/repo2 is forked to <a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Push", func(t *testing.T) {
|
||||
p := pushTestPayload()
|
||||
|
||||
pl, err := tc.Push(p)
|
||||
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<br>[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1<br>[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1`, pl.RichMessage.HTML)
|
||||
})
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
call func() (TelegramPayload, error)
|
||||
text string
|
||||
}{
|
||||
{
|
||||
"Create", func() (TelegramPayload, error) { return tc.Create(createTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> created`,
|
||||
},
|
||||
{
|
||||
"Delete", func() (TelegramPayload, error) { return tc.Delete(deleteTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> deleted`,
|
||||
},
|
||||
{
|
||||
"Fork", func() (TelegramPayload, error) { return tc.Fork(forkTestPayload()) },
|
||||
`test/repo2 is forked to <a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>`,
|
||||
},
|
||||
{
|
||||
"Push", func() (TelegramPayload, error) { return tc.Push(pushTestPayload()) },
|
||||
`[<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<br>[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1<br>[<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1`,
|
||||
},
|
||||
{
|
||||
"IssueComment", func() (TelegramPayload, error) { return tc.IssueComment(issueCommentTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on issue <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>more info needed`,
|
||||
},
|
||||
{
|
||||
"PullRequest", func() (TelegramPayload, error) { return tc.PullRequest(pullRequestTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Pull request opened: <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>fixes bug #2`,
|
||||
},
|
||||
{
|
||||
"PullRequestComment", func() (TelegramPayload, error) { return tc.IssueComment(pullRequestCommentTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on pull request <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>changes requested`,
|
||||
},
|
||||
{
|
||||
"Review", func() (TelegramPayload, error) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
return tc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
},
|
||||
`[test/repo] Pull request review approved: #12 Fix bug<br>good job`,
|
||||
},
|
||||
{
|
||||
"Repository", func() (TelegramPayload, error) { return tc.Repository(repositoryTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Repository created`,
|
||||
},
|
||||
{
|
||||
"Package", func() (TelegramPayload, error) { return tc.Package(packageTestPayload()) },
|
||||
`Package created: <a href="http://localhost:3000/user1/-/packages/container/GiteaContainer/latest" rel="nofollow">GiteaContainer:latest</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`,
|
||||
},
|
||||
{
|
||||
"Release", func() (TelegramPayload, error) { return tc.Release(pullReleaseTestPayload()) },
|
||||
`[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0" rel="nofollow">v1.0</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`,
|
||||
},
|
||||
} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
pl, err := testCase.call()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.text, pl.RichMessage.HTML)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
p := issueTestPayload()
|
||||
|
||||
p.Action = api.HookIssueOpened
|
||||
pl, err := tc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue opened: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br><br>issue body`, pl.RichMessage.HTML)
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = tc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue closed: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
p := issueCommentTestPayload()
|
||||
|
||||
pl, err := tc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on issue <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>more info needed`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
|
||||
pl, err := tc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Pull request opened: <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>fixes bug #2`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
p := pullRequestCommentTestPayload()
|
||||
|
||||
pl, err := tc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on pull request <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br>changes requested`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
p := pullRequestTestPayload()
|
||||
p.Action = api.HookIssueReviewed
|
||||
|
||||
pl, err := tc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[test/repo] Pull request review approved: #12 Fix bug<br>good job`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
p := repositoryTestPayload()
|
||||
|
||||
pl, err := tc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Repository created`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
p := packageTestPayload()
|
||||
|
||||
pl, err := tc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `Package created: <a href="http://localhost:3000/user1/-/packages/container/GiteaContainer/latest" rel="nofollow">GiteaContainer:latest</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
for _, testCase := range []struct {
|
||||
action api.HookIssueAction
|
||||
text string
|
||||
}{
|
||||
{api.HookIssueOpened, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue opened: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a><br><br>issue body`},
|
||||
{api.HookIssueClosed, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue closed: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`},
|
||||
} {
|
||||
p.Action = testCase.action
|
||||
pl, err := tc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.text, pl.RichMessage.HTML)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
p := wikiTestPayload()
|
||||
|
||||
p.Action = api.HookWikiCreated
|
||||
pl, err := tc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = tc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' edited (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = tc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' deleted by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
p := pullReleaseTestPayload()
|
||||
|
||||
pl, err := tc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0" rel="nofollow">v1.0</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.RichMessage.HTML)
|
||||
for _, testCase := range []struct {
|
||||
action api.HookWikiAction
|
||||
text string
|
||||
}{
|
||||
{api.HookWikiCreated, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`},
|
||||
{api.HookWikiEdited, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' edited (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`},
|
||||
{api.HookWikiDeleted, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>' deleted by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`},
|
||||
} {
|
||||
p.Action = testCase.action
|
||||
pl, err := tc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.text, pl.RichMessage.HTML)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user