mirror of https://github.com/k3s-io/k3s
Merge pull request #9217 from caesarxuchao/add-v1-tests-to-pkg/kubectl/cmd
add v1 tests to kubectl/cmd/*pull/6/head
commit
c92b4255b3
|
@ -118,7 +118,6 @@ func TestPodAndContainer(t *testing.T) {
|
||||||
func TestExec(t *testing.T) {
|
func TestExec(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name, version, podPath, execPath, container string
|
name, version, podPath, execPath, container string
|
||||||
nsInQuery bool
|
|
||||||
pod *api.Pod
|
pod *api.Pod
|
||||||
execErr bool
|
execErr bool
|
||||||
}{
|
}{
|
||||||
|
@ -127,7 +126,6 @@ func TestExec(t *testing.T) {
|
||||||
version: "v1beta3",
|
version: "v1beta3",
|
||||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||||
execPath: "/api/v1beta3/namespaces/test/pods/foo/exec",
|
execPath: "/api/v1beta3/namespaces/test/pods/foo/exec",
|
||||||
nsInQuery: false,
|
|
||||||
pod: execPod(),
|
pod: execPod(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -135,7 +133,21 @@ func TestExec(t *testing.T) {
|
||||||
version: "v1beta3",
|
version: "v1beta3",
|
||||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||||
execPath: "/api/v1beta3/namespaces/test/pods/foo/exec",
|
execPath: "/api/v1beta3/namespaces/test/pods/foo/exec",
|
||||||
nsInQuery: false,
|
pod: execPod(),
|
||||||
|
execErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "v1 - pod exec",
|
||||||
|
version: "v1",
|
||||||
|
podPath: "/api/v1/namespaces/test/pods/foo",
|
||||||
|
execPath: "/api/v1/namespaces/test/pods/foo/exec",
|
||||||
|
pod: execPod(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "v1 - pod exec error",
|
||||||
|
version: "v1",
|
||||||
|
podPath: "/api/v1/namespaces/test/pods/foo",
|
||||||
|
execPath: "/api/v1/namespaces/test/pods/foo/exec",
|
||||||
pod: execPod(),
|
pod: execPod(),
|
||||||
execErr: true,
|
execErr: true,
|
||||||
},
|
},
|
||||||
|
@ -147,11 +159,6 @@ func TestExec(t *testing.T) {
|
||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == test.podPath && m == "GET":
|
case p == test.podPath && m == "GET":
|
||||||
if test.nsInQuery {
|
|
||||||
if ns := req.URL.Query().Get("namespace"); ns != "test" {
|
|
||||||
t.Errorf("%s: did not get expected namespace: %s\n", test.name, ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body := objBody(codec, test.pod)
|
body := objBody(codec, test.pod)
|
||||||
return &http.Response{StatusCode: 200, Body: body}, nil
|
return &http.Response{StatusCode: 200, Body: body}, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -153,7 +153,6 @@ func TestLog(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name, version, podPath, logPath, container string
|
name, version, podPath, logPath, container string
|
||||||
nsInQuery bool
|
|
||||||
pod *api.Pod
|
pod *api.Pod
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -161,7 +160,13 @@ func TestLog(t *testing.T) {
|
||||||
version: "v1beta3",
|
version: "v1beta3",
|
||||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||||
logPath: "/api/v1beta3/namespaces/test/pods/foo/log",
|
logPath: "/api/v1beta3/namespaces/test/pods/foo/log",
|
||||||
nsInQuery: false,
|
pod: testPod(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "v1 - pod log",
|
||||||
|
version: "v1",
|
||||||
|
podPath: "/api/v1/namespaces/test/pods/foo",
|
||||||
|
logPath: "/api/v1/namespaces/test/pods/foo/log",
|
||||||
pod: testPod(),
|
pod: testPod(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -173,19 +178,9 @@ func TestLog(t *testing.T) {
|
||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == test.podPath && m == "GET":
|
case p == test.podPath && m == "GET":
|
||||||
if test.nsInQuery {
|
|
||||||
if ns := req.URL.Query().Get("namespace"); ns != "test" {
|
|
||||||
t.Errorf("%s: did not get expected namespace: %s\n", test.name, ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body := objBody(codec, test.pod)
|
body := objBody(codec, test.pod)
|
||||||
return &http.Response{StatusCode: 200, Body: body}, nil
|
return &http.Response{StatusCode: 200, Body: body}, nil
|
||||||
case p == test.logPath && m == "GET":
|
case p == test.logPath && m == "GET":
|
||||||
if test.nsInQuery {
|
|
||||||
if ns := req.URL.Query().Get("namespace"); ns != "test" {
|
|
||||||
t.Errorf("%s: did not get expected namespace: %s\n", test.name, ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body := ioutil.NopCloser(bytes.NewBufferString(logContent))
|
body := ioutil.NopCloser(bytes.NewBufferString(logContent))
|
||||||
return &http.Response{StatusCode: 200, Body: body}, nil
|
return &http.Response{StatusCode: 200, Body: body}, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -41,7 +41,6 @@ func TestPortForward(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name, version, podPath, pfPath, container string
|
name, version, podPath, pfPath, container string
|
||||||
nsInQuery bool
|
|
||||||
pod *api.Pod
|
pod *api.Pod
|
||||||
pfErr bool
|
pfErr bool
|
||||||
}{
|
}{
|
||||||
|
@ -50,7 +49,6 @@ func TestPortForward(t *testing.T) {
|
||||||
version: "v1beta3",
|
version: "v1beta3",
|
||||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||||
pfPath: "/api/v1beta3/namespaces/test/pods/foo/portforward",
|
pfPath: "/api/v1beta3/namespaces/test/pods/foo/portforward",
|
||||||
nsInQuery: false,
|
|
||||||
pod: execPod(),
|
pod: execPod(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -58,7 +56,21 @@ func TestPortForward(t *testing.T) {
|
||||||
version: "v1beta3",
|
version: "v1beta3",
|
||||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||||
pfPath: "/api/v1beta3/namespaces/test/pods/foo/portforward",
|
pfPath: "/api/v1beta3/namespaces/test/pods/foo/portforward",
|
||||||
nsInQuery: false,
|
pod: execPod(),
|
||||||
|
pfErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "v1 - pod portforward",
|
||||||
|
version: "v1",
|
||||||
|
podPath: "/api/v1/namespaces/test/pods/foo",
|
||||||
|
pfPath: "/api/v1/namespaces/test/pods/foo/portforward",
|
||||||
|
pod: execPod(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "v1 - pod portforward error",
|
||||||
|
version: "v1",
|
||||||
|
podPath: "/api/v1/namespaces/test/pods/foo",
|
||||||
|
pfPath: "/api/v1/namespaces/test/pods/foo/portforward",
|
||||||
pod: execPod(),
|
pod: execPod(),
|
||||||
pfErr: true,
|
pfErr: true,
|
||||||
},
|
},
|
||||||
|
@ -70,11 +82,6 @@ func TestPortForward(t *testing.T) {
|
||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == test.podPath && m == "GET":
|
case p == test.podPath && m == "GET":
|
||||||
if test.nsInQuery {
|
|
||||||
if ns := req.URL.Query().Get("namespace"); ns != "test" {
|
|
||||||
t.Errorf("%s: did not get expected namespace: %s\n", test.name, ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body := objBody(codec, test.pod)
|
body := objBody(codec, test.pod)
|
||||||
return &http.Response{StatusCode: 200, Body: body}, nil
|
return &http.Response{StatusCode: 200, Body: body}, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -174,6 +174,144 @@ func TestMerge(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Pod",
|
||||||
|
obj: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fragment: `{ "apiVersion": "v1" }`,
|
||||||
|
expected: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
RestartPolicy: api.RestartPolicyAlways,
|
||||||
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
/* TODO: uncomment this test once Merge is updated to use
|
||||||
|
strategic-merge-patch. See #844.
|
||||||
|
{
|
||||||
|
kind: "Pod",
|
||||||
|
obj: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
Containers: []api.Container{
|
||||||
|
api.Container{
|
||||||
|
Name: "c1",
|
||||||
|
Image: "red-image",
|
||||||
|
},
|
||||||
|
api.Container{
|
||||||
|
Name: "c2",
|
||||||
|
Image: "blue-image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fragment: `{ "apiVersion": "v1", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`,
|
||||||
|
expected: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
Containers: []api.Container{
|
||||||
|
api.Container{
|
||||||
|
Name: "c1",
|
||||||
|
Image: "green-image",
|
||||||
|
},
|
||||||
|
api.Container{
|
||||||
|
Name: "c2",
|
||||||
|
Image: "blue-image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, */
|
||||||
|
{
|
||||||
|
kind: "Pod",
|
||||||
|
obj: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fragment: `{ "apiVersion": "v1", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`,
|
||||||
|
expected: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
Volumes: []api.Volume{
|
||||||
|
{
|
||||||
|
Name: "v1",
|
||||||
|
VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "v2",
|
||||||
|
VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RestartPolicy: api.RestartPolicyAlways,
|
||||||
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "Pod",
|
||||||
|
obj: &api.Pod{},
|
||||||
|
fragment: "invalid json",
|
||||||
|
expected: &api.Pod{},
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "Service",
|
||||||
|
obj: &api.Service{},
|
||||||
|
fragment: `{ "apiVersion": "badVersion" }`,
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "Service",
|
||||||
|
obj: &api.Service{
|
||||||
|
Spec: api.ServiceSpec{},
|
||||||
|
},
|
||||||
|
fragment: `{ "apiVersion": "v1", "spec": { "ports": [ { "port": 0 } ] } }`,
|
||||||
|
expected: &api.Service{
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
SessionAffinity: "None",
|
||||||
|
Type: api.ServiceTypeClusterIP,
|
||||||
|
Ports: []api.ServicePort{
|
||||||
|
{
|
||||||
|
Protocol: api.ProtocolTCP,
|
||||||
|
Port: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "Service",
|
||||||
|
obj: &api.Service{
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
Selector: map[string]string{
|
||||||
|
"version": "v1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fragment: `{ "apiVersion": "v1", "spec": { "selector": { "version": "v2" } } }`,
|
||||||
|
expected: &api.Service{
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
SessionAffinity: "None",
|
||||||
|
Type: api.ServiceTypeClusterIP,
|
||||||
|
Selector: map[string]string{
|
||||||
|
"version": "v2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue