2015-03-24 23:40:18 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-03-24 23:40:18 +00:00
|
|
|
|
|
|
|
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-08-12 17:35:07 +00:00
|
|
|
package unversioned
|
2015-03-24 23:40:18 +00:00
|
|
|
|
|
|
|
import (
|
2015-03-29 08:49:23 +00:00
|
|
|
"net/url"
|
2015-03-24 23:40:18 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
2015-03-24 23:40:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getNodesResourceName() string {
|
|
|
|
return "nodes"
|
|
|
|
}
|
2015-03-29 08:49:23 +00:00
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestListNodes(t *testing.T) {
|
2015-03-24 23:40:18 +00:00
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "GET",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
|
|
|
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
|
|
|
}
|
2015-09-04 07:06:01 +00:00
|
|
|
response, err := c.Setup(t).Nodes().List(labels.Everything(), fields.Everything())
|
2015-03-24 23:40:18 +00:00
|
|
|
c.Validate(t, response, err)
|
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestListNodesLabels(t *testing.T) {
|
2015-09-04 07:06:01 +00:00
|
|
|
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
|
2015-03-29 08:49:23 +00:00
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "GET",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
|
2015-07-07 23:52:38 +00:00
|
|
|
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
2015-03-29 08:49:23 +00:00
|
|
|
Response: Response{
|
|
|
|
StatusCode: 200,
|
|
|
|
Body: &api.NodeList{
|
|
|
|
Items: []api.Node{
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"name": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-09-04 07:06:01 +00:00
|
|
|
c.Setup(t)
|
2015-03-29 08:49:23 +00:00
|
|
|
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
|
|
|
|
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
2015-04-10 10:08:36 +00:00
|
|
|
receivedNodeList, err := c.Nodes().List(selector, fields.Everything())
|
2015-03-29 08:49:23 +00:00
|
|
|
c.Validate(t, receivedNodeList, err)
|
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestGetNode(t *testing.T) {
|
2015-03-24 23:40:18 +00:00
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "GET",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "1"),
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
2015-09-10 08:40:22 +00:00
|
|
|
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "node-1"}}},
|
2015-03-24 23:40:18 +00:00
|
|
|
}
|
2015-09-04 07:06:01 +00:00
|
|
|
response, err := c.Setup(t).Nodes().Get("1")
|
2015-03-24 23:40:18 +00:00
|
|
|
c.Validate(t, response, err)
|
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestGetNodeWithNoName(t *testing.T) {
|
2015-03-24 23:40:18 +00:00
|
|
|
c := &testClient{Error: true}
|
2015-09-04 07:06:01 +00:00
|
|
|
receivedNode, err := c.Setup(t).Nodes().Get("")
|
2015-03-24 23:40:18 +00:00
|
|
|
if (err != nil) && (err.Error() != nameRequiredError) {
|
|
|
|
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:49:23 +00:00
|
|
|
c.Validate(t, receivedNode, err)
|
2015-03-24 23:40:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestCreateNode(t *testing.T) {
|
|
|
|
requestNode := &api.Node{
|
2015-03-24 23:40:18 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
2015-09-10 08:40:22 +00:00
|
|
|
Name: "node-1",
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
2015-03-25 13:44:40 +00:00
|
|
|
Status: api.NodeStatus{
|
2015-03-24 23:40:18 +00:00
|
|
|
Capacity: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("1000m"),
|
|
|
|
api.ResourceMemory: resource.MustParse("1Mi"),
|
|
|
|
},
|
2015-03-25 13:44:40 +00:00
|
|
|
},
|
|
|
|
Spec: api.NodeSpec{
|
2015-03-24 23:40:18 +00:00
|
|
|
Unschedulable: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "POST",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
|
2015-09-10 08:40:22 +00:00
|
|
|
Body: requestNode},
|
2015-03-24 23:40:18 +00:00
|
|
|
Response: Response{
|
|
|
|
StatusCode: 200,
|
2015-09-10 08:40:22 +00:00
|
|
|
Body: requestNode,
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
|
|
|
}
|
2015-09-10 08:40:22 +00:00
|
|
|
receivedNode, err := c.Setup(t).Nodes().Create(requestNode)
|
|
|
|
c.Validate(t, receivedNode, err)
|
2015-03-24 23:40:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestDeleteNode(t *testing.T) {
|
2015-03-24 23:40:18 +00:00
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "DELETE",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
|
|
|
Response: Response{StatusCode: 200},
|
|
|
|
}
|
2015-09-04 07:06:01 +00:00
|
|
|
err := c.Setup(t).Nodes().Delete("foo")
|
2015-03-24 23:40:18 +00:00
|
|
|
c.Validate(t, nil, err)
|
|
|
|
}
|
|
|
|
|
2015-09-10 08:40:22 +00:00
|
|
|
func TestUpdateNode(t *testing.T) {
|
|
|
|
requestNode := &api.Node{
|
2015-03-24 23:40:18 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
ResourceVersion: "1",
|
|
|
|
},
|
2015-03-25 13:44:40 +00:00
|
|
|
Status: api.NodeStatus{
|
2015-03-24 23:40:18 +00:00
|
|
|
Capacity: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("1000m"),
|
|
|
|
api.ResourceMemory: resource.MustParse("1Mi"),
|
|
|
|
},
|
2015-03-25 13:44:40 +00:00
|
|
|
},
|
|
|
|
Spec: api.NodeSpec{
|
2015-03-24 23:40:18 +00:00
|
|
|
Unschedulable: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
c := &testClient{
|
|
|
|
Request: testRequest{
|
|
|
|
Method: "PUT",
|
2015-09-04 07:06:01 +00:00
|
|
|
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
|
2015-03-24 23:40:18 +00:00
|
|
|
},
|
2015-09-10 08:40:22 +00:00
|
|
|
Response: Response{StatusCode: 200, Body: requestNode},
|
2015-03-24 23:40:18 +00:00
|
|
|
}
|
2015-09-10 08:40:22 +00:00
|
|
|
response, err := c.Setup(t).Nodes().Update(requestNode)
|
2015-03-24 23:40:18 +00:00
|
|
|
c.Validate(t, response, err)
|
|
|
|
}
|