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.

79 lines
2.6 KiB

  1. import groovy.util.GroovyTestCase
  2. import org.wikimedia.integration.GerritPipelineComment
  3. class GerritCommentTestCase extends GroovyTestCase {
  4. private GerritPipelineComment gerritComment
  5. void testGetDashboardOutput() {
  6. gerritComment = new GerritPipelineComment(
  7. jobName: "service-pipeline-test-and-publish"
  8. )
  9. assert gerritComment.formatDashboard() == 'pipeline-dashboard: service-pipeline-test-and-publish'
  10. }
  11. void testGetResultOutput() {
  12. gerritComment = new GerritPipelineComment(
  13. jobName: 'service-pipeline-test-and-publish',
  14. jobStatus: 'SUCCESS',
  15. buildNumber: '25'
  16. )
  17. assert gerritComment.formatResult() == \
  18. 'pipeline-build-result: SUCCESS (job: service-pipeline-test-and-publish, build: 25)'
  19. }
  20. void testGetFormatImage() {
  21. def imageName = 'docker-registry.wikimedia.org/wikimedia/mediawiki-services-citoid'
  22. def expected = "IMAGE:\n ${imageName}"
  23. gerritComment = new GerritPipelineComment(image: imageName)
  24. assert gerritComment.formatImage() == expected
  25. }
  26. void testGetFormatTags() {
  27. def tags = ['2019-02-11-214153-production', 'fc52e49b051872b282c6a66be6649c7d437bf066']
  28. def expected = "TAGS:\n 2019-02-11-214153-production, fc52e49b051872b282c6a66be6649c7d437bf066"
  29. gerritComment = new GerritPipelineComment(tags: tags)
  30. assert gerritComment.formatTags() == expected
  31. }
  32. void testwithoutImage() {
  33. def expected = '''\
  34. pipeline-dashboard: service-pipeline-test-and-publish
  35. pipeline-build-result: SUCCESS (job: service-pipeline-test-and-publish, build: 25)
  36. '''.stripIndent()
  37. gerritComment = new GerritPipelineComment(
  38. jobName: 'service-pipeline-test-and-publish',
  39. jobStatus: 'SUCCESS',
  40. buildNumber: '25',
  41. )
  42. assert gerritComment.formatMessage() == expected
  43. }
  44. void testwithImage() {
  45. def tags = ['2019-02-11-214153-production', 'fc52e49b051872b282c6a66be6649c7d437bf066']
  46. def imageName = 'docker-registry.wikimedia.org/wikimedia/mediawiki-services-citoid'
  47. def expected = '''\
  48. pipeline-dashboard: service-pipeline-test-and-publish
  49. pipeline-build-result: SUCCESS (job: service-pipeline-test-and-publish, build: 25)
  50. IMAGE:
  51. docker-registry.wikimedia.org/wikimedia/mediawiki-services-citoid
  52. TAGS:
  53. 2019-02-11-214153-production, fc52e49b051872b282c6a66be6649c7d437bf066
  54. '''.stripIndent()
  55. gerritComment = new GerritPipelineComment(
  56. jobName: 'service-pipeline-test-and-publish',
  57. jobStatus: 'SUCCESS',
  58. buildNumber: '25',
  59. image: imageName,
  60. tags: tags
  61. )
  62. assert gerritComment.formatMessage() == expected
  63. }
  64. }