mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
remove references to v1beta1/2 in listwatch_test.go
This commit is contained in:
parent
43889c612c
commit
1be9789795
60
pkg/client/cache/listwatch_test.go
vendored
60
pkg/client/cache/listwatch_test.go
vendored
@ -19,7 +19,6 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
@ -37,28 +36,8 @@ func parseSelectorOrDie(s string) fields.Selector {
|
|||||||
return selector
|
return selector
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildResourcePath is a convenience function for knowing if a namespace should be in a path param or not
|
|
||||||
func buildResourcePath(prefix, namespace, resource string) string {
|
|
||||||
base := path.Join("/api", testapi.Version(), prefix)
|
|
||||||
if len(namespace) > 0 {
|
|
||||||
if !(testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2") {
|
|
||||||
base = path.Join(base, "namespaces", namespace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return path.Join(base, resource)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getHostFieldLabel() string {
|
|
||||||
switch testapi.Version() {
|
|
||||||
case "v1beta1", "v1beta2":
|
|
||||||
return "DesiredState.Host"
|
|
||||||
default:
|
|
||||||
return "spec.host"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildQueryValues is a convenience function for knowing if a namespace should be in a query param or not
|
// buildQueryValues is a convenience function for knowing if a namespace should be in a query param or not
|
||||||
func buildQueryValues(namespace string, query url.Values) url.Values {
|
func buildQueryValues(query url.Values) url.Values {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
if query != nil {
|
if query != nil {
|
||||||
for key, values := range query {
|
for key, values := range query {
|
||||||
@ -67,9 +46,6 @@ func buildQueryValues(namespace string, query url.Values) url.Values {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2" {
|
|
||||||
v.Set("namespace", namespace)
|
|
||||||
}
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +63,7 @@ func TestListWatchesCanList(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
// Minion
|
// Minion
|
||||||
{
|
{
|
||||||
location: buildLocation(buildResourcePath("", api.NamespaceAll, "minions"), buildQueryValues(api.NamespaceAll, nil)),
|
location: testapi.ResourcePath("minions", api.NamespaceAll, ""),
|
||||||
resource: "minions",
|
resource: "minions",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
fieldSelector: parseSelectorOrDie(""),
|
fieldSelector: parseSelectorOrDie(""),
|
||||||
@ -95,20 +71,20 @@ func TestListWatchesCanList(t *testing.T) {
|
|||||||
// pod with "assigned" field selector.
|
// pod with "assigned" field selector.
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("", api.NamespaceAll, "pods"),
|
testapi.ResourcePath("pods", api.NamespaceAll, ""),
|
||||||
buildQueryValues(api.NamespaceAll, url.Values{fieldSelectorQueryParamName: []string{getHostFieldLabel() + "="}})),
|
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
|
||||||
},
|
},
|
||||||
// pod in namespace "foo"
|
// pod in namespace "foo"
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("", "foo", "pods"),
|
testapi.ResourcePath("pods", "foo", ""),
|
||||||
buildQueryValues("foo", url.Values{fieldSelectorQueryParamName: []string{getHostFieldLabel() + "="}})),
|
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
namespace: "foo",
|
namespace: "foo",
|
||||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
@ -139,8 +115,8 @@ func TestListWatchesCanWatch(t *testing.T) {
|
|||||||
// Minion
|
// Minion
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("watch", api.NamespaceAll, "minions"),
|
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
|
||||||
buildQueryValues(api.NamespaceAll, url.Values{"resourceVersion": []string{""}})),
|
buildQueryValues(url.Values{"resourceVersion": []string{""}})),
|
||||||
rv: "",
|
rv: "",
|
||||||
resource: "minions",
|
resource: "minions",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
@ -148,8 +124,8 @@ func TestListWatchesCanWatch(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("watch", api.NamespaceAll, "minions"),
|
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
|
||||||
buildQueryValues(api.NamespaceAll, url.Values{"resourceVersion": []string{"42"}})),
|
buildQueryValues(url.Values{"resourceVersion": []string{"42"}})),
|
||||||
rv: "42",
|
rv: "42",
|
||||||
resource: "minions",
|
resource: "minions",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
@ -158,22 +134,22 @@ func TestListWatchesCanWatch(t *testing.T) {
|
|||||||
// pod with "assigned" field selector.
|
// pod with "assigned" field selector.
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("watch", api.NamespaceAll, "pods"),
|
testapi.ResourcePathWithPrefix("watch", "pods", api.NamespaceAll, ""),
|
||||||
buildQueryValues(api.NamespaceAll, url.Values{fieldSelectorQueryParamName: []string{getHostFieldLabel() + "="}, "resourceVersion": []string{"0"}})),
|
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})),
|
||||||
rv: "0",
|
rv: "0",
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
|
||||||
},
|
},
|
||||||
// pod with namespace foo and assigned field selector
|
// pod with namespace foo and assigned field selector
|
||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
buildResourcePath("watch", "foo", "pods"),
|
testapi.ResourcePathWithPrefix("watch", "pods", "foo", ""),
|
||||||
buildQueryValues("foo", url.Values{fieldSelectorQueryParamName: []string{getHostFieldLabel() + "="}, "resourceVersion": []string{"0"}})),
|
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})),
|
||||||
rv: "0",
|
rv: "0",
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
namespace: "foo",
|
namespace: "foo",
|
||||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
fieldSelector: fields.Set{"spec.host": ""}.AsSelector(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user