2015-04-11 07:56:39 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-04-11 07:56:39 +00:00
|
|
|
|
|
|
|
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 testapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-06-04 17:20:29 +00:00
|
|
|
func TestResourcePathWithPrefix(t *testing.T) {
|
2015-04-11 07:56:39 +00:00
|
|
|
testCases := []struct {
|
|
|
|
prefix string
|
|
|
|
resource string
|
|
|
|
namespace string
|
|
|
|
name string
|
|
|
|
expected string
|
|
|
|
}{
|
2015-09-04 07:06:01 +00:00
|
|
|
{"prefix", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource/myresource"},
|
|
|
|
{"prefix", "resource", "", "myresource", "/api/" + Default.Version() + "/prefix/resource/myresource"},
|
|
|
|
{"prefix", "resource", "mynamespace", "", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource"},
|
|
|
|
{"prefix", "resource", "", "", "/api/" + Default.Version() + "/prefix/resource"},
|
|
|
|
{"", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
|
2015-04-11 07:56:39 +00:00
|
|
|
}
|
|
|
|
for _, item := range testCases {
|
2015-09-04 07:06:01 +00:00
|
|
|
if actual := Default.ResourcePathWithPrefix(item.prefix, item.resource, item.namespace, item.name); actual != item.expected {
|
2015-04-11 07:56:39 +00:00
|
|
|
t.Errorf("Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s", item.expected, actual, item.prefix, item.resource, item.namespace, item.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 17:20:29 +00:00
|
|
|
func TestResourcePath(t *testing.T) {
|
2015-04-11 07:56:39 +00:00
|
|
|
testCases := []struct {
|
|
|
|
resource string
|
|
|
|
namespace string
|
|
|
|
name string
|
|
|
|
expected string
|
|
|
|
}{
|
2015-09-04 07:06:01 +00:00
|
|
|
{"resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
|
|
|
|
{"resource", "", "myresource", "/api/" + Default.Version() + "/resource/myresource"},
|
|
|
|
{"resource", "mynamespace", "", "/api/" + Default.Version() + "/namespaces/mynamespace/resource"},
|
|
|
|
{"resource", "", "", "/api/" + Default.Version() + "/resource"},
|
2015-04-11 07:56:39 +00:00
|
|
|
}
|
|
|
|
for _, item := range testCases {
|
2015-09-04 07:06:01 +00:00
|
|
|
if actual := Default.ResourcePath(item.resource, item.namespace, item.name); actual != item.expected {
|
2015-04-11 07:56:39 +00:00
|
|
|
t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|