func TestK8SServiceVolumeConfigMapAddsVolumeAndVolumeMountToPod(t *testing.T) {
	t.Parallel()
	deployment := renderK8SServiceDeploymentWithSetValues(
		t,
		map[string]string{
			"configMaps.dbsettings.as":        "volume",
			"configMaps.dbsettings.mountPath": "/etc/db",
		},
	)
	renderedPodContainers := deployment.Spec.Template.Spec.Containers
	require.Equal(t, len(renderedPodContainers), 1)
	appContainer := renderedPodContainers[0]
	renderedPodVolumes := deployment.Spec.Template.Spec.Volumes
	require.Equal(t, len(renderedPodVolumes), 1)
	podVolume := renderedPodVolumes[0]
	assert.Equal(t, podVolume.Name, "dbsettings-volume")
	require.NotNil(t, podVolume.ConfigMap)
	assert.Equal(t, podVolume.ConfigMap.Name, "dbsettings")
	require.Equal(t, len(appContainer.VolumeMounts), 1)
	volumeMount := appContainer.VolumeMounts[0]
	assert.Equal(t, volumeMount.Name, "dbsettings-volume")
	assert.Equal(t, volumeMount.MountPath, "/etc/db")
}
Test that setting the `configMaps` input value with volume include the volume mount for the config map
We test by injecting to configMaps:
configMaps:
dbsettings:
as: volume
mountPath: /etc/db
package test
import (
	"fmt"
	"path/filepath"
	"strings"
	"testing"
	"github.com/gruntwork-io/terratest/modules/helm"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	corev1 "k8s.io/api/core/v1"
)
func TestK8SServiceEnvVarConfigMapsSecretsEmptyDoesNotAddEnvVarsAndVolumesToPod(t *testing.T) {
	t.Parallel()
	deployment := renderK8SServiceDeploymentWithSetValues(t, map[string]string{})
	renderedPodContainers := deployment.Spec.Template.Spec.Containers
	require.Equal(t, len(renderedPodContainers), 1)
	appContainer := renderedPodContainers[0]
	environments := appContainer.Env
	assert.Equal(t, len(environments), 0)
	renderedPodVolumes := deployment.Spec.Template.Spec.Volumes
	assert.Equal(t, len(renderedPodVolumes), 0)
}
func TestK8SServiceEnvVarAddsEnvVarsToPod(t *testing.T) {
	t.Parallel()
	deployment := renderK8SServiceDeploymentWithSetValues(
		t,
		map[string]string{
			"envVars.DB_HOST": "mysql.default.svc.cluster.local",
			"envVars.DB_PORT": "3306",
		},
	)
	renderedPodContainers := deployment.Spec.Template.Spec.Containers
	require.Equal(t, len(renderedPodContainers), 1)
	appContainer := renderedPodContainers[0]
	environments := appContainer.Env
	assert.Equal(t, len(environments), 2)
	renderedEnvVar := map[string]string{}
	for _, env := range environments {
		renderedEnvVar[env.Name] = env.Value
	}
	assert.Equal(t, renderedEnvVar["DB_HOST"], "mysql.default.svc.cluster.local")
	assert.Equal(t, renderedEnvVar["DB_PORT"], "3306")
}
func TestK8SServiceAdditionalEnvVarAddsEnvVarsToPod(t *testing.T) {
	t.Parallel()
	deployment := renderK8SServiceDeploymentWithSetValues(
		t,
		map[string]string{
			"additionalContainerEnv[0].name":                         "DD_AGENT_HOST",
			"additionalContainerEnv[0].valueFrom.fieldRef.fieldPath": "status.hostIP",
			"additionalContainerEnv[1].name":                         "DD_ENTITY_ID",
			"additionalContainerEnv[1].valueFrom.fieldRef.fieldPath": "metadata.uid",
		},
	)
	renderedPodContainers := deployment.Spec.Template.Spec.Containers
	require.Equal(t, len(renderedPodContainers), 1)
	appContainer := renderedPodContainers[0]
	environments := appContainer.Env
	assert.Equal(t, len(environments), 2)
	renderedEnvVar := map[string]string{}
	for _, env := range environments {
		renderedEnvVar[env.Name] = env.ValueFrom.FieldRef.FieldPath
	}
	assert.Equal(t, renderedEnvVar["DD_AGENT_HOST"], "status.hostIP")
	assert.Equal(t, renderedEnvVar["DD_ENTITY_ID"], "metadata.uid")
}
func TestK8SServiceEnvironmentConfigMapAddsEnvVarsToPod(t *testing.T) {
	t.Parallel()
	deployment := renderK8SServiceDeploymentWithSetValues(
		t,
		map[string]string{
			"configMaps.dbsettings.as":                    "environment",
			"configMaps.dbsettings.items.host.envVarName": "DB_HOST",
			"configMaps.dbsettings.items.port.envVarName": "DB_PORT",
		},
	)
	renderedPodContainers := deployment.Spec.Template.Spec.Containers
	require.Equal(t, len(renderedPodContainers), 1)
	appContainer := renderedPodContainers[0]
	environments := appContainer.Env
	assert.Equal(t, len(environments), 2)
	renderedEnvVar := map[string]corev1.EnvVar{}
	for _, env := range environments {
		renderedEnvVar[env.Name] = env
	}
	assert.Equal(t, renderedEnvVar["DB_HOST"].Value, "")
	require.NotNil(t, renderedEnvVar["DB_HOST"].ValueFrom)
	require.NotNil(t, renderedEnvVar["DB_HOST"].ValueFrom.ConfigMapKeyRef)
	assert.Equal(t, renderedEnvVar["DB_HOST"].ValueFrom.ConfigMapKeyRef.Key, "host")
	assert.Equal(t, renderedEnvVar["DB_HOST"].ValueFrom.ConfigMapKeyRef.Name, "dbsettings")
	assert.Equal(t, renderedEnvVar["DB_PORT"].Value, "")
	require.NotNil(t, renderedEnvVar["DB_PORT"].ValueFrom)
	require.NotNil(t, renderedEnvVar["DB_PORT"].ValueFrom.ConfigMapKeyRef)
	assert.Equal(t, renderedEnvVar["DB_PORT"].ValueFrom.ConfigMapKeyRef.Key, "port")
	assert.Equal(t, renderedEnvVar["DB_PORT"].ValueFrom.ConfigMapKeyRef.Name, "dbsettings")
}