2015-08-21 14:23:12 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-12-04 01:22:48 +00:00
|
|
|
package unversioned_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "k8s.io/kubernetes/pkg/client/unversioned"
|
|
|
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
|
|
|
|
)
|
2015-08-21 14:23:12 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
2015-10-09 22:04:41 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2015-08-21 14:23:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getJobResourceName() string {
|
|
|
|
return "jobs"
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListJobs(t *testing.T) {
|
|
|
|
ns := api.NamespaceAll
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "GET",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, ""),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{StatusCode: 200,
|
2015-10-09 22:49:10 +00:00
|
|
|
Body: &extensions.JobList{
|
|
|
|
Items: []extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.JobSpec{
|
2015-09-25 19:07:06 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-12-10 09:39:03 +00:00
|
|
|
receivedJobList, err := c.Setup(t).Extensions().Jobs(ns).List(api.ListOptions{})
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, receivedJobList, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetJob(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "GET",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
|
2015-12-04 01:22:48 +00:00
|
|
|
Query: simple.BuildQueryValues(nil),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{
|
2015-08-21 14:23:12 +00:00
|
|
|
StatusCode: 200,
|
2015-10-09 22:49:10 +00:00
|
|
|
Body: &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.JobSpec{
|
2015-09-25 19:07:06 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-10-12 18:18:50 +00:00
|
|
|
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Get("foo")
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, receivedJob, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetJobWithNoName(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{Error: true}
|
2015-10-12 18:18:50 +00:00
|
|
|
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Get("")
|
2015-12-04 01:22:48 +00:00
|
|
|
if (err != nil) && (err.Error() != simple.NameRequiredError) {
|
|
|
|
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
|
2015-08-21 14:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Validate(t, receivedJob, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateJob(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-10-09 22:49:10 +00:00
|
|
|
requestJob := &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Namespace: ns,
|
|
|
|
ResourceVersion: "1",
|
|
|
|
},
|
|
|
|
}
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "PUT",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
|
2015-12-04 01:22:48 +00:00
|
|
|
Query: simple.BuildQueryValues(nil),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{
|
2015-08-21 14:23:12 +00:00
|
|
|
StatusCode: 200,
|
2015-10-09 22:49:10 +00:00
|
|
|
Body: &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.JobSpec{
|
2015-09-25 19:07:06 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-10-12 18:18:50 +00:00
|
|
|
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Update(requestJob)
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, receivedJob, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateJobStatus(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-10-09 22:49:10 +00:00
|
|
|
requestJob := &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Namespace: ns,
|
|
|
|
ResourceVersion: "1",
|
|
|
|
},
|
|
|
|
}
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "PUT",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo") + "/status",
|
2015-12-04 01:22:48 +00:00
|
|
|
Query: simple.BuildQueryValues(nil),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{
|
2015-08-21 14:23:12 +00:00
|
|
|
StatusCode: 200,
|
2015-10-09 22:49:10 +00:00
|
|
|
Body: &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.JobSpec{
|
2015-09-25 19:07:06 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Status: extensions.JobStatus{
|
2015-08-21 14:23:12 +00:00
|
|
|
Active: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-10-12 18:18:50 +00:00
|
|
|
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).UpdateStatus(requestJob)
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, receivedJob, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteJob(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "DELETE",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
|
2015-12-04 01:22:48 +00:00
|
|
|
Query: simple.BuildQueryValues(nil),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{StatusCode: 200},
|
2015-08-21 14:23:12 +00:00
|
|
|
}
|
2015-10-12 18:18:50 +00:00
|
|
|
err := c.Setup(t).Extensions().Jobs(ns).Delete("foo", nil)
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, nil, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateJob(t *testing.T) {
|
|
|
|
ns := api.NamespaceDefault
|
2015-10-09 22:49:10 +00:00
|
|
|
requestJob := &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Namespace: ns,
|
|
|
|
},
|
|
|
|
}
|
2015-12-04 01:22:48 +00:00
|
|
|
c := &simple.Client{
|
|
|
|
Request: simple.Request{
|
2015-08-21 14:23:12 +00:00
|
|
|
Method: "POST",
|
2015-10-09 22:15:35 +00:00
|
|
|
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, ""),
|
2015-08-21 14:23:12 +00:00
|
|
|
Body: requestJob,
|
2015-12-04 01:22:48 +00:00
|
|
|
Query: simple.BuildQueryValues(nil),
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
2015-12-04 01:22:48 +00:00
|
|
|
Response: simple.Response{
|
2015-08-21 14:23:12 +00:00
|
|
|
StatusCode: 200,
|
2015-10-09 22:49:10 +00:00
|
|
|
Body: &extensions.Job{
|
2015-08-21 14:23:12 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.JobSpec{
|
2015-09-25 19:07:06 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-08-21 14:23:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-10-12 18:18:50 +00:00
|
|
|
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Create(requestJob)
|
2015-08-21 14:23:12 +00:00
|
|
|
c.Validate(t, receivedJob, err)
|
|
|
|
}
|