2015-06-16 17:50:40 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
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 app
|
|
|
|
|
|
|
|
import (
|
2015-09-21 22:57:05 +00:00
|
|
|
"reflect"
|
2015-06-16 17:50:40 +00:00
|
|
|
"regexp"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLongRunningRequestRegexp(t *testing.T) {
|
|
|
|
regexp := regexp.MustCompile(defaultLongRunningRequestRE)
|
|
|
|
dontMatch := []string{
|
|
|
|
"/api/v1/watch-namespace/",
|
|
|
|
"/api/v1/namespace-proxy/",
|
|
|
|
"/api/v1/namespace-watch",
|
|
|
|
"/api/v1/namespace-proxy",
|
|
|
|
"/api/v1/namespace-portforward/pods",
|
|
|
|
"/api/v1/portforward/pods",
|
|
|
|
". anything",
|
|
|
|
"/ that",
|
|
|
|
}
|
|
|
|
doMatch := []string{
|
|
|
|
"/api/v1/pods/watch",
|
|
|
|
"/api/v1/watch/stuff",
|
|
|
|
"/api/v1/default/service/proxy",
|
|
|
|
"/api/v1/pods/proxy/path/to/thing",
|
2015-09-09 03:58:36 +00:00
|
|
|
"/api/v1/namespaces/myns/pods/mypod/log",
|
2015-06-16 17:50:40 +00:00
|
|
|
"/api/v1/namespaces/myns/pods/mypod/logs",
|
|
|
|
"/api/v1/namespaces/myns/pods/mypod/portforward",
|
|
|
|
"/api/v1/namespaces/myns/pods/mypod/exec",
|
2015-09-09 03:58:36 +00:00
|
|
|
"/api/v1/namespaces/myns/pods/mypod/attach",
|
|
|
|
"/api/v1/namespaces/myns/pods/mypod/log/",
|
2015-06-16 17:50:40 +00:00
|
|
|
"/api/v1/namespaces/myns/pods/mypod/logs/",
|
|
|
|
"/api/v1/namespaces/myns/pods/mypod/portforward/",
|
|
|
|
"/api/v1/namespaces/myns/pods/mypod/exec/",
|
2015-09-09 03:58:36 +00:00
|
|
|
"/api/v1/namespaces/myns/pods/mypod/attach/",
|
2015-06-16 17:50:40 +00:00
|
|
|
"/api/v1/watch/namespaces/myns/pods",
|
|
|
|
}
|
|
|
|
for _, path := range dontMatch {
|
|
|
|
if regexp.MatchString(path) {
|
|
|
|
t.Errorf("path should not have match regexp but did: %s", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, path := range doMatch {
|
|
|
|
if !regexp.MatchString(path) {
|
|
|
|
t.Errorf("path should have match regexp did not: %s", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-21 22:57:05 +00:00
|
|
|
|
|
|
|
func TestGenerateStorageVersionMap(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
legacyVersion string
|
|
|
|
storageVersions string
|
|
|
|
expectedMap map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
legacyVersion: "v1",
|
|
|
|
storageVersions: "v1,experimental/v1alpha1",
|
|
|
|
expectedMap: map[string]string{
|
|
|
|
"": "v1",
|
|
|
|
"experimental": "experimental/v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
legacyVersion: "",
|
|
|
|
storageVersions: "experimental/v1alpha1,v1",
|
|
|
|
expectedMap: map[string]string{
|
|
|
|
"": "v1",
|
|
|
|
"experimental": "experimental/v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
legacyVersion: "",
|
|
|
|
storageVersions: "",
|
|
|
|
expectedMap: map[string]string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
output := generateStorageVersionMap(test.legacyVersion, test.storageVersions)
|
|
|
|
if !reflect.DeepEqual(test.expectedMap, output) {
|
|
|
|
t.Errorf("unexpected error. expect: %v, got: %v", test.expectedMap, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|