-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-legacy-links
- Loading branch information
Showing
77 changed files
with
1,066 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import org.junit.* | ||
import static groovy.test.GroovyAssert.* | ||
|
||
class BuildStateTest extends KibanaBasePipelineTest { | ||
def buildState | ||
|
||
@Before | ||
void setUp() { | ||
super.setUp() | ||
|
||
buildState = loadScript("vars/buildState.groovy") | ||
} | ||
|
||
@Test | ||
void 'get() returns existing data'() { | ||
buildState.add('test', 1) | ||
def actual = buildState.get('test') | ||
assertEquals(1, actual) | ||
} | ||
|
||
@Test | ||
void 'get() returns null for missing data'() { | ||
def actual = buildState.get('missing_key') | ||
assertEquals(null, actual) | ||
} | ||
|
||
@Test | ||
void 'add() does not overwrite existing keys'() { | ||
assertTrue(buildState.add('test', 1)) | ||
assertFalse(buildState.add('test', 2)) | ||
|
||
def actual = buildState.get('test') | ||
|
||
assertEquals(1, actual) | ||
} | ||
|
||
@Test | ||
void 'set() overwrites existing keys'() { | ||
assertFalse(buildState.has('test')) | ||
buildState.set('test', 1) | ||
assertTrue(buildState.has('test')) | ||
buildState.set('test', 2) | ||
|
||
def actual = buildState.get('test') | ||
|
||
assertEquals(2, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import org.junit.* | ||
import static org.mockito.Mockito.*; | ||
|
||
class GithubCommitStatusTest extends KibanaBasePipelineTest { | ||
def githubCommitStatus | ||
def githubApiMock | ||
def buildStateMock | ||
|
||
def EXPECTED_STATUS_URL = 'repos/elastic/kibana/statuses/COMMIT_HASH' | ||
def EXPECTED_CONTEXT = 'kibana-ci' | ||
def EXPECTED_BUILD_URL = 'http://jenkins.localhost:8080/job/elastic+kibana+master/1/' | ||
|
||
interface BuildState { | ||
Object get(String key) | ||
} | ||
|
||
interface GithubApi { | ||
Object post(String url, Map data) | ||
} | ||
|
||
@Before | ||
void setUp() { | ||
super.setUp() | ||
|
||
buildStateMock = mock(BuildState) | ||
githubApiMock = mock(GithubApi) | ||
|
||
when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ]) | ||
when(githubApiMock.post(any(), any())).thenReturn(null) | ||
|
||
props([ | ||
buildState: buildStateMock, | ||
githubApi: githubApiMock, | ||
]) | ||
|
||
githubCommitStatus = loadScript("vars/githubCommitStatus.groovy") | ||
} | ||
|
||
void verifyStatusCreate(String state, String description) { | ||
verify(githubApiMock).post( | ||
EXPECTED_STATUS_URL, | ||
[ | ||
'state': state, | ||
'description': description, | ||
'context': EXPECTED_CONTEXT, | ||
'target_url': EXPECTED_BUILD_URL, | ||
] | ||
) | ||
} | ||
|
||
@Test | ||
void 'onStart() should create a pending status'() { | ||
githubCommitStatus.onStart() | ||
verifyStatusCreate('pending', 'Build started.') | ||
} | ||
|
||
@Test | ||
void 'onFinish() should create a success status'() { | ||
githubCommitStatus.onFinish() | ||
verifyStatusCreate('success', 'Build completed successfully.') | ||
} | ||
|
||
@Test | ||
void 'onFinish() should create an error status for failed builds'() { | ||
mockFailureBuild() | ||
githubCommitStatus.onFinish() | ||
verifyStatusCreate('error', 'Build failed.') | ||
} | ||
|
||
@Test | ||
void 'onStart() should exit early for PRs'() { | ||
prop('githubPr', [ isPr: { true } ]) | ||
|
||
githubCommitStatus.onStart() | ||
verifyZeroInteractions(githubApiMock) | ||
} | ||
|
||
@Test | ||
void 'onFinish() should exit early for PRs'() { | ||
prop('githubPr', [ isPr: { true } ]) | ||
|
||
githubCommitStatus.onFinish() | ||
verifyZeroInteractions(githubApiMock) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.