Skip to content

Commit 0784042

Browse files
committed
#153 add tests and refactor
1 parent 51e6770 commit 0784042

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/com/cloudogu/ces/cesbuildlib/Makefile.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Makefile {
2929
}
3030

3131
/**
32-
* Creates the develop branch for Git Flow based on the base version.
32+
* Determines the develop branch for Git Flow based on the base version.
3333
*/
34-
String getGitFlowDevelopBranch() {
34+
String determineGitFlowDevelopBranch() {
3535
def develop = "develop"
3636
def baseVersion = getBaseVersion()
3737
if (baseVersion != null && baseVersion != "") {
@@ -41,9 +41,9 @@ class Makefile {
4141
}
4242

4343
/**
44-
* Creates the main branch for Git Flow based on the base version.
44+
* Determines the main branch for Git Flow based on the base version.
4545
*/
46-
String getGitFlowMainBranch(defaultBranch="main") {
46+
String determineGitFlowMainBranch(defaultBranch="main") {
4747
def baseVersion = getBaseVersion()
4848
if (baseVersion != null && baseVersion != "") {
4949
// The master branch is legacy so we don't create one here, even if it was passed as parameter.

test/com/cloudogu/ces/cesbuildlib/MakefileTest.groovy

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cloudogu.ces.cesbuildlib
22

33
import org.junit.Test
4+
import org.junit.jupiter.api.DisplayName
45

56
import static org.assertj.core.api.Assertions.assertThat
67

@@ -39,7 +40,7 @@ class MakefileTest {
3940

4041
Makefile makefile = new Makefile(scriptMock)
4142

42-
def result = makefile.getDevelopBranchName()
43+
def result = makefile.determineGitFlowDevelopBranch()
4344

4445
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
4546
assertThat(result).isEqualTo("4.2.2/develop")
@@ -52,7 +53,7 @@ class MakefileTest {
5253

5354
Makefile makefile = new Makefile(scriptMock)
5455

55-
def result = makefile.getMainBranchName()
56+
def result = makefile.determineGitFlowMainBranch()
5657

5758
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
5859
assertThat(result).isEqualTo("4.2.2/main")
@@ -65,7 +66,7 @@ class MakefileTest {
6566

6667
Makefile makefile = new Makefile(scriptMock)
6768

68-
def result = makefile.getDevelopBranchName()
69+
def result = makefile.determineGitFlowDevelopBranch()
6970

7071
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
7172
assertThat(result).isEqualTo("develop")
@@ -78,9 +79,37 @@ class MakefileTest {
7879

7980
Makefile makefile = new Makefile(scriptMock)
8081

81-
def result = makefile.getMainBranchName()
82+
def result = makefile.determineGitFlowMainBranch()
8283

8384
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
8485
assertThat(result).isEqualTo("main")
8586
}
87+
88+
@Test
89+
@DisplayName("should replace master with main if BASE_VERSION is used and the default branch is master")
90+
void shouldReplaceMasterWithMain() {
91+
def scriptMock = new ScriptMock()
92+
scriptMock.expectedShRetValueForScript.put('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString(), "4.5".toString())
93+
94+
Makefile makefile = new Makefile(scriptMock)
95+
96+
def result = makefile.determineGitFlowMainBranch("master")
97+
98+
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
99+
assertThat(result).isEqualTo("4.5/main")
100+
}
101+
102+
@Test
103+
@DisplayName("should use default branch if BASE_VERSION is not used")
104+
void shouldUseDefaultBranch() {
105+
def scriptMock = new ScriptMock()
106+
scriptMock.expectedShRetValueForScript.put('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString(), "".toString())
107+
108+
Makefile makefile = new Makefile(scriptMock)
109+
110+
def result = makefile.determineGitFlowMainBranch("master")
111+
112+
assertThat(scriptMock.allActualArgs[0]).isEqualTo('grep -e "^BASE_VERSION=" Makefile | sed "s/BASE_VERSION=//g"'.toString())
113+
assertThat(result).isEqualTo("master")
114+
}
86115
}

0 commit comments

Comments
 (0)