Unverified Commit 2da6d6da authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason
Browse files

test: update tests for ingress class changes

parent f98e25ef
Loading
Loading
Loading
Loading
+64 −15
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ SecRule REQUEST_HEADERS:Content-Type \"text/plain\" \"log,deny,id:\'20010\',stat
				ValuesFiles: tc.valueFiles,
				SetValues:   tc.values,
			}
			output := helm.RenderTemplate(t, opts, helmChartPath, "ModSecurity-test-release", templates)
			output := helm.RenderTemplate(t, opts, helmChartPath, "modsecurity-test-release", templates)

			ingress := new(extensions.Ingress)
			helm.UnmarshalK8SYaml(t, output, ingress)
@@ -328,27 +328,76 @@ func TestIngressTemplate_TLSSecret(t *testing.T) {
func TestIngressTemplate_NetworkingV1Beta1(t *testing.T) {
	templates := []string{"templates/ingress.yaml"}
	releaseName := "ingress-networking-v1beta1"
	tcs := []struct {
		name                           string
		values                         map[string]string
		expectedIngressClassAnnotation string
	}{
		{
			name:                           "defaults",
			expectedIngressClassAnnotation: "nginx",
		},
		{
			name: "custom ingress.className",
			values: map[string]string{
				"ingress.className": "custom",
			},
			expectedIngressClassAnnotation: "custom",
		},
	}
	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
		SetValues: map[string]string{"ingress.enabled": "true"},
				SetValues: tc.values,
			}
			output := helm.RenderTemplate(t, opts, helmChartPath, releaseName, templates, "--api-versions", "networking.k8s.io/v1beta1/Ingress")
			ingress := new(networkingv1beta.Ingress)
			helm.UnmarshalK8SYaml(t, output, ingress)
			require.Equal(t, "networking.k8s.io/v1beta1", ingress.APIVersion)
			require.Equal(t, tc.expectedIngressClassAnnotation, ingress.Annotations["kubernetes.io/ingress.class"])
		})
	}
}

func TestIngressTemplate_NetworkingV1(t *testing.T) {
	templates := []string{"templates/ingress.yaml"}
	releaseName := "ingress-networking-v1"
	tcs := []struct {
		name                           string
		values                         map[string]string
		expectedIngressClassName       string
		expectedIngressClassAnnotation string
	}{
		{
			name:                           "defaults",
			expectedIngressClassAnnotation: "nginx",
		},
		{
			name: "custom ingress.className",
			values: map[string]string{
				"ingress.className": "custom",
			},
			expectedIngressClassName:       "custom",
			expectedIngressClassAnnotation: "custom",
		},
	}
	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
		SetValues: map[string]string{"ingress.enabled": "true"},
				SetValues: tc.values,
			}
			output := helm.RenderTemplate(t, opts, helmChartPath, releaseName, templates, "--api-versions", "networking.k8s.io/v1/Ingress")
			ingress := new(networkingv1.Ingress)
			helm.UnmarshalK8SYaml(t, output, ingress)
			require.Equal(t, "networking.k8s.io/v1", ingress.APIVersion)
	require.Equal(t, "nginx", *ingress.Spec.IngressClassName)
	require.NotContains(t, "kubernetes.io/ingress.class", ingress.Annotations)
			if tc.expectedIngressClassName == "" {
				require.Nil(t, ingress.Spec.IngressClassName)
			} else {
				require.Equal(t, tc.expectedIngressClassName, *ingress.Spec.IngressClassName)
			}
			require.Equal(t, tc.expectedIngressClassAnnotation, ingress.Annotations["kubernetes.io/ingress.class"])
		})
	}
}

func TestIngressTemplate_Extensions(t *testing.T) {