You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slack_test.go 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package webhook
  5. import (
  6. "testing"
  7. api "code.gitea.io/gitea/modules/structs"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestSlackIssuesPayloadOpened(t *testing.T) {
  12. p := issueTestPayload()
  13. sl := &SlackMeta{
  14. Username: p.Sender.UserName,
  15. }
  16. p.Action = api.HookIssueOpened
  17. pl, err := getSlackIssuesPayload(p, sl)
  18. require.Nil(t, err)
  19. require.NotNil(t, pl)
  20. 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)
  21. p.Action = api.HookIssueClosed
  22. pl, err = getSlackIssuesPayload(p, sl)
  23. require.Nil(t, err)
  24. require.NotNil(t, pl)
  25. 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)
  26. }
  27. func TestSlackIssueCommentPayload(t *testing.T) {
  28. p := issueCommentTestPayload()
  29. sl := &SlackMeta{
  30. Username: p.Sender.UserName,
  31. }
  32. pl, err := getSlackIssueCommentPayload(p, sl)
  33. require.Nil(t, err)
  34. require.NotNil(t, pl)
  35. 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)
  36. }
  37. func TestSlackPullRequestCommentPayload(t *testing.T) {
  38. p := pullRequestCommentTestPayload()
  39. sl := &SlackMeta{
  40. Username: p.Sender.UserName,
  41. }
  42. pl, err := getSlackIssueCommentPayload(p, sl)
  43. require.Nil(t, err)
  44. require.NotNil(t, pl)
  45. 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)
  46. }
  47. func TestSlackReleasePayload(t *testing.T) {
  48. p := pullReleaseTestPayload()
  49. sl := &SlackMeta{
  50. Username: p.Sender.UserName,
  51. }
  52. pl, err := getSlackReleasePayload(p, sl)
  53. require.Nil(t, err)
  54. require.NotNil(t, pl)
  55. assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release <http://localhost:3000/test/repo/src/v1.0|v1.0> created by <https://try.gitea.io/user1|user1>", pl.Text)
  56. }
  57. func TestSlackPullRequestPayload(t *testing.T) {
  58. p := pullRequestTestPayload()
  59. sl := &SlackMeta{
  60. Username: p.Sender.UserName,
  61. }
  62. pl, err := getSlackPullRequestPayload(p, sl)
  63. require.Nil(t, err)
  64. require.NotNil(t, pl)
  65. assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request <http://localhost:3000/test/repo/pulls/12|#2 Fix bug> opened by <https://try.gitea.io/user1|user1>", pl.Text)
  66. }