From c3351199487be38586c98da417db0255744d7933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AA=E0=AE=BE=E0=AE=B2=E0=AE=BE=E0=AE=9C=E0=AE=BF?= Date: Sun, 14 Jan 2018 00:01:47 +0530 Subject: [PATCH] test case added for ssl redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: பாலாஜி --- internal/contour/virtualhost_test.go | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 internal/contour/virtualhost_test.go diff --git a/internal/contour/virtualhost_test.go b/internal/contour/virtualhost_test.go new file mode 100644 index 00000000000..fdea7f1351a --- /dev/null +++ b/internal/contour/virtualhost_test.go @@ -0,0 +1,57 @@ +// Copyright © 2018 Heptio +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package contour + +import ( + "testing" + + "k8s.io/api/extensions/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestSslRedirect(t *testing.T) { + tests := map[string]struct { + i *v1beta1.Ingress + valid bool + }{ + "redirect to https": { + i: &v1beta1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + "kubenetes.io/ingress.ssl-redirect": "true", + }, + }, + }, + valid: true, + }, + "don't redirect to https": { + i: &v1beta1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + "kubenetes.io/ingress.ssl-redirect": "false", + }, + }, + }, + valid: false, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + got := sslRedirect(tc.i) + want := tc.valid + if got != want { + t.Fatalf("sslRedirect: got: %v, want: %v", got, want) + } + }) + } +}