mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Updating unit tests for pkg/client so that they pass with v1beta3 api
This commit is contained in:
parent
f584069573
commit
ba3746172f
@ -27,8 +27,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@ -37,8 +35,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
// TODO: Move this to a common place, it's needed in multiple tests.
|
||||
const apiPath = "/api/v1beta1"
|
||||
const nameRequiredError = "name is required parameter to Get"
|
||||
|
||||
type testRequest struct {
|
||||
@ -135,14 +131,14 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
|
||||
// We check the query manually, so blank it out so that FakeHandler.ValidateRequest
|
||||
// won't check it.
|
||||
c.handler.RequestReceived.URL.RawQuery = ""
|
||||
c.handler.ValidateRequest(t, path.Join(apiPath, c.Request.Path), c.Request.Method, requestBody)
|
||||
c.handler.ValidateRequest(t, path.Join(c.Request.Path), c.Request.Method, requestBody)
|
||||
for key, values := range c.Request.Query {
|
||||
validator, ok := c.QueryValidator[key]
|
||||
if !ok {
|
||||
switch key {
|
||||
case "labels":
|
||||
case api.LabelSelectorQueryParam(testapi.Version()):
|
||||
validator = validateLabels
|
||||
case "fields":
|
||||
case api.FieldSelectorQueryParam(testapi.Version()):
|
||||
validator = validateFields
|
||||
default:
|
||||
validator = func(a, b string) bool { return a == b }
|
||||
@ -186,49 +182,13 @@ func buildQueryValues(namespace string, query url.Values) url.Values {
|
||||
}
|
||||
}
|
||||
if len(namespace) > 0 {
|
||||
if testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2" {
|
||||
if api.PreV1Beta3(testapi.Version()) {
|
||||
v.Set("namespace", namespace)
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func TestListEmptyPods(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/pods"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.PodList{}},
|
||||
}
|
||||
podList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||
c.Validate(t, podList, err)
|
||||
}
|
||||
|
||||
func TestListPods(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/pods"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||
c.Validate(t, receivedPodList, err)
|
||||
}
|
||||
|
||||
func validateLabels(a, b string) bool {
|
||||
sA, eA := labels.Parse(a)
|
||||
if eA != nil {
|
||||
@ -247,421 +207,15 @@ func validateFields(a, b string) bool {
|
||||
return sA.String() == sB.String()
|
||||
}
|
||||
|
||||
func TestListPodsLabels(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/pods"), Query: buildQueryValues(ns, url.Values{"labels": []string{"foo=bar,name=baz"}})},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c.Setup()
|
||||
c.QueryValidator["labels"] = validateLabels
|
||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||
receivedPodList, err := c.Pods(ns).List(selector)
|
||||
c.Validate(t, receivedPodList, err)
|
||||
}
|
||||
|
||||
func TestGetPod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/pods/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.Pod{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Get("foo")
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestGetPodWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Pods(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestDeletePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: buildResourcePath(ns, "/pods/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Pods(ns).Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCreatePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestPod := &api.Pod{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: buildResourcePath(ns, "/pods"), Query: buildQueryValues(ns, nil), Body: requestPod},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: requestPod,
|
||||
},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Create(requestPod)
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestUpdatePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestPod := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/pods/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: requestPod},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Update(requestPod)
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestListControllers(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/replicationControllers"},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ReplicationControllerList{
|
||||
Items: []api.ReplicationController{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedControllerList, err := c.Setup().ReplicationControllers(api.NamespaceAll).List(labels.Everything())
|
||||
c.Validate(t, receivedControllerList, err)
|
||||
|
||||
}
|
||||
|
||||
func TestGetController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/replicationControllers/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Get("foo")
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func TestGetControllerWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().ReplicationControllers(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestUpdateController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestController := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/replicationControllers/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Update(requestController)
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func TestDeleteController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: buildResourcePath(ns, "/replicationControllers/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().ReplicationControllers(ns).Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCreateController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestController := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: buildResourcePath(ns, "/replicationControllers"), Body: requestController, Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Create(requestController)
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func body(obj runtime.Object, raw *string) *string {
|
||||
if obj != nil {
|
||||
bs, _ := latest.Codec.Encode(obj)
|
||||
bs, _ := testapi.Codec().Encode(obj)
|
||||
body := string(bs)
|
||||
return &body
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
func TestListServices(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/services"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "name",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"one": "two",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedServiceList, err := c.Setup().Services(ns).List(labels.Everything())
|
||||
t.Logf("received services: %v %#v", err, receivedServiceList)
|
||||
c.Validate(t, receivedServiceList, err)
|
||||
}
|
||||
|
||||
func TestListServicesLabels(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/services"), Query: buildQueryValues(ns, url.Values{"labels": []string{"foo=bar,name=baz"}})},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "name",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"one": "two",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c.Setup()
|
||||
c.QueryValidator["labels"] = validateLabels
|
||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||
receivedServiceList, err := c.Services(ns).List(selector)
|
||||
c.Validate(t, receivedServiceList, err)
|
||||
}
|
||||
|
||||
func TestGetService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/services/1"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Get("1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetServiceWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Services(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestCreateService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: buildResourcePath(ns, "/services"), Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}, Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestUpdateService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
svc := &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1", ResourceVersion: "1"}}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/services/service-1"), Body: svc, Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: svc},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Update(svc)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestDeleteService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: buildResourcePath(ns, "/services/1"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Services(ns).Delete("1")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestListEndpooints(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/endpoints"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.EndpointsList{
|
||||
Items: []api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "endpoint-1"},
|
||||
Endpoints: []api.Endpoint{
|
||||
{IP: "10.245.1.2", Port: 8080}, {IP: "10.245.1.3", Port: 8080}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedEndpointsList, err := c.Setup().Endpoints(ns).List(labels.Everything())
|
||||
c.Validate(t, receivedEndpointsList, err)
|
||||
}
|
||||
|
||||
func TestGetEndpoints(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: buildResourcePath(ns, "/endpoints/endpoint-1"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Endpoints(ns).Get("endpoint-1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetEndpointWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Endpoints(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestGetServerVersion(t *testing.T) {
|
||||
expect := version.Info{
|
||||
Major: "foo",
|
||||
@ -711,97 +265,3 @@ func TestGetServerAPIVersions(t *testing.T) {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListMinions(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/minions"},
|
||||
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
||||
}
|
||||
response, err := c.Setup().Nodes().List()
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetMinion(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/minions/1"},
|
||||
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "minion-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Nodes().Get("1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetMinionWithNoName(t *testing.T) {
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Nodes().Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestCreateMinion(t *testing.T) {
|
||||
requestMinion := &api.Node{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "minion-1",
|
||||
},
|
||||
Spec: api.NodeSpec{
|
||||
Capacity: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1000m"),
|
||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||
},
|
||||
Unschedulable: false,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: "/minions", Body: requestMinion},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: requestMinion,
|
||||
},
|
||||
}
|
||||
receivedMinion, err := c.Setup().Nodes().Create(requestMinion)
|
||||
c.Validate(t, receivedMinion, err)
|
||||
}
|
||||
|
||||
func TestDeleteMinion(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/minions/foo"},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Nodes().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestUpdateMinion(t *testing.T) {
|
||||
requestMinion := &api.Node{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Spec: api.NodeSpec{
|
||||
Capacity: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1000m"),
|
||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||
},
|
||||
Unschedulable: true,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/minions/foo"},
|
||||
Response: Response{StatusCode: 200, Body: requestMinion},
|
||||
}
|
||||
response, err := c.Setup().Nodes().Update(requestMinion)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestNewMinionPath(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/nodes/foo"},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
cl := c.Setup()
|
||||
cl.apiVersion = "v1beta3"
|
||||
err := cl.Nodes().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
66
pkg/client/endpoints_test.go
Normal file
66
pkg/client/endpoints_test.go
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. 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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func TestListEndpooints(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, ""), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.EndpointsList{
|
||||
Items: []api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "endpoint-1"},
|
||||
Endpoints: []api.Endpoint{
|
||||
{IP: "10.245.1.2", Port: 8080}, {IP: "10.245.1.3", Port: 8080}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedEndpointsList, err := c.Setup().Endpoints(ns).List(labels.Everything())
|
||||
c.Validate(t, receivedEndpointsList, err)
|
||||
}
|
||||
|
||||
func TestGetEndpoints(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, "endpoint-1"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Endpoints(ns).Get("endpoint-1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetEndpointWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Endpoints(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
Copyright 2015 Google Inc. 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.
|
||||
@ -32,19 +32,19 @@ func TestEventSearch(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/events",
|
||||
Path: testapi.ResourcePath("events", "baz", ""),
|
||||
Query: url.Values{
|
||||
"fields": []string{
|
||||
"involvedObject.kind=Pod,",
|
||||
api.FieldSelectorQueryParam(testapi.Version()): []string{
|
||||
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,",
|
||||
"involvedObject.namespace=baz",
|
||||
"involvedObject.namespace=baz,",
|
||||
"involvedObject.kind=Pod",
|
||||
},
|
||||
"labels": []string{},
|
||||
api.LabelSelectorQueryParam(testapi.Version()): []string{},
|
||||
},
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: &api.EventList{}},
|
||||
}
|
||||
eventList, err := c.Setup().Events("").Search(
|
||||
eventList, err := c.Setup().Events("baz").Search(
|
||||
&api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
@ -78,13 +78,13 @@ func TestEventCreate(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: "/events",
|
||||
Path: testapi.ResourcePath("events", api.NamespaceDefault, ""),
|
||||
Body: event,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: event},
|
||||
}
|
||||
|
||||
response, err := c.Setup().Events("").Create(event)
|
||||
response, err := c.Setup().Events(api.NamespaceDefault).Create(event)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v should be nil.", err)
|
||||
@ -117,13 +117,13 @@ func TestEventGet(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/events/1",
|
||||
Path: testapi.ResourcePath("events", "other", "1"),
|
||||
Body: nil,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: event},
|
||||
}
|
||||
|
||||
response, err := c.Setup().Events("").Get("1")
|
||||
response, err := c.Setup().Events("other").Get("1")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("%v should be nil.", err)
|
||||
@ -158,7 +158,7 @@ func TestEventList(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/events",
|
||||
Path: testapi.ResourcePath("events", ns, ""),
|
||||
Body: nil,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: eventList},
|
||||
@ -184,7 +184,10 @@ func TestEventList(t *testing.T) {
|
||||
func TestEventDelete(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/events/foo"},
|
||||
Request: testRequest{
|
||||
Method: "DELETE",
|
||||
Path: testapi.ResourcePath("events", ns, "foo"),
|
||||
},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Events(ns).Delete("foo")
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
Copyright 2015 Google Inc. 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.
|
||||
@ -22,10 +22,18 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func getLimitRangesResourceName() string {
|
||||
if api.PreV1Beta3(testapi.Version()) {
|
||||
return "limitRanges"
|
||||
}
|
||||
return "limitranges"
|
||||
}
|
||||
|
||||
func TestLimitRangeCreate(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
limitRange := &api.LimitRange{
|
||||
@ -51,7 +59,7 @@ func TestLimitRangeCreate(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: buildResourcePath(ns, "/limitRanges"),
|
||||
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: limitRange,
|
||||
},
|
||||
@ -87,7 +95,7 @@ func TestLimitRangeGet(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: buildResourcePath(ns, "/limitRanges/abc"),
|
||||
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: nil,
|
||||
},
|
||||
@ -111,7 +119,7 @@ func TestLimitRangeList(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: buildResourcePath(ns, "/limitRanges"),
|
||||
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: nil,
|
||||
},
|
||||
@ -145,7 +153,7 @@ func TestLimitRangeUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/limitRanges/abc"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: limitRange},
|
||||
}
|
||||
response, err := c.Setup().LimitRanges(ns).Update(limitRange)
|
||||
@ -175,7 +183,7 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/limitRanges/abc"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: limitRange},
|
||||
}
|
||||
_, err := c.Setup().LimitRanges(ns).Update(limitRange)
|
||||
@ -187,7 +195,7 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
|
||||
func TestLimitRangeDelete(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: buildResourcePath(ns, "/limitRanges/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().LimitRanges(ns).Delete("foo")
|
||||
@ -196,7 +204,10 @@ func TestLimitRangeDelete(t *testing.T) {
|
||||
|
||||
func TestLimitRangeWatch(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/watch/limitRanges", Query: url.Values{"resourceVersion": []string{}}},
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/api/" + testapi.Version() + "/watch/" + getLimitRangesResourceName(),
|
||||
Query: url.Values{"resourceVersion": []string{}}},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
_, err := c.Setup().LimitRanges(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
|
||||
|
129
pkg/client/minions_test.go
Normal file
129
pkg/client/minions_test.go
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. 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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
)
|
||||
|
||||
func getNodesResourceName() string {
|
||||
if api.PreV1Beta3(testapi.Version()) {
|
||||
return "minions"
|
||||
}
|
||||
return "nodes"
|
||||
}
|
||||
func TestListMinions(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
||||
}
|
||||
response, err := c.Setup().Nodes().List()
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetMinion(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", "1"),
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "minion-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Nodes().Get("1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetMinionWithNoName(t *testing.T) {
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Nodes().Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestCreateMinion(t *testing.T) {
|
||||
requestMinion := &api.Node{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "minion-1",
|
||||
},
|
||||
Spec: api.NodeSpec{
|
||||
Capacity: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1000m"),
|
||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||
},
|
||||
Unschedulable: false,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
|
||||
Body: requestMinion},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: requestMinion,
|
||||
},
|
||||
}
|
||||
receivedMinion, err := c.Setup().Nodes().Create(requestMinion)
|
||||
c.Validate(t, receivedMinion, err)
|
||||
}
|
||||
|
||||
func TestDeleteMinion(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "DELETE",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"),
|
||||
},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Nodes().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestUpdateMinion(t *testing.T) {
|
||||
requestMinion := &api.Node{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Spec: api.NodeSpec{
|
||||
Capacity: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1000m"),
|
||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||
},
|
||||
Unschedulable: true,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "PUT",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"),
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: requestMinion},
|
||||
}
|
||||
response, err := c.Setup().Nodes().Update(requestMinion)
|
||||
c.Validate(t, response, err)
|
||||
}
|
@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
@ -33,7 +34,7 @@ func TestNamespaceCreate(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: "/namespaces",
|
||||
Path: testapi.ResourcePath("namespaces", "", ""),
|
||||
Body: namespace,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: namespace},
|
||||
@ -58,7 +59,7 @@ func TestNamespaceGet(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/namespaces/foo",
|
||||
Path: testapi.ResourcePath("namespaces", "", "foo"),
|
||||
Body: nil,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: namespace},
|
||||
@ -86,7 +87,7 @@ func TestNamespaceList(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/namespaces",
|
||||
Path: testapi.ResourcePath("namespaces", "", ""),
|
||||
Body: nil,
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: namespaceList},
|
||||
@ -122,7 +123,9 @@ func TestNamespaceUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/namespaces/foo"},
|
||||
Request: testRequest{
|
||||
Method: "PUT",
|
||||
Path: testapi.ResourcePath("namespaces", "", "foo")},
|
||||
Response: Response{StatusCode: 200, Body: requestNamespace},
|
||||
}
|
||||
receivedNamespace, err := c.Setup().Namespaces().Update(requestNamespace)
|
||||
@ -144,7 +147,10 @@ func TestNamespaceFinalize(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/namespaces/foo/finalize"},
|
||||
Request: testRequest{
|
||||
Method: "PUT",
|
||||
Path: testapi.ResourcePath("namespaces", "", "foo") + "/finalize",
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: requestNamespace},
|
||||
}
|
||||
receivedNamespace, err := c.Setup().Namespaces().Finalize(requestNamespace)
|
||||
@ -153,7 +159,7 @@ func TestNamespaceFinalize(t *testing.T) {
|
||||
|
||||
func TestNamespaceDelete(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/namespaces/foo"},
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("namespaces", "", "foo")},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Namespaces().Delete("foo")
|
||||
@ -162,7 +168,10 @@ func TestNamespaceDelete(t *testing.T) {
|
||||
|
||||
func TestNamespaceWatch(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/watch/namespaces", Query: url.Values{"resourceVersion": []string{}}},
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/api/" + testapi.Version() + "/watch/namespaces",
|
||||
Query: url.Values{"resourceVersion": []string{}}},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
_, err := c.Setup().Namespaces().Watch(labels.Everything(), fields.Everything(), "")
|
||||
|
187
pkg/client/pods_test.go
Normal file
187
pkg/client/pods_test.go
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. 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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func TestListEmptyPods(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.PodList{}},
|
||||
}
|
||||
podList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||
c.Validate(t, podList, err)
|
||||
}
|
||||
|
||||
func TestListPods(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||
c.Validate(t, receivedPodList, err)
|
||||
}
|
||||
|
||||
func TestListPodsLabels(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath("pods", ns, ""),
|
||||
Query: buildQueryValues(ns, url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c.Setup()
|
||||
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
|
||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||
receivedPodList, err := c.Pods(ns).List(selector)
|
||||
c.Validate(t, receivedPodList, err)
|
||||
}
|
||||
|
||||
func TestGetPod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.Pod{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Get("foo")
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestGetPodWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Pods(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestDeletePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Pods(ns).Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCreatePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestPod := &api.Pod{
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(ns, nil), Body: requestPod},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: requestPod,
|
||||
},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Create(requestPod)
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestUpdatePod(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestPod := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: requestPod},
|
||||
}
|
||||
receivedPod, err := c.Setup().Pods(ns).Update(requestPod)
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
166
pkg/client/replication_controllers_test.go
Normal file
166
pkg/client/replication_controllers_test.go
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. 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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func getRCResourceName() string {
|
||||
if api.PreV1Beta3(testapi.Version()) {
|
||||
return "replicationControllers"
|
||||
}
|
||||
return "replicationcontrollers"
|
||||
}
|
||||
|
||||
func TestListControllers(t *testing.T) {
|
||||
ns := api.NamespaceAll
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath(getRCResourceName(), ns, ""),
|
||||
},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ReplicationControllerList{
|
||||
Items: []api.ReplicationController{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedControllerList, err := c.Setup().ReplicationControllers(ns).List(labels.Everything())
|
||||
c.Validate(t, receivedControllerList, err)
|
||||
|
||||
}
|
||||
|
||||
func TestGetController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Get("foo")
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func TestGetControllerWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().ReplicationControllers(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestUpdateController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestController := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Update(requestController)
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func TestDeleteController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().ReplicationControllers(ns).Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCreateController(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestController := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: testapi.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 2,
|
||||
Template: &api.PodTemplateSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedController, err := c.Setup().ReplicationControllers(ns).Create(requestController)
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
@ -22,10 +22,18 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func getResourceQuotasResoureName() string {
|
||||
if api.PreV1Beta3(testapi.Version()) {
|
||||
return "resourceQuotas"
|
||||
}
|
||||
return "resourcequotas"
|
||||
}
|
||||
|
||||
func TestResourceQuotaCreate(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
resourceQuota := &api.ResourceQuota{
|
||||
@ -47,7 +55,7 @@ func TestResourceQuotaCreate(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: buildResourcePath(ns, "/resourceQuotas"),
|
||||
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: resourceQuota,
|
||||
},
|
||||
@ -79,7 +87,7 @@ func TestResourceQuotaGet(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: buildResourcePath(ns, "/resourceQuotas/abc"),
|
||||
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: nil,
|
||||
},
|
||||
@ -103,7 +111,7 @@ func TestResourceQuotaList(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: buildResourcePath(ns, "/resourceQuotas"),
|
||||
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""),
|
||||
Query: buildQueryValues(ns, nil),
|
||||
Body: nil,
|
||||
},
|
||||
@ -133,7 +141,7 @@ func TestResourceQuotaUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/resourceQuotas/abc"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: resourceQuota},
|
||||
}
|
||||
response, err := c.Setup().ResourceQuotas(ns).Update(resourceQuota)
|
||||
@ -160,7 +168,10 @@ func TestResourceQuotaStatusUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/resourceQuotas/abc/status"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{
|
||||
Method: "PUT",
|
||||
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status",
|
||||
Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: resourceQuota},
|
||||
}
|
||||
response, err := c.Setup().ResourceQuotas(ns).Status(resourceQuota)
|
||||
@ -186,7 +197,7 @@ func TestInvalidResourceQuotaUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: buildResourcePath(ns, "/resourceQuotas/abc"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: resourceQuota},
|
||||
}
|
||||
_, err := c.Setup().ResourceQuotas(ns).Update(resourceQuota)
|
||||
@ -198,7 +209,7 @@ func TestInvalidResourceQuotaUpdate(t *testing.T) {
|
||||
func TestResourceQuotaDelete(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: buildResourcePath(ns, "/resourceQuotas/foo"), Query: buildQueryValues(ns, nil)},
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().ResourceQuotas(ns).Delete("foo")
|
||||
@ -207,7 +218,10 @@ func TestResourceQuotaDelete(t *testing.T) {
|
||||
|
||||
func TestResourceQuotaWatch(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/watch/resourceQuotas", Query: url.Values{"resourceVersion": []string{}}},
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: "/api/" + testapi.Version() + "/watch/" + getResourceQuotasResoureName(),
|
||||
Query: url.Values{"resourceVersion": []string{}}},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
_, err := c.Setup().ResourceQuotas(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
|
||||
|
154
pkg/client/services_test.go
Normal file
154
pkg/client/services_test.go
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. 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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func TestListServices(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath("services", ns, ""),
|
||||
Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "name",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"one": "two",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
receivedServiceList, err := c.Setup().Services(ns).List(labels.Everything())
|
||||
t.Logf("received services: %v %#v", err, receivedServiceList)
|
||||
c.Validate(t, receivedServiceList, err)
|
||||
}
|
||||
|
||||
func TestListServicesLabels(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath("services", ns, ""),
|
||||
Query: buildQueryValues(ns, url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "name",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"one": "two",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c.Setup()
|
||||
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
|
||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||
receivedServiceList, err := c.Services(ns).List(selector)
|
||||
c.Validate(t, receivedServiceList, err)
|
||||
}
|
||||
|
||||
func TestGetService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath("services", ns, "1"),
|
||||
Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Get("1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestGetServiceWithNoName(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Services(ns).Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
}
|
||||
|
||||
func TestCreateService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "POST",
|
||||
Path: testapi.ResourcePath("services", ns, ""),
|
||||
Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}},
|
||||
Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestUpdateService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
svc := &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1", ResourceVersion: "1"}}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath("services", ns, "service-1"), Body: svc, Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200, Body: svc},
|
||||
}
|
||||
response, err := c.Setup().Services(ns).Update(svc)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestDeleteService(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("services", ns, "1"), Query: buildQueryValues(ns, nil)},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Services(ns).Delete("1")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user