-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76d627a
commit a6b8aa4
Showing
3 changed files
with
176 additions
and
1 deletion.
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
85 changes: 85 additions & 0 deletions
85
src/test/groovy/com/lesfurets/jenkins/TestSharedLibraryWithProjectSourceRetriever.groovy
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 @@ | ||
package com.lesfurets.jenkins | ||
|
||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library | ||
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource | ||
import static org.assertj.core.api.Assertions.assertThat | ||
|
||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import org.junit.runners.Parameterized.Parameter | ||
import org.junit.runners.Parameterized.Parameters | ||
|
||
import com.lesfurets.jenkins.unit.BasePipelineTest | ||
|
||
@RunWith(Parameterized.class) | ||
class TestSharedLibraryWithProjectSourceRetriever extends BasePipelineTest { | ||
|
||
// For simplicity we use the common@master here. In this case 'commons@master' | ||
// does not denote the master branch of the commons lib. In this case it is | ||
// just a folder containing the lib. ProjectSourceRetriever is by design | ||
// agnostic to branches and agnostic to library names. | ||
// By default ProjectSourceRetriever works upon '.', which is the project | ||
// root directory. Here for testing the retriever is used in a way so that | ||
// it refers to the folder mentioned below. | ||
String sharedLibs = this.class.getResource('/libs/commons@master').getFile() | ||
|
||
@Parameter(0) | ||
public String script | ||
@Parameter(1) | ||
public boolean allowOverride | ||
@Parameter(2) | ||
public boolean implicit | ||
@Parameter(3) | ||
public boolean expected | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins' | ||
super.setUp() | ||
} | ||
|
||
@Parameters(name = "Test {0} allowOverride:{1} implicit:{2} expected:{3}") | ||
static Collection<Object[]> data() { | ||
return [['libraryJob', false, false, false], | ||
['libraryJob', false, false, false], | ||
['libraryJob_implicit', false, false, true], | ||
['libraryJob_implicit', false, true, false], | ||
|
||
// Utils2, denoted in the job below, cannot be resolved | ||
// since we do not have the lib from the feature branch | ||
// despite this is requested in the pipeline. | ||
// ProjectSourceRetriever does by design | ||
// not take branches into account. | ||
['libraryJob_feature', true, true, true], | ||
|
||
].collect { it as Object[] } | ||
} | ||
|
||
@Test | ||
void library_annotation() throws Exception { | ||
boolean exception = false | ||
def library = library().name('commons') | ||
.defaultVersion('<notNeeded>') | ||
.allowOverride(allowOverride) | ||
.implicit(implicit) | ||
.targetPath('<notNeeded>') | ||
.retriever(projectSource(sharedLibs)) | ||
.build() | ||
helper.registerSharedLibrary(library) | ||
try { | ||
def script = runScript("job/library/${script}.jenkins") | ||
script.execute() | ||
printCallStack() | ||
} catch (e) { | ||
e.printStackTrace() | ||
exception = true | ||
} | ||
assertThat(expected).isEqualTo(exception) | ||
|
||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/test/groovy/com/lesfurets/jenkins/TestSharedLibraryWithProjectSourceRetrieverCPS.groovy
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 @@ | ||
package com.lesfurets.jenkins | ||
|
||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library | ||
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource | ||
import static org.assertj.core.api.Assertions.assertThat | ||
|
||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import org.junit.runners.Parameterized.Parameter | ||
import org.junit.runners.Parameterized.Parameters | ||
|
||
import com.lesfurets.jenkins.unit.cps.BasePipelineTestCPS | ||
|
||
@RunWith(Parameterized.class) | ||
class TestSharedLibraryWithProjectSourceRetrieverCPS extends BasePipelineTestCPS { | ||
|
||
// For simplicity we use the common@master here. In this case 'commons@master' | ||
// does not denote the master branch of the commons lib. In this case it is | ||
// just a folder containing the lib. ProjectSourceRetriever is by design | ||
// agnostic to branches and agnostic to library names. | ||
// By default ProjectSourceRetriever works upon '.', which is the project | ||
// root directory. Here for testing the retriever is used in a way so that | ||
// it refers to the folder mentioned below. | ||
String sharedLibs = this.class.getResource('/libs/commons@master').getFile() | ||
|
||
@Parameter(0) | ||
public String script | ||
@Parameter(1) | ||
public boolean allowOverride | ||
@Parameter(2) | ||
public boolean implicit | ||
@Parameter(3) | ||
public boolean expected | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins' | ||
super.setUp() | ||
} | ||
|
||
@Parameters(name = "Test {0} allowOverride:{1} implicit:{2} expected:{3}") | ||
static Collection<Object[]> data() { | ||
return [['libraryJob', false, false, false], | ||
['libraryJob', false, false, false], | ||
['libraryJob_implicit', false, false, true], | ||
['libraryJob_implicit', false, true, false], | ||
|
||
// Utils2, denoted in the job below, cannot be resolved | ||
// since we do not have the lib from the feature branch | ||
// despite this is requested in the pipeline. | ||
// ProjectSourceRetriever does by design | ||
// not take branches into account. | ||
['libraryJob_feature', true, true, true], | ||
|
||
].collect { it as Object[] } | ||
} | ||
|
||
@Test | ||
void library_annotation() throws Exception { | ||
boolean exception = false | ||
def library = library().name('commons') | ||
.defaultVersion('<notNeeded>') | ||
.allowOverride(allowOverride) | ||
.implicit(implicit) | ||
.targetPath('<notNeeded>') | ||
.retriever(projectSource(sharedLibs)) | ||
.build() | ||
helper.registerSharedLibrary(library) | ||
try { | ||
def script = runScript("job/library/${script}.jenkins") | ||
script.execute() | ||
printCallStack() | ||
} catch (e) { | ||
e.printStackTrace() | ||
exception = true | ||
} | ||
assertThat(expected).isEqualTo(exception) | ||
|
||
} | ||
} |