mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
Added namespace test case for POST to /pods
This commit is contained in:
parent
7cf664439f
commit
14dd466e83
@ -65,42 +65,45 @@ func TestReadOnly(t *testing.T) {
|
|||||||
|
|
||||||
func TestKindAndNamespace(t *testing.T) {
|
func TestKindAndNamespace(t *testing.T) {
|
||||||
successCases := []struct {
|
successCases := []struct {
|
||||||
|
method string
|
||||||
url string
|
url string
|
||||||
expectedNamespace string
|
expectedNamespace string
|
||||||
expectedKind string
|
expectedKind string
|
||||||
expectedParts []string
|
expectedParts []string
|
||||||
}{
|
}{
|
||||||
// resource paths
|
// resource paths
|
||||||
{"/ns/other/pods", "other", "pods", []string{"pods"}},
|
{"GET", "/ns/other/pods", "other", "pods", []string{"pods"}},
|
||||||
{"/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
||||||
{"/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
{"GET", "/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
||||||
{"/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"POST", "/pods", api.NamespaceDefault, "pods", []string{"pods"}},
|
||||||
{"/pods/foo?namespace=other", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/pods?namespace=other", "other", "pods", []string{"pods"}},
|
{"GET", "/pods/foo?namespace=other", "other", "pods", []string{"pods", "foo"}},
|
||||||
|
{"GET", "/pods?namespace=other", "other", "pods", []string{"pods"}},
|
||||||
|
|
||||||
// special verbs
|
// special verbs
|
||||||
{"/proxy/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/proxy/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
||||||
{"/proxy/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"GET", "/proxy/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/redirect/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/redirect/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
||||||
{"/redirect/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"GET", "/redirect/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/watch/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
{"GET", "/watch/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
||||||
{"/watch/ns/other/pods", "other", "pods", []string{"pods"}},
|
{"GET", "/watch/ns/other/pods", "other", "pods", []string{"pods"}},
|
||||||
|
|
||||||
// full-qualified paths
|
// fully-qualified paths
|
||||||
{"/api/v1beta1/ns/other/pods", "other", "pods", []string{"pods"}},
|
{"GET", "/api/v1beta1/ns/other/pods", "other", "pods", []string{"pods"}},
|
||||||
{"/api/v1beta1/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/api/v1beta1/ns/other/pods/foo", "other", "pods", []string{"pods", "foo"}},
|
||||||
{"/api/v1beta1/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
{"GET", "/api/v1beta1/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
||||||
{"/api/v1beta1/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"POST", "/api/v1beta1/pods", api.NamespaceDefault, "pods", []string{"pods"}},
|
||||||
{"/api/v1beta1/pods/foo?namespace=other", "other", "pods", []string{"pods", "foo"}},
|
{"GET", "/api/v1beta1/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/api/v1beta1/pods?namespace=other", "other", "pods", []string{"pods"}},
|
{"GET", "/api/v1beta1/pods/foo?namespace=other", "other", "pods", []string{"pods", "foo"}},
|
||||||
{"/api/v1beta1/proxy/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"GET", "/api/v1beta1/pods?namespace=other", "other", "pods", []string{"pods"}},
|
||||||
{"/api/v1beta1/redirect/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
{"GET", "/api/v1beta1/proxy/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/api/v1beta1/watch/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
{"GET", "/api/v1beta1/redirect/pods/foo", api.NamespaceDefault, "pods", []string{"pods", "foo"}},
|
||||||
{"/api/v1beta1/watch/ns/other/pods", "other", "pods", []string{"pods"}},
|
{"GET", "/api/v1beta1/watch/pods", api.NamespaceAll, "pods", []string{"pods"}},
|
||||||
|
{"GET", "/api/v1beta1/watch/ns/other/pods", "other", "pods", []string{"pods"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, successCase := range successCases {
|
for _, successCase := range successCases {
|
||||||
req, _ := http.NewRequest("GET", successCase.url, nil)
|
req, _ := http.NewRequest(successCase.method, successCase.url, nil)
|
||||||
namespace, kind, parts, err := KindAndNamespace(req)
|
namespace, kind, parts, err := KindAndNamespace(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for url: %s", successCase.url)
|
t.Errorf("Unexpected error for url: %s", successCase.url)
|
||||||
|
Loading…
Reference in New Issue
Block a user