diff --git a/test/e2e/common.go b/test/e2e/common.go index d70d67cf8..38cf46043 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -23,6 +23,12 @@ func withCommand(command []string) podOption { } } +func withEnvironmentalVariables(envVar []corev1.EnvVar) podOption { + return func(p *corev1.Pod) { + p.Spec.Containers[0].Env = envVar + } +} + func withConfigMapBinding(mountPath string, configMapName string) podOption { return func(p *corev1.Pod) { p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{Name: "config-volume", MountPath: mountPath}) diff --git a/test/e2e/common_suite_test.go b/test/e2e/common_suite_test.go index 3f889267c..1357cec94 100644 --- a/test/e2e/common_suite_test.go +++ b/test/e2e/common_suite_test.go @@ -163,6 +163,7 @@ func (tc *testCase) run() { if tc.expectedPodLogString != "" { LogString, err := comparePodLogString(ctx, client, *tc.pod, tc.expectedPodLogString) if err != nil { + t.Logf("Output:%s", LogString) t.Fatal(err) } t.Logf("Log output of peer pod:%s", LogString) @@ -291,8 +292,8 @@ func comparePodLogString(ctx context.Context, client klient.Client, customPod v1 return podLogString, err } - if podLogString != expectedPodlogString { - return podLogString, errors.New("Error: Pod Log doesn't match with Expected String") + if !strings.Contains(podLogString, expectedPodlogString) { + return podLogString, errors.New("Error: Pod Log doesn't contain Expected String") } return podLogString, nil @@ -493,3 +494,30 @@ func doTestCreatePeerPodAndCheckWorkDirLogs(t *testing.T, assert CloudAssert) { expectedPodLogString := "/other" newTestCase(t, "WorkDirPeerPod", assert, "Peer pod with work directory has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run() } + +func doTestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t *testing.T, assert CloudAssert) { + namespace := envconf.RandomName("default", 7) + podName := "env-variable-in-image" + imageName := "quay.io/confidential-containers/test-images:testenv" + pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever)) + expectedPodLogString := "ISPRODUCTION=false" + newTestCase(t, "EnvVariablePeerPodWithImageOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run() +} + +func doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T, assert CloudAssert) { + namespace := envconf.RandomName("default", 7) + podName := "env-variable-in-config" + imageName := "nginx:latest" + pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}}), withCommand([]string{"/bin/sh", "-c", "env"})) + expectedPodLogString := "ISPRODUCTION=true" + newTestCase(t, "EnvVariablePeerPodWithDeploymentOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).run() +} + +func doTestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t *testing.T, assert CloudAssert) { + namespace := envconf.RandomName("default", 7) + podName := "env-variable-in-both" + imageName := "quay.io/confidential-containers/test-images:testenv" + pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}})) + expectedPodLogString := "ISPRODUCTION=true" + newTestCase(t, "EnvVariablePeerPodWithBoth", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run() +} diff --git a/test/e2e/fixtures/Dockerfile.testenv b/test/e2e/fixtures/Dockerfile.testenv new file mode 100644 index 000000000..a909d103a --- /dev/null +++ b/test/e2e/fixtures/Dockerfile.testenv @@ -0,0 +1,3 @@ +FROM --platform="${TARGETPLATFORM}" alpine:latest +ENV ISPRODUCTION=false +ENTRYPOINT [ "/bin/sh", "-c", "env" ] diff --git a/test/e2e/ibmcloud_test.go b/test/e2e/ibmcloud_test.go index c9f7090e8..4b8fd2e79 100644 --- a/test/e2e/ibmcloud_test.go +++ b/test/e2e/ibmcloud_test.go @@ -106,6 +106,27 @@ func TestCreatePeerPodAndCheckWorkDirLogs(t *testing.T) { doTestCreatePeerPodAndCheckWorkDirLogs(t, assert) } +func TestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t *testing.T) { + assert := IBMCloudAssert{ + vpc: pv.IBMCloudProps.VPC, + } + doTestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t, assert) +} + +func TestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T) { + assert := IBMCloudAssert{ + vpc: pv.IBMCloudProps.VPC, + } + doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t, assert) +} + +func TestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t *testing.T) { + assert := IBMCloudAssert{ + vpc: pv.IBMCloudProps.VPC, + } + doTestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t, assert) +} + // IBMCloudAssert implements the CloudAssert interface for ibmcloud. type IBMCloudAssert struct { vpc *vpcv1.VpcV1