1+ #! ./test/libs/bats/bin/bats
2+
3+ load ' libs/bats-support/load'
4+ load ' libs/bats-assert/load'
5+
6+ source " $PWD /concourse-java.sh"
7+
8+ @test " get_next_milestone_release() when has no version should fail" {
9+ run get_next_milestone_release
10+ assert [ " $status " -eq 1 ]
11+ assert_output " missing get_next_milestone_release() version argument"
12+ }
13+
14+ @test " get_next_rc_release() when has no version should fail" {
15+ run get_next_rc_release
16+ assert [ " $status " -eq 1 ]
17+ assert_output " missing get_next_rc_release() version argument"
18+ }
19+
20+ @test " get_next_tag_based_release() when has no version should fail" {
21+ run get_next_tag_based_release
22+ assert [ " $status " -eq 1 ]
23+ assert_output " missing get_next_tag_based_release() version argument"
24+ }
25+
26+ @test " get_next_tag_based_release() when has no tag type should fail" {
27+ run get_next_tag_based_release " 1.2.3"
28+ assert [ " $status " -eq 1 ]
29+ assert_output " missing get_next_tag_based_release() tag type argument"
30+ }
31+
32+ @test " get_next_milestone_release() when has no tag should return M1" {
33+ repo=$( mock_git_repo )
34+ cd " $repo "
35+ run get_next_milestone_release " 1.2.3-SNAPSHOT"
36+ assert_output " 1.2.3-M1"
37+ }
38+
39+ @test " get_next_rc_release() when has no tag should return RC1" {
40+ repo=$( mock_git_repo )
41+ cd " $repo "
42+ run get_next_rc_release " 1.2.3-SNAPSHOT"
43+ assert_output " 1.2.3-RC1"
44+ }
45+
46+ @test " get_next_tag_based_release() when has no tag and dashed should return dashed X1" {
47+ repo=$( mock_git_repo )
48+ cd " $repo "
49+ run get_next_tag_based_release " 1.2.3-SNAPSHOT" " X"
50+ assert_output " 1.2.3-X1"
51+ }
52+
53+ @test " get_next_tag_based_release() when has no tag and dashed should return dashed X1" {
54+ repo=$( mock_git_repo )
55+ cd " $repo "
56+ run get_next_tag_based_release " 1.2.3.BUILD-SNAPSHOT" " X"
57+ assert_output " 1.2.3.X1"
58+ }
59+
60+ @test " get_next_tag_based_release() when has tags and dashed should return dashed X tag+1" {
61+ repo=$( mock_git_repo " v1.2.3-X1" " v1.2.3-X3" " v1.2.3-X2" )
62+ cd " $repo "
63+ run get_next_tag_based_release " 1.2.3-SNAPSHOT" " X"
64+ assert_output " 1.2.3-X4"
65+ }
66+
67+ @test " get_next_tag_based_release() when has tags and dashed should return dot X tag+1" {
68+ repo=$( mock_git_repo " v1.2.3.X1" " v1.2.3.X3" " v1.2.3.X2" )
69+ cd " $repo "
70+ run get_next_tag_based_release " 1.2.3.BUILD-SNAPSHOT" " X"
71+ assert_output " 1.2.3.X4"
72+ }
73+
74+ @test " get_next_tag_based_release() when has multiple tags should return version match tag+1" {
75+ repo=$( mock_git_repo " v1.5.0.A1" " v1.5.0.A2" " v1.5.0.B1" " v2.0.0.A1" " v2.0.0.B1" " v2.0.0.B2" )
76+ cd " $repo "
77+ run get_next_tag_based_release " 1.5.0.BUILD-SNAPSHOT" " A"
78+ assert_output " 1.5.0.A3"
79+ run get_next_tag_based_release " 1.5.0.BUILD-SNAPSHOT" " B"
80+ assert_output " 1.5.0.B2"
81+ run get_next_tag_based_release " 2.0.0.BUILD-SNAPSHOT" " A"
82+ assert_output " 2.0.0.A2"
83+ run get_next_tag_based_release " 2.0.0.BUILD-SNAPSHOT" " B"
84+ assert_output " 2.0.0.B3"
85+ }
86+
87+ mock_git_repo () {
88+ local tmpdir=$( mktemp -d $BATS_TMPDIR /gitrepo.XXXXXX) >&2
89+ mkdir -p " $tmpdir " >&2
90+ cd " $tmpdir " >&2
91+ git init >&2
92+ echo " foo" > foo.txt
93+ git add foo.txt >&2
94+ git commit -m' Initial commit' >&2
95+ for tag in " $@ " ; do
96+ git tag " $tag " >&2
97+ done
98+ echo " $tmpdir "
99+ }
0 commit comments