-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from jonesbusy/feature/jcasc-tests
Add JCasC, local data and JobDSL tests
- Loading branch information
Showing
12 changed files
with
278 additions
and
0 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
57 changes: 57 additions & 0 deletions
57
src/test/java/jenkins/plugins/itemstorage/ConfigurationAsCodeCompatibilityTest.java
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,57 @@ | ||
package jenkins.plugins.itemstorage; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import jenkins.plugins.itemstorage.local.LocalItemStorage; | ||
import jenkins.plugins.itemstorage.s3.NonAWSS3ItemStorage; | ||
import jenkins.plugins.itemstorage.s3.S3ItemStorage; | ||
|
||
public class ConfigurationAsCodeCompatibilityTest { | ||
|
||
@Rule | ||
public JenkinsConfiguredWithCodeRule jenkins = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
@ConfiguredWithCode("local.yml") | ||
public void shouldSupportConfigurationAsCodeForLocalStorage() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
LocalItemStorage localItemStorage = (LocalItemStorage) storage; | ||
assertThat(localItemStorage.getRoot(), is("jobcaches")); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("nonaws.yml") | ||
public void shouldSupportConfigurationAsCodeForNonAws() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
NonAWSS3ItemStorage s3ItemStorage = (NonAWSS3ItemStorage) storage; | ||
assertThat(s3ItemStorage.getBucketName(), is("caches")); | ||
assertThat(s3ItemStorage.getRegion(), is("eu-central-2")); | ||
assertThat(s3ItemStorage.getCredentialsId(), is("s3")); | ||
assertThat(s3ItemStorage.getPrefix(), is("the-prefix/")); | ||
assertThat(s3ItemStorage.getEndpoint(), is("http://localhost:9000")); | ||
assertThat(s3ItemStorage.getParallelDownloads(), is(false)); | ||
assertThat(s3ItemStorage.getPathStyleAccess(), is(true)); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("aws.yml") | ||
public void shouldSupportConfigurationAsCodeForAws() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
S3ItemStorage s3ItemStorage = (S3ItemStorage) storage; | ||
assertThat(s3ItemStorage.getBucketName(), is("caches")); | ||
assertThat(s3ItemStorage.getRegion(), is("eu-central-2")); | ||
assertThat(s3ItemStorage.getCredentialsId(), is("s3")); | ||
assertThat(s3ItemStorage.getPrefix(), is("the-prefix/")); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/jenkins/plugins/itemstorage/DataMigrationTest.java
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,57 @@ | ||
package jenkins.plugins.itemstorage; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import jenkins.plugins.itemstorage.local.LocalItemStorage; | ||
import jenkins.plugins.itemstorage.s3.NonAWSS3ItemStorage; | ||
import jenkins.plugins.itemstorage.s3.S3ItemStorage; | ||
|
||
public class DataMigrationTest { | ||
|
||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
@Test | ||
@LocalData | ||
public void shouldMigrateLocalData() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
LocalItemStorage localItemStorage = (LocalItemStorage) storage; | ||
assertThat(localItemStorage.getRoot(), is("jobcaches")); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void shouldMigrateAwsData() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
S3ItemStorage s3ItemStorage = (S3ItemStorage) storage; | ||
assertThat(s3ItemStorage.getBucketName(), is("bucket1")); | ||
assertThat(s3ItemStorage.getRegion(), is("us-gov-west-1")); | ||
assertThat(s3ItemStorage.getCredentialsId(), is("s3")); | ||
assertThat(s3ItemStorage.getPrefix(), is("the-prefix/")); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void shouldMigrateNonAwsData() { | ||
ItemStorage<?> storage = GlobalItemStorage.get().getStorage(); | ||
assertThat(storage, is(notNullValue())); | ||
NonAWSS3ItemStorage s3ItemStorage = (NonAWSS3ItemStorage) storage; | ||
assertThat(s3ItemStorage.getBucketName(), is("bucket1")); | ||
assertThat(s3ItemStorage.getRegion(), is("eu-central-2")); | ||
assertThat(s3ItemStorage.getCredentialsId(), is("s3")); | ||
assertThat(s3ItemStorage.getPrefix(), is("the-prefix/")); | ||
assertThat(s3ItemStorage.getEndpoint(), is("http://localhost:9000")); | ||
assertThat(s3ItemStorage.getParallelDownloads(), is(true)); | ||
assertThat(s3ItemStorage.getPathStyleAccess(), is(true)); | ||
} | ||
|
||
} |
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,57 @@ | ||
package jenkins.plugins.jobdsl; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import javaposse.jobdsl.plugin.ExecuteDslScripts; | ||
import javaposse.jobdsl.plugin.LookupStrategy; | ||
import javaposse.jobdsl.plugin.RemovedJobAction; | ||
import javaposse.jobdsl.plugin.RemovedViewAction; | ||
import jenkins.plugins.jobcacher.CacheWrapper; | ||
|
||
public class JobDslTest { | ||
|
||
public static final String ANSIBLE_DSL_GROOVY_PLAYBOOK = "jobdsl/playbook.groovy"; | ||
|
||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
@Test | ||
@Issue("https://github.com/jenkinsci/jobcacher-plugin/issues/271") | ||
@Ignore | ||
public void shouldCreateFreestyleJob() throws Exception { | ||
runJobDsl("/jobdsl/freestyle.groovy", jenkins); | ||
CacheWrapper step = jenkins.jenkins.getItemByFullName("freestyle", FreeStyleProject.class).getBuildWrappersList().get(CacheWrapper.class); | ||
assertNotNull(step); | ||
assertThat(step.getCaches(), hasSize(2)); | ||
assertThat(step.getSkipSave(), is(true)); | ||
assertThat(step.getSkipRestore(), is(false)); | ||
assertThat(step.getMaxCacheSize(), is(1024L)); | ||
assertThat(step.getDefaultBranch(), is("main")); | ||
} | ||
|
||
private void runJobDsl(String script, JenkinsRule rule) throws Exception { | ||
FreeStyleProject job = rule.createFreeStyleProject(); | ||
String scriptText = IOUtils.toString(JobDslTest.class.getResourceAsStream(script), StandardCharsets.UTF_8); | ||
ExecuteDslScripts builder = new ExecuteDslScripts(); | ||
builder.setScriptText(scriptText); | ||
builder.setRemovedJobAction(RemovedJobAction.DELETE); | ||
builder.setRemovedViewAction(RemovedViewAction.DELETE); | ||
builder.setLookupStrategy(LookupStrategy.JENKINS_ROOT); | ||
job.getBuildersList().add(builder); | ||
rule.buildAndAssertSuccess(job); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../DataMigrationTest/shouldMigrateAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
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,9 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<jenkins.plugins.itemstorage.GlobalItemStorage plugin="jobcacher@999999-SNAPSHOT"> | ||
<storage class="jenkins.plugins.itemstorage.s3.S3ItemStorage"> | ||
<credentialsId>s3</credentialsId> | ||
<bucketName>bucket1</bucketName> | ||
<prefix>the-prefix/</prefix> | ||
<region>us-gov-west-1</region> | ||
</storage> | ||
</jenkins.plugins.itemstorage.GlobalItemStorage> |
6 changes: 6 additions & 0 deletions
6
...ataMigrationTest/shouldMigrateLocalData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
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,6 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<jenkins.plugins.itemstorage.GlobalItemStorage plugin="jobcacher@999999-SNAPSHOT"> | ||
<storage class="jenkins.plugins.itemstorage.local.LocalItemStorage"> | ||
<root>jobcaches</root> | ||
</storage> | ||
</jenkins.plugins.itemstorage.GlobalItemStorage> |
12 changes: 12 additions & 0 deletions
12
...taMigrationTest/shouldMigrateNonAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
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,12 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<jenkins.plugins.itemstorage.GlobalItemStorage plugin="jobcacher@999999-SNAPSHOT"> | ||
<storage class="jenkins.plugins.itemstorage.s3.NonAWSS3ItemStorage"> | ||
<bucketName>bucket1</bucketName> | ||
<prefix>the-prefix/</prefix> | ||
<endpoint>http://localhost:9000</endpoint> | ||
<region>eu-central-2</region> | ||
<pathStyleAccess>true</pathStyleAccess> | ||
<parallelDownloads>true</parallelDownloads> | ||
<credentialsId>s3</credentialsId> | ||
</storage> | ||
</jenkins.plugins.itemstorage.GlobalItemStorage> |
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,8 @@ | ||
unclassified: | ||
globalItemStorage: | ||
storage: | ||
s3: | ||
bucketName: "caches" | ||
prefix: "the-prefix/" | ||
credentialsId: "s3" | ||
region: "eu-central-2" |
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,5 @@ | ||
unclassified: | ||
globalItemStorage: | ||
storage: | ||
local: | ||
root: "jobcaches" |
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,11 @@ | ||
unclassified: | ||
globalItemStorage: | ||
storage: | ||
nonAWSS3: | ||
bucketName: "caches" | ||
prefix: "the-prefix/" | ||
credentialsId: "s3" | ||
endpoint: "http://localhost:9000" | ||
parallelDownloads: false | ||
pathStyleAccess: true | ||
region: "eu-central-2" |
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,25 @@ | ||
freeStyleJob('freestyle') { | ||
wrappers { | ||
jobcacher { | ||
caches { | ||
arbitraryFileCache { | ||
path('node_modules') | ||
includes('**/*') | ||
excludes(null) | ||
} | ||
arbitraryFileCache { | ||
path('.m2/repository') | ||
includes('**/*') | ||
excludes(null) | ||
} | ||
} | ||
skipRestore(false) | ||
skipSave(true) | ||
defaultBranch('main') | ||
maxCacheSize(1024L) | ||
} | ||
} | ||
steps { | ||
shell('ls -lah') | ||
} | ||
} |