diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-12-08 18:41:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 11:41:14 +0100 |
commit | 42354dfe45fa0cabb59674b896c44a55a56cf163 (patch) | |
tree | 86b859881da6ef6bf288183933d7bc519dedc3d4 /services/webhook/slack_test.go | |
parent | 4d66ee1f74799196cbdbfd925c3f95e552584b42 (diff) | |
download | gitea-42354dfe45fa0cabb59674b896c44a55a56cf163.tar.gz gitea-42354dfe45fa0cabb59674b896c44a55a56cf163.zip |
Move webhook type from int to string (#13664)
* Move webhook type from int to string
* rename webhook_services
* finish refactor
* Fix merge
* Ignore unnecessary ci
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'services/webhook/slack_test.go')
-rw-r--r-- | services/webhook/slack_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/services/webhook/slack_test.go b/services/webhook/slack_test.go new file mode 100644 index 0000000000..20de80bd65 --- /dev/null +++ b/services/webhook/slack_test.go @@ -0,0 +1,80 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package webhook + +import ( + "testing" + + api "code.gitea.io/gitea/modules/structs" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestSlackIssuesPayloadOpened(t *testing.T) { + p := issueTestPayload() + p.Action = api.HookIssueOpened + + 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.(*SlackPayload).Text) + + p.Action = api.HookIssueClosed + 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.(*SlackPayload).Text) +} + +func TestSlackIssueCommentPayload(t *testing.T) { + p := issueCommentTestPayload() + s := new(SlackPayload) + s.Username = p.Sender.UserName + + 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.(*SlackPayload).Text) +} + +func TestSlackPullRequestCommentPayload(t *testing.T) { + p := pullRequestCommentTestPayload() + s := new(SlackPayload) + s.Username = p.Sender.UserName + + 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.(*SlackPayload).Text) +} + +func TestSlackReleasePayload(t *testing.T) { + p := pullReleaseTestPayload() + s := new(SlackPayload) + s.Username = p.Sender.UserName + + 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.(*SlackPayload).Text) +} + +func TestSlackPullRequestPayload(t *testing.T) { + p := pullRequestTestPayload() + s := new(SlackPayload) + s.Username = p.Sender.UserName + + 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.(*SlackPayload).Text) +} |