-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pod): add pod creation tests to check that env variables are set
- Loading branch information
1 parent
ee50d29
commit 4b46b7e
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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\"]'", | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
internal/controllers/terraformrun/testdata/pod/nominal-case.yaml
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,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 |
15 changes: 15 additions & 0 deletions
15
internal/controllers/terraformrun/testdata/pod/repository-layers.yaml
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,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\"]'"] |