address nikhiljindal's comments in #9225
This commit is contained in:
@@ -20,12 +20,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResourcePathWithPrefixForV1Beta3(t *testing.T) {
|
||||
if Version() != "v1beta3" {
|
||||
// Skip the test if we are not testing v1beta3.
|
||||
return
|
||||
}
|
||||
|
||||
func TestResourcePathWithPrefix(t *testing.T) {
|
||||
testCases := []struct {
|
||||
prefix string
|
||||
resource string
|
||||
@@ -33,11 +28,11 @@ func TestResourcePathWithPrefixForV1Beta3(t *testing.T) {
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"prefix", "resource", "mynamespace", "myresource", "/api/v1beta3/prefix/namespaces/mynamespace/resource/myresource"},
|
||||
{"prefix", "resource", "", "myresource", "/api/v1beta3/prefix/resource/myresource"},
|
||||
{"prefix", "resource", "mynamespace", "", "/api/v1beta3/prefix/namespaces/mynamespace/resource"},
|
||||
{"prefix", "resource", "", "", "/api/v1beta3/prefix/resource"},
|
||||
{"", "resource", "mynamespace", "myresource", "/api/v1beta3/namespaces/mynamespace/resource/myresource"},
|
||||
{"prefix", "resource", "mynamespace", "myresource", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource/myresource"},
|
||||
{"prefix", "resource", "", "myresource", "/api/" + Version() + "/prefix/resource/myresource"},
|
||||
{"prefix", "resource", "mynamespace", "", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource"},
|
||||
{"prefix", "resource", "", "", "/api/" + Version() + "/prefix/resource"},
|
||||
{"", "resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePathWithPrefix(item.prefix, item.resource, item.namespace, item.name); actual != item.expected {
|
||||
@@ -46,48 +41,17 @@ func TestResourcePathWithPrefixForV1Beta3(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourcePathWithPrefixForV1(t *testing.T) {
|
||||
if Version() != "v1" {
|
||||
// Skip the test if we are not testing v1.
|
||||
return
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
prefix string
|
||||
resource string
|
||||
namespace string
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"prefix", "resource", "mynamespace", "myresource", "/api/v1/prefix/namespaces/mynamespace/resource/myresource"},
|
||||
{"prefix", "resource", "", "myresource", "/api/v1/prefix/resource/myresource"},
|
||||
{"prefix", "resource", "mynamespace", "", "/api/v1/prefix/namespaces/mynamespace/resource"},
|
||||
{"prefix", "resource", "", "", "/api/v1/prefix/resource"},
|
||||
{"", "resource", "mynamespace", "myresource", "/api/v1/namespaces/mynamespace/resource/myresource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePathWithPrefix(item.prefix, item.resource, item.namespace, item.name); actual != item.expected {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourcePathForV1Beta3(t *testing.T) {
|
||||
if Version() != "v1beta3" {
|
||||
// Skip the test if we are not testing v1beta3.
|
||||
return
|
||||
}
|
||||
|
||||
func TestResourcePath(t *testing.T) {
|
||||
testCases := []struct {
|
||||
resource string
|
||||
namespace string
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"resource", "mynamespace", "myresource", "/api/v1beta3/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/v1beta3/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/v1beta3/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/v1beta3/resource"},
|
||||
{"resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/" + Version() + "/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/" + Version() + "/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/" + Version() + "/resource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePath(item.resource, item.namespace, item.name); actual != item.expected {
|
||||
@@ -96,70 +60,17 @@ func TestResourcePathForV1Beta3(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourcePathForV1(t *testing.T) {
|
||||
if Version() != "v1" {
|
||||
// Skip the test if we are not testing v1.
|
||||
return
|
||||
}
|
||||
|
||||
func TestResourcePathWithNamespaceQuery(t *testing.T) {
|
||||
testCases := []struct {
|
||||
resource string
|
||||
namespace string
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"resource", "mynamespace", "myresource", "/api/v1/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/v1/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/v1/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/v1/resource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePath(item.resource, item.namespace, item.name); actual != item.expected {
|
||||
t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourcePathWithNamespaceQueryForV1Beta3(t *testing.T) {
|
||||
if Version() != "v1beta3" {
|
||||
// Skip the test if we are not testing v1beta3.
|
||||
return
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
resource string
|
||||
namespace string
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"resource", "mynamespace", "myresource", "/api/v1beta3/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/v1beta3/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/v1beta3/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/v1beta3/resource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePathWithNamespaceQuery(item.resource, item.namespace, item.name); actual != item.expected {
|
||||
t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourcePathWithNamespaceQueryForV1(t *testing.T) {
|
||||
if Version() != "v1" {
|
||||
// Skip the test if we are not testing v1.
|
||||
return
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
resource string
|
||||
namespace string
|
||||
name string
|
||||
expected string
|
||||
}{
|
||||
{"resource", "mynamespace", "myresource", "/api/v1/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/v1/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/v1/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/v1/resource"},
|
||||
{"resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"},
|
||||
{"resource", "", "myresource", "/api/" + Version() + "/resource/myresource"},
|
||||
{"resource", "mynamespace", "", "/api/" + Version() + "/namespaces/mynamespace/resource"},
|
||||
{"resource", "", "", "/api/" + Version() + "/resource"},
|
||||
}
|
||||
for _, item := range testCases {
|
||||
if actual := ResourcePathWithNamespaceQuery(item.resource, item.namespace, item.name); actual != item.expected {
|
||||
|
@@ -21,7 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
@@ -137,8 +137,7 @@ func TestDecodeList(t *testing.T) {
|
||||
pl := &api.List{
|
||||
Items: []runtime.Object{
|
||||
&api.Pod{ObjectMeta: api.ObjectMeta{Name: "1"}},
|
||||
&runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1beta3"}, RawJSON: []byte(`{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"test"}}`)},
|
||||
&runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: "v1"}, RawJSON: []byte(`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"test"}}`)},
|
||||
&runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: testapi.Version()}, RawJSON: []byte(`{"kind":"Pod","apiVersion":"` + testapi.Version() + `","metadata":{"name":"test"}}`)},
|
||||
&runtime.Unstructured{TypeMeta: runtime.TypeMeta{Kind: "Foo", APIVersion: "Bar"}, Object: map[string]interface{}{"test": "value"}},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user