Skip to content

Commit

Permalink
add new test - TestAccKubernetesCronJobV1_minimalWithBackoffLimitPerI…
Browse files Browse the repository at this point in the history
…ndex
  • Loading branch information
BBBmau committed Sep 21, 2024
1 parent 248c69d commit 80a683e
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions kubernetes/resource_kubernetes_cron_job_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,59 @@ func TestAccKubernetesCronJobV1_minimalWithPodFailurePolicy(t *testing.T) {
},
{
Config: testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesCronJobV1Exists(resourceName, &conf2),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.#", "2"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.action", "FailJob"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.container_name", "test"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.#", "3"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.0", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.1", "2"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.2", "42"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.action", "Ignore"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.on_pod_condition.0.type", "DisruptionTarget"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.on_pod_condition.0.status", "False"),
testAccCheckKubernetesCronJobV1ForceNew(&conf1, &conf2, true),
),
},
},
})
}

func TestAccKubernetesCronJobV1_minimalWithBackoffLimitPerIndex(t *testing.T) {
var conf1, conf2 batchv1.CronJob

name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
resourceName := "kubernetes_cron_job_v1.test"
imageName := busyboxImage

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
skipIfClusterVersionLessThan(t, "1.29.0")
},
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckKubernetesCronJobV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesCronJobV1ConfigMinimal(name, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesCronJobV1Exists(resourceName, &conf1),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.metadata.0.namespace", ""),
),
},
{
Config: testAccKubernetesCronJobV1ConfigMinimalWithBackoffLimitPerIndex(name, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesCronJobV1Exists(resourceName, &conf2),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"),
Expand Down Expand Up @@ -463,6 +516,56 @@ func testAccKubernetesCronJobV1ConfigMinimal(name, imageName string) string {
`, name, imageName)
}

func testAccKubernetesCronJobV1ConfigMinimalWithBackoffLimitPerIndex(name, imageName string) string {
return fmt.Sprintf(`resource "kubernetes_cron_job_v1" "test" {
metadata {
name = "%s"
}
spec {
schedule = "*/1 * * * *"
job_template {
metadata {}
spec {
backoff_limit_per_index = 3
max_failed_indexes = 4
completions = 4
completion_mode = "Indexed"
pod_failure_policy {
rule {
action = "FailJob"
on_exit_codes {
container_name = "test"
operator = "In"
values = [1, 2, 42]
}
}
rule {
action = "Ignore"
on_pod_condition {
status = "False"
type = "DisruptionTarget"
}
}
}
template {
metadata {}
spec {
container {
name = "test"
image = "%s"
command = ["sleep", "5"]
}
termination_grace_period_seconds = 1
}
}
}
}
}
}
`, name, imageName)
}

func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName string) string {
return fmt.Sprintf(`resource "kubernetes_cron_job_v1" "test" {
metadata {
Expand Down

0 comments on commit 80a683e

Please sign in to comment.