summaryrefslogtreecommitdiffstats
path: root/modules/webhook/slack_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-09-05 10:57:13 +0800
committerGitHub <noreply@github.com>2020-09-04 22:57:13 -0400
commitb51bd7f1d62cd623601185162d84ac29adb25366 (patch)
tree95ce8ebda0a5cf65a44385b7017325338529d583 /modules/webhook/slack_test.go
parente1535c74cc494dce85ea5c2e8a25665bed444217 (diff)
downloadgitea-b51bd7f1d62cd623601185162d84ac29adb25366.tar.gz
gitea-b51bd7f1d62cd623601185162d84ac29adb25366.zip
Refactor webhook payload convertion (#12310)
* Refactor webhook payload convertion * Fix lint Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/webhook/slack_test.go')
-rw-r--r--modules/webhook/slack_test.go56
1 files changed, 24 insertions, 32 deletions
diff --git a/modules/webhook/slack_test.go b/modules/webhook/slack_test.go
index 15503434f8..20de80bd65 100644
--- a/modules/webhook/slack_test.go
+++ b/modules/webhook/slack_test.go
@@ -14,75 +14,67 @@ import (
func TestSlackIssuesPayloadOpened(t *testing.T) {
p := issueTestPayload()
- sl := &SlackMeta{
- Username: p.Sender.UserName,
- }
-
p.Action = api.HookIssueOpened
- pl, err := getSlackIssuesPayload(p, sl)
+
+ s := new(SlackPayload)
+ s.Username = p.Sender.UserName
+
+ pl, err := s.Issue(p)
require.NoError(t, err)
require.NotNil(t, pl)
- assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
+ assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
p.Action = api.HookIssueClosed
- pl, err = getSlackIssuesPayload(p, sl)
+ pl, err = s.Issue(p)
require.NoError(t, err)
require.NotNil(t, pl)
- 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)
+ 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.(*SlackPayload).Text)
}
func TestSlackIssueCommentPayload(t *testing.T) {
p := issueCommentTestPayload()
+ s := new(SlackPayload)
+ s.Username = p.Sender.UserName
- sl := &SlackMeta{
- Username: p.Sender.UserName,
- }
-
- pl, err := getSlackIssueCommentPayload(p, sl)
+ pl, err := s.IssueComment(p)
require.NoError(t, err)
require.NotNil(t, pl)
- 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)
+ 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.(*SlackPayload).Text)
}
func TestSlackPullRequestCommentPayload(t *testing.T) {
p := pullRequestCommentTestPayload()
+ s := new(SlackPayload)
+ s.Username = p.Sender.UserName
- sl := &SlackMeta{
- Username: p.Sender.UserName,
- }
-
- pl, err := getSlackIssueCommentPayload(p, sl)
+ pl, err := s.IssueComment(p)
require.NoError(t, err)
require.NotNil(t, pl)
- assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/2|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)
+ assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/2|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
}
func TestSlackReleasePayload(t *testing.T) {
p := pullReleaseTestPayload()
+ s := new(SlackPayload)
+ s.Username = p.Sender.UserName
- sl := &SlackMeta{
- Username: p.Sender.UserName,
- }
-
- pl, err := getSlackReleasePayload(p, sl)
+ pl, err := s.Release(p)
require.NoError(t, err)
require.NotNil(t, pl)
- assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.Text)
+ assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
}
func TestSlackPullRequestPayload(t *testing.T) {
p := pullRequestTestPayload()
+ s := new(SlackPayload)
+ s.Username = p.Sender.UserName
- sl := &SlackMeta{
- Username: p.Sender.UserName,
- }
-
- pl, err := getSlackPullRequestPayload(p, sl)
+ pl, err := s.PullRequest(p)
require.NoError(t, err)
require.NotNil(t, pl)
- assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)
+ assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
}