Skip to content

Commit

Permalink
feat(pod): add pod creation tests to check that env variables are set
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMrqes committed Nov 29, 2024
1 parent ee50d29 commit 4b46b7e
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions internal/controllers/terraformrun/pod_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package terraformrun_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

var _ = Describe("Pod", func() {
var run *configv1alpha1.TerraformRun
var reconcileError error
var err error
var name types.NamespacedName
Describe("Nominal Case", func() {
Describe("When a TerraformRun is created with overridden plan args", Ordered, func() {
BeforeAll(func() {
name = types.NamespacedName{
Name: "nominal-case-plan",
Namespace: "default",
}
_, run, reconcileError, err = getResult(name)
})
It("should still exists", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should not return an error", func() {
Expect(reconcileError).NotTo(HaveOccurred())
})
It("should have an associated pod", func() {
Expect(run.Status.RunnerPod).To(Not(BeEmpty()))
})
It("should have created a pod", func() {
pods, err := reconciler.GetLinkedPods(run)
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Items)).To(Equal(1))
})
It("should have passed the TF_CLI_ARGS_plan env var to the pod", func() {
pods, err := reconciler.GetLinkedPods(run)
Expect(err).NotTo(HaveOccurred())
Expect(pods.Items[0].Spec.Containers[0].Env).To(ContainElement(corev1.EnvVar{
Name: "TF_CLI_ARGS_plan",
Value: "--target 'module.this.random_pet.this[\"first\"]'",
}))
})
})
Describe("When a TerraformRun is created with overridden apply args", Ordered, func() {
BeforeAll(func() {
name = types.NamespacedName{
Name: "nominal-case-apply",
Namespace: "default",
}
_, run, reconcileError, err = getResult(name)
})
It("should still exists", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should not return an error", func() {
Expect(reconcileError).NotTo(HaveOccurred())
})
It("should have an associated pod", func() {
Expect(run.Status.RunnerPod).To(Not(BeEmpty()))
})
It("should have created a pod", func() {
pods, err := reconciler.GetLinkedPods(run)
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Items)).To(Equal(1))
})
It("should have passed the TF_CLI_ARGS_apply env var to the pod", func() {
pods, err := reconciler.GetLinkedPods(run)
Expect(err).NotTo(HaveOccurred())
Expect(pods.Items[0].Spec.Containers[0].Env).To(ContainElement(corev1.EnvVar{
Name: "TF_CLI_ARGS_plan",
Value: "--target 'module.this.random_pet.this[\"first\"]'",
}))
})
})
})
})
21 changes: 21 additions & 0 deletions internal/controllers/terraformrun/testdata/pod/nominal-case.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: config.terraform.padok.cloud/v1alpha1
kind: TerraformRun
metadata:
name: nominal-case-plan
namespace: default
spec:
action: plan
layer:
name: pod-nominal-case-extra-args
namespace: default
---
apiVersion: config.terraform.padok.cloud/v1alpha1
kind: TerraformRun
metadata:
name: nominal-case-apply
namespace: default
spec:
action: apply
layer:
name: pod-nominal-case-extra-args
namespace: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

apiVersion: config.terraform.padok.cloud/v1alpha1
kind: TerraformLayer
metadata:
name: pod-nominal-case-extra-args
namespace: default
spec:
branch: main
path: terraform/
repository:
name: burrito
namespace: default
overrideRunnerSpec:
extraPlanArgs: ["--target", "'module.this.random_pet.this[\"first\"]'"]
extraApplyArgs: ["--target", "'module.this.random_pet.this[\"first\"]'"]

0 comments on commit 4b46b7e

Please sign in to comment.