Skip to content

Commit

Permalink
test (gradle-plugin/it): Add Gradle integration test for CronJob
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
anurag-rajawat committed Apr 1, 2023
1 parent f15c9c0 commit 6df8db0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
41 changes: 41 additions & 0 deletions gradle-plugin/it/src/it/controller/expected/cronjob/kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: v1
kind: List
items:
- apiVersion: batch/v1
kind: CronJob
metadata:
labels:
app: controller
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: controller
spec:
jobTemplate:
spec:
template:
metadata:
labels:
app: controller
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
spec:
containers:
- name: repository-controller
image: repository/controller:latest
imagePullPolicy: IfNotPresent
securityContext:
privileged: false
env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: metadata.name
restartPolicy: OnFailure
schedule: '*/2 * * * *'
37 changes: 37 additions & 0 deletions gradle-plugin/it/src/it/controller/expected/cronjob/openshift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: List
items:
- apiVersion: batch/v1
kind: CronJob
metadata:
labels:
app: controller
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: controller
spec:
jobTemplate:
spec:
template:
metadata:
labels:
app: controller
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
spec:
containers:
- name: repository-controller
image: repository/controller:latest
imagePullPolicy: IfNotPresent
securityContext:
privileged: false
env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
restartPolicy: OnFailure
schedule: '*/2 * * * *'
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -45,4 +46,23 @@ void k8sResourceTask_whenRunWithConfiguredControllerType_generatesK8sManifestWit
.contains("Adding revision history limit to 2")
.contains("validating");
}

@Test
void k8sResourceTask_whenRunWithCronJobController_generatesK8sManifestWithCronJobController() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("controller")
.withArguments("-Pjkube.enricher.jkube-controller.type=CronJob",
"-Pjkube.enricher.jkube-controller.schedule=*/2 * * * *", "k8sResource")
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(),
gradleRunner.resolveFile("expected", "cronjob", "kubernetes.yml"));
assertThat(result).extracting(BuildResult::getOutput).asString()
.contains(
"Using resource templates from",
"Adding a default CronJob",
"Adding revision history limit to 2",
"validating"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -45,4 +46,23 @@ void ocResourceTask_whenRunWithConfiguredControllerType_generatesOpenShiftManife
.contains("Adding revision history limit to 2")
.contains("validating");
}

@Test
void ocResourceTask_whenRunWithCronJobController_generatesOpenShiftManifestWithCronJobController() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("controller")
.withArguments("-Pjkube.enricher.jkube-controller.type=CronJob",
"-Pjkube.enricher.jkube-controller.schedule=*/2 * * * *", "ocResource", "--stacktrace")
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(),
gradleRunner.resolveFile("expected", "cronjob", "openshift.yml"));
assertThat(result).extracting(BuildResult::getOutput).asString()
.contains(
"Using resource templates from",
"Adding a default CronJob",
"Adding revision history limit to 2",
"validating"
);
}
}

0 comments on commit 6df8db0

Please sign in to comment.