2016-11-10 22:56:29 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes 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 controller
|
|
|
|
|
|
|
|
import (
|
2017-02-14 14:02:23 +00:00
|
|
|
"reflect"
|
2017-04-01 14:39:42 +00:00
|
|
|
"testing"
|
2017-02-14 14:02:23 +00:00
|
|
|
|
2017-10-06 20:33:32 +00:00
|
|
|
"k8s.io/ingress-nginx/pkg/ingress"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/auth"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/authreq"
|
2017-10-19 20:03:02 +00:00
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/cors"
|
2017-10-06 20:33:32 +00:00
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/ipwhitelist"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/proxy"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/ratelimit"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/redirect"
|
|
|
|
"k8s.io/ingress-nginx/pkg/ingress/annotations/rewrite"
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
2017-01-24 03:08:46 +00:00
|
|
|
type fakeError struct{}
|
|
|
|
|
|
|
|
func (fe *fakeError) Error() string {
|
|
|
|
return "fakeError"
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMergeLocationAnnotations(t *testing.T) {
|
|
|
|
// initial parameters
|
|
|
|
loc := ingress.Location{}
|
|
|
|
annotations := map[string]interface{}{
|
|
|
|
"Path": "/checkpath",
|
|
|
|
"IsDefBackend": true,
|
|
|
|
"Backend": "foo_backend",
|
|
|
|
"BasicDigestAuth": auth.BasicDigest{},
|
|
|
|
DeniedKeyName: &fakeError{},
|
2017-10-22 22:09:28 +00:00
|
|
|
"CorsConfig": cors.CorsConfig{},
|
2017-01-24 03:08:46 +00:00
|
|
|
"ExternalAuth": authreq.External{},
|
|
|
|
"RateLimit": ratelimit.RateLimit{},
|
2017-08-19 21:13:02 +00:00
|
|
|
"Redirect": redirect.Redirect{},
|
|
|
|
"Rewrite": rewrite.Redirect{},
|
2017-01-24 03:08:46 +00:00
|
|
|
"Whitelist": ipwhitelist.SourceRange{},
|
2017-10-06 03:28:21 +00:00
|
|
|
"Proxy": proxy.Configuration{},
|
2017-01-24 03:08:46 +00:00
|
|
|
"UsePortInRedirects": true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// create test table
|
|
|
|
type fooMergeLocationAnnotationsStruct struct {
|
|
|
|
fName string
|
|
|
|
er interface{}
|
|
|
|
}
|
|
|
|
fooTests := []fooMergeLocationAnnotationsStruct{}
|
|
|
|
for name, value := range annotations {
|
|
|
|
fva := fooMergeLocationAnnotationsStruct{name, value}
|
|
|
|
fooTests = append(fooTests, fva)
|
|
|
|
}
|
|
|
|
|
|
|
|
// execute test
|
|
|
|
mergeLocationAnnotations(&loc, annotations)
|
|
|
|
|
|
|
|
// check result
|
|
|
|
for _, foo := range fooTests {
|
|
|
|
fv := reflect.ValueOf(loc).FieldByName(foo.fName).Interface()
|
|
|
|
if !reflect.DeepEqual(fv, foo.er) {
|
|
|
|
t.Errorf("Returned %v but expected %v for the field %s", fv, foo.er, foo.fName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := annotations[DeniedKeyName]; ok {
|
|
|
|
t.Errorf("%s should be removed after mergeLocationAnnotations", DeniedKeyName)
|
|
|
|
}
|
|
|
|
}
|