From 94864c2de6695148648fe9ec06409924b4dfeb88 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Wed, 19 Aug 2020 16:11:54 +0200 Subject: [PATCH 1/2] Adding small test for util Signed-off-by: Matthias Wessendorf --- pkg/utils/headers_test.go | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 pkg/utils/headers_test.go diff --git a/pkg/utils/headers_test.go b/pkg/utils/headers_test.go new file mode 100644 index 00000000000..2d1abe008a6 --- /dev/null +++ b/pkg/utils/headers_test.go @@ -0,0 +1,57 @@ +/* + * Copyright 2020 The Knative Authors + * + * 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 utils + +import ( + "net/http" + "testing" +) + +func TestPassThroughHeaders(t *testing.T) { + + testCases := map[string]struct { + additionalHeaders http.Header + expectedPassedThroughHeaders int + }{ + "pass through of two values": { + additionalHeaders: map[string][]string{ + "not": {"passed", "through"}, + "nor": {"this-one"}, + "x-requEst-id": {"1234"}, + "knatIve-will-pass-through": {"true", "always"}, + }, + expectedPassedThroughHeaders: 2, + }, + "nothing passes through": { + additionalHeaders: map[string][]string{ + "not": {"passed", "through"}, + "nor": {"this-one"}, + }, + expectedPassedThroughHeaders: 0, + }, + } + for n, tc := range testCases { + t.Run(n, func(t *testing.T) { + + headers := PassThroughHeaders(tc.additionalHeaders) + if len(headers) != tc.expectedPassedThroughHeaders { + t.Errorf("Not matching the expected number of passed through headers") + } + }) + } +} +} From 26f9695a3abe811a894e1a0572f41a0e627dba38 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Wed, 19 Aug 2020 16:38:39 +0200 Subject: [PATCH 2/2] fixing error Signed-off-by: Matthias Wessendorf --- pkg/utils/headers_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/utils/headers_test.go b/pkg/utils/headers_test.go index 2d1abe008a6..ef7355699d6 100644 --- a/pkg/utils/headers_test.go +++ b/pkg/utils/headers_test.go @@ -54,4 +54,3 @@ func TestPassThroughHeaders(t *testing.T) { }) } } -}