Move pkg/client/unvrsioned#testClient to pkg/client/unversioned/testclient#simple

This commit is contained in:
Chao Xu 2015-12-03 17:22:48 -08:00
parent 8d46df0162
commit 6f0eb521a6
20 changed files with 723 additions and 622 deletions

View File

@ -20,222 +20,16 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"path"
"reflect"
"strings"
"testing"
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/version"
)
const nameRequiredError = "resource name may not be empty"
type testRequest struct {
Method string
Path string
Header string
Query url.Values
Body runtime.Object
RawBody *string
}
type Response struct {
StatusCode int
Body runtime.Object
RawBody *string
}
type testClient struct {
*Client
Request testRequest
Response Response
Error bool
Created bool
server *httptest.Server
handler *util.FakeHandler
// For query args, an optional function to validate the contents
// useful when the contents can change but still be correct.
// Maps from query arg key to validator.
// If no validator is present, string equality is used.
QueryValidator map[string]func(string, string) bool
}
func (c *testClient) Setup(t *testing.T) *testClient {
c.handler = &util.FakeHandler{
StatusCode: c.Response.StatusCode,
}
if responseBody := body(t, c.Response.Body, c.Response.RawBody); responseBody != nil {
c.handler.ResponseBody = *responseBody
}
c.server = httptest.NewServer(c.handler)
if c.Client == nil {
c.Client = NewOrDie(&Config{
Host: c.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
})
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
c.ExtensionsClient = NewExtensionsOrDie(&Config{
Host: c.server.URL,
GroupVersion: testapi.Extensions.GroupVersion(),
})
}
c.QueryValidator = map[string]func(string, string) bool{}
return c
}
func (c *testClient) Validate(t *testing.T, received runtime.Object, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !api.Semantic.DeepDerivative(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
}
}
func (c *testClient) ValidateRaw(t *testing.T, received []byte, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
}
}
func (c *testClient) ValidateCommon(t *testing.T, err error) {
defer c.server.Close()
if c.Error {
if err == nil {
t.Errorf("error expected for %#v, got none", c.Request)
}
return
}
if err != nil {
t.Errorf("no error expected for %#v, got: %v", c.Request, err)
}
if c.handler.RequestReceived == nil {
t.Errorf("handler had an empty request, %#v", c)
return
}
requestBody := body(t, c.Request.Body, c.Request.RawBody)
actualQuery := c.handler.RequestReceived.URL.Query()
t.Logf("got query: %v", actualQuery)
t.Logf("path: %v", c.Request.Path)
// 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(c.Request.Path), c.Request.Method, requestBody)
for key, values := range c.Request.Query {
validator, ok := c.QueryValidator[key]
if !ok {
switch key {
case unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String()):
validator = validateLabels
case unversioned.FieldSelectorQueryParam(testapi.Default.GroupVersion().String()):
validator = validateFields
default:
validator = func(a, b string) bool { return a == b }
}
}
observed := actualQuery.Get(key)
wanted := strings.Join(values, "")
if !validator(wanted, observed) {
t.Errorf("Unexpected query arg for key: %s. Expected %s, Received %s", key, wanted, observed)
}
}
if c.Request.Header != "" {
if c.handler.RequestReceived.Header.Get(c.Request.Header) == "" {
t.Errorf("header %q not found in request %#v", c.Request.Header, c.handler.RequestReceived)
}
}
if expected, received := requestBody, c.handler.RequestBody; expected != nil && *expected != received {
t.Errorf("bad body for request %#v: expected %s, got %s", c.Request, *expected, received)
}
}
// buildResourcePath is a convenience function for knowing if a namespace should be in a path param or not
func buildResourcePath(namespace, resource string) string {
if len(namespace) > 0 {
return path.Join("namespaces", namespace, resource)
}
return resource
}
// buildQueryValues is a convenience function for knowing if a namespace should be in a query param or not
func buildQueryValues(query url.Values) url.Values {
v := url.Values{}
if query != nil {
for key, values := range query {
for _, value := range values {
v.Add(key, value)
}
}
}
return v
}
func validateLabels(a, b string) bool {
sA, eA := labels.Parse(a)
if eA != nil {
return false
}
sB, eB := labels.Parse(b)
if eB != nil {
return false
}
return sA.String() == sB.String()
}
func validateFields(a, b string) bool {
sA, _ := fields.ParseSelector(a)
sB, _ := fields.ParseSelector(b)
return sA.String() == sB.String()
}
func body(t *testing.T, obj runtime.Object, raw *string) *string {
if obj != nil {
fqKind, err := api.Scheme.ObjectKind(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
var bs []byte
if api.Scheme.Recognizes(testapi.Default.GroupVersion().WithKind(fqKind.Kind)) {
bs, err = testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else if api.Scheme.Recognizes(testapi.Extensions.GroupVersion().WithKind(fqKind.Kind)) {
bs, err = testapi.Extensions.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else {
t.Errorf("unexpected kind: %v", fqKind.Kind)
}
body := string(bs)
return &body
}
return raw
}
func TestGetServerVersion(t *testing.T) {
expect := version.Info{
Major: "foo",

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"testing"
@ -31,12 +36,12 @@ func getDSResourceName() string {
func TestListDaemonSets(t *testing.T) {
ns := api.NamespaceAll
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Response: simple.Response{StatusCode: 200,
Body: &extensions.DaemonSetList{
Items: []extensions.DaemonSet{
{
@ -62,9 +67,9 @@ func TestListDaemonSets(t *testing.T) {
func TestGetDaemonSet(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{
@ -86,10 +91,10 @@ func TestGetDaemonSet(t *testing.T) {
func TestGetDaemonSetWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedPod, err := c.Setup(t).Extensions().DaemonSets(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedPod, err)
@ -100,9 +105,9 @@ func TestUpdateDaemonSet(t *testing.T) {
requestDaemonSet := &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{
@ -127,9 +132,9 @@ func TestUpdateDaemonSetUpdateStatus(t *testing.T) {
requestDaemonSet := &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo") + "/status", Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo") + "/status", Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{
@ -152,9 +157,9 @@ func TestUpdateDaemonSetUpdateStatus(t *testing.T) {
func TestDeleteDaemon(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Extensions().DaemonSets(ns).Delete("foo")
c.Validate(t, nil, err)
@ -165,9 +170,9 @@ func TestCreateDaemonSet(t *testing.T) {
requestDaemonSet := &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, ""), Body: requestDaemonSet, Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "POST", Path: testapi.Extensions.ResourcePath(getDSResourceName(), ns, ""), Body: requestDaemonSet, Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &extensions.DaemonSet{
ObjectMeta: api.ObjectMeta{

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -38,14 +43,14 @@ func TestDeploymentCreate(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: &deployment,
},
Response: Response{StatusCode: 200, Body: &deployment},
Response: simple.Response{StatusCode: 200, Body: &deployment},
}
response, err := c.Setup(t).Deployments(ns).Create(&deployment)
@ -63,14 +68,14 @@ func TestDeploymentGet(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: deployment},
Response: simple.Response{StatusCode: 200, Body: deployment},
}
response, err := c.Setup(t).Deployments(ns).Get("abc")
@ -89,14 +94,14 @@ func TestDeploymentList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: deploymentList},
Response: simple.Response{StatusCode: 200, Body: deploymentList},
}
response, err := c.Setup(t).Deployments(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -111,13 +116,13 @@ func TestDeploymentUpdate(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{StatusCode: 200, Body: deployment},
Response: simple.Response{StatusCode: 200, Body: deployment},
}
response, err := c.Setup(t).Deployments(ns).Update(deployment)
c.Validate(t, response, err)
@ -132,13 +137,13 @@ func TestDeploymentUpdateStatus(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{StatusCode: 200, Body: deployment},
Response: simple.Response{StatusCode: 200, Body: deployment},
}
response, err := c.Setup(t).Deployments(ns).UpdateStatus(deployment)
c.Validate(t, response, err)
@ -146,26 +151,26 @@ func TestDeploymentUpdateStatus(t *testing.T) {
func TestDeploymentDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "DELETE",
Path: testapi.Extensions.ResourcePath(getDeploymentsResoureName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Deployments(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
func TestDeploymentWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePathWithPrefix("watch", getDeploymentsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}},
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).Deployments(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"testing"
@ -26,9 +31,9 @@ import (
func TestListEndpoints(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, ""), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200,
Body: &api.EndpointsList{
Items: []api.Endpoints{
{
@ -48,9 +53,9 @@ func TestListEndpoints(t *testing.T) {
func TestGetEndpoints(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, "endpoint-1"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, "endpoint-1"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
}
response, err := c.Setup(t).Endpoints(ns).Get("endpoint-1")
c.Validate(t, response, err)
@ -58,10 +63,10 @@ func TestGetEndpoints(t *testing.T) {
func TestGetEndpointWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedPod, err := c.Setup(t).Endpoints(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedPod, err)

View File

@ -190,7 +190,7 @@ func (e *events) GetFieldSelector(involvedObjectName, involvedObjectNamespace, i
apiVersion := e.client.APIVersion().String()
field := fields.Set{}
if involvedObjectName != nil {
field[getInvolvedObjectNameFieldLabel(apiVersion)] = *involvedObjectName
field[GetInvolvedObjectNameFieldLabel(apiVersion)] = *involvedObjectName
}
if involvedObjectNamespace != nil {
field["involvedObject.namespace"] = *involvedObjectNamespace
@ -205,6 +205,6 @@ func (e *events) GetFieldSelector(involvedObjectName, involvedObjectNamespace, i
}
// Returns the appropriate field label to use for name of the involved object as per the given API version.
func getInvolvedObjectNameFieldLabel(version string) string {
func GetInvolvedObjectNameFieldLabel(version string) string {
return "involvedObject.name"
}

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -27,20 +32,20 @@ import (
)
func TestEventSearch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("events", "baz", ""),
Query: url.Values{
unversioned.FieldSelectorQueryParam(testapi.Default.GroupVersion().String()): []string{
getInvolvedObjectNameFieldLabel(testapi.Default.GroupVersion().String()) + "=foo,",
GetInvolvedObjectNameFieldLabel(testapi.Default.GroupVersion().String()) + "=foo,",
"involvedObject.namespace=baz,",
"involvedObject.kind=Pod",
},
unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String()): []string{},
},
},
Response: Response{StatusCode: 200, Body: &api.EventList{}},
Response: simple.Response{StatusCode: 200, Body: &api.EventList{}},
}
eventList, err := c.Setup(t).Events("baz").Search(
&api.Pod{
@ -74,13 +79,13 @@ func TestEventCreate(t *testing.T) {
Count: 1,
Type: api.EventTypeNormal,
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath("events", api.NamespaceDefault, ""),
Body: event,
},
Response: Response{StatusCode: 200, Body: event},
Response: simple.Response{StatusCode: 200, Body: event},
}
response, err := c.Setup(t).Events(api.NamespaceDefault).Create(event)
@ -114,13 +119,13 @@ func TestEventGet(t *testing.T) {
Count: 1,
Type: api.EventTypeNormal,
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("events", "other", "1"),
Body: nil,
},
Response: Response{StatusCode: 200, Body: event},
Response: simple.Response{StatusCode: 200, Body: event},
}
response, err := c.Setup(t).Events("other").Get("1")
@ -156,13 +161,13 @@ func TestEventList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("events", ns, ""),
Body: nil,
},
Response: Response{StatusCode: 200, Body: eventList},
Response: simple.Response{StatusCode: 200, Body: eventList},
}
response, err := c.Setup(t).Events(ns).List(unversioned.ListOptions{})
@ -183,12 +188,12 @@ func TestEventList(t *testing.T) {
func TestEventDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "DELETE",
Path: testapi.Default.ResourcePath("events", ns, "foo"),
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Events(ns).Delete("foo")
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -38,14 +43,14 @@ func TestHorizontalPodAutoscalerCreate(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: &horizontalPodAutoscaler,
},
Response: Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
Response: simple.Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
}
response, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).Create(&horizontalPodAutoscaler)
@ -63,14 +68,14 @@ func TestHorizontalPodAutoscalerGet(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler},
Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
}
response, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).Get("abc")
@ -89,14 +94,14 @@ func TestHorizontalPodAutoscalerList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
}
response, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -111,9 +116,9 @@ func TestHorizontalPodAutoscalerUpdate(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
}
response, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler)
c.Validate(t, response, err)
@ -128,9 +133,9 @@ func TestHorizontalPodAutoscalerUpdateStatus(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc") + "/status", Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc") + "/status", Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
}
response, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).UpdateStatus(horizontalPodAutoscaler)
c.Validate(t, response, err)
@ -138,21 +143,21 @@ func TestHorizontalPodAutoscalerUpdateStatus(t *testing.T) {
func TestHorizontalPodAutoscalerDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Extensions.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Extensions().HorizontalPodAutoscalers(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
func TestHorizontalPodAutoscalerWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).Extensions().HorizontalPodAutoscalers(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"testing"
@ -31,12 +36,12 @@ func getIngressResourceName() string {
func TestListIngress(t *testing.T) {
ns := api.NamespaceAll
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Response: simple.Response{StatusCode: 200,
Body: &extensions.IngressList{
Items: []extensions.Ingress{
{
@ -61,13 +66,13 @@ func TestListIngress(t *testing.T) {
func TestGetIngress(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Ingress{
ObjectMeta: api.ObjectMeta{
@ -89,10 +94,10 @@ func TestGetIngress(t *testing.T) {
func TestGetIngressWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedIngress, err := c.Setup(t).Extensions().Ingress(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedIngress, err)
@ -107,13 +112,13 @@ func TestUpdateIngress(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Ingress{
ObjectMeta: api.ObjectMeta{
@ -150,13 +155,13 @@ func TestUpdateIngressStatus(t *testing.T) {
LoadBalancer: lbStatus,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo") + "/status",
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Ingress{
ObjectMeta: api.ObjectMeta{
@ -181,13 +186,13 @@ func TestUpdateIngressStatus(t *testing.T) {
func TestDeleteIngress(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "DELETE",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Extensions().Ingress(ns).Delete("foo", nil)
c.Validate(t, nil, err)
@ -201,14 +206,14 @@ func TestCreateIngress(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Extensions.ResourcePath(getIngressResourceName(), ns, ""),
Body: requestIngress,
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Ingress{
ObjectMeta: api.ObjectMeta{

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"testing"
@ -31,12 +36,12 @@ func getJobResourceName() string {
func TestListJobs(t *testing.T) {
ns := api.NamespaceAll
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Response: simple.Response{StatusCode: 200,
Body: &extensions.JobList{
Items: []extensions.Job{
{
@ -61,13 +66,13 @@ func TestListJobs(t *testing.T) {
func TestGetJob(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Job{
ObjectMeta: api.ObjectMeta{
@ -89,10 +94,10 @@ func TestGetJob(t *testing.T) {
func TestGetJobWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedJob, err := c.Setup(t).Extensions().Jobs(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedJob, err)
@ -107,13 +112,13 @@ func TestUpdateJob(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Job{
ObjectMeta: api.ObjectMeta{
@ -142,13 +147,13 @@ func TestUpdateJobStatus(t *testing.T) {
ResourceVersion: "1",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo") + "/status",
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Job{
ObjectMeta: api.ObjectMeta{
@ -173,13 +178,13 @@ func TestUpdateJobStatus(t *testing.T) {
func TestDeleteJob(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "DELETE",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, "foo"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Extensions().Jobs(ns).Delete("foo", nil)
c.Validate(t, nil, err)
@ -193,14 +198,14 @@ func TestCreateJob(t *testing.T) {
Namespace: ns,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Extensions.ResourcePath(getJobResourceName(), ns, ""),
Body: requestJob,
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: &extensions.Job{
ObjectMeta: api.ObjectMeta{

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -52,14 +57,14 @@ func TestLimitRangeCreate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: limitRange,
},
Response: Response{StatusCode: 200, Body: limitRange},
Response: simple.Response{StatusCode: 200, Body: limitRange},
}
response, err := c.Setup(t).LimitRanges(ns).Create(limitRange)
@ -88,14 +93,14 @@ func TestLimitRangeGet(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: limitRange},
Response: simple.Response{StatusCode: 200, Body: limitRange},
}
response, err := c.Setup(t).LimitRanges(ns).Get("abc")
@ -112,14 +117,14 @@ func TestLimitRangeList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: limitRangeList},
Response: simple.Response{StatusCode: 200, Body: limitRangeList},
}
response, err := c.Setup(t).LimitRanges(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -148,9 +153,9 @@ func TestLimitRangeUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: limitRange},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: limitRange},
}
response, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
c.Validate(t, response, err)
@ -178,9 +183,9 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: limitRange},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: limitRange},
}
_, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
if err == nil {
@ -190,21 +195,21 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
func TestLimitRangeDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).LimitRanges(ns).Delete("foo")
c.Validate(t, nil, err)
}
func TestLimitRangeWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", getLimitRangesResourceName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).LimitRanges(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -30,13 +35,13 @@ func TestNamespaceCreate(t *testing.T) {
namespace := &api.Namespace{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: namespace,
},
Response: Response{StatusCode: 200, Body: namespace},
Response: simple.Response{StatusCode: 200, Body: namespace},
}
// from the source ns, provision a new global namespace "foo"
@ -55,13 +60,13 @@ func TestNamespaceGet(t *testing.T) {
namespace := &api.Namespace{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("namespaces", "", "foo"),
Body: nil,
},
Response: Response{StatusCode: 200, Body: namespace},
Response: simple.Response{StatusCode: 200, Body: namespace},
}
response, err := c.Setup(t).Namespaces().Get("foo")
@ -83,13 +88,13 @@ func TestNamespaceList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: nil,
},
Response: Response{StatusCode: 200, Body: namespaceList},
Response: simple.Response{StatusCode: 200, Body: namespaceList},
}
response, err := c.Setup(t).Namespaces().List(unversioned.ListOptions{})
@ -121,11 +126,11 @@ func TestNamespaceUpdate(t *testing.T) {
Finalizers: []api.FinalizerName{api.FinalizerKubernetes},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
Response: Response{StatusCode: 200, Body: requestNamespace},
Response: simple.Response{StatusCode: 200, Body: requestNamespace},
}
receivedNamespace, err := c.Setup(t).Namespaces().Update(requestNamespace)
c.Validate(t, receivedNamespace, err)
@ -145,33 +150,33 @@ func TestNamespaceFinalize(t *testing.T) {
Finalizers: []api.FinalizerName{api.FinalizerKubernetes},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath("namespaces", "", "foo") + "/finalize",
},
Response: Response{StatusCode: 200, Body: requestNamespace},
Response: simple.Response{StatusCode: 200, Body: requestNamespace},
}
receivedNamespace, err := c.Setup(t).Namespaces().Finalize(requestNamespace)
c.Validate(t, receivedNamespace, err)
}
func TestNamespaceDelete(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Namespaces().Delete("foo")
c.Validate(t, nil, err)
}
func TestNamespaceWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", "namespaces", "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).Namespaces().Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -32,12 +37,12 @@ func getNodesResourceName() string {
}
func TestListNodes(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
},
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: unversioned.ListMeta{ResourceVersion: "1"}}},
Response: simple.Response{StatusCode: 200, Body: &api.NodeList{ListMeta: unversioned.ListMeta{ResourceVersion: "1"}}},
}
response, err := c.Setup(t).Nodes().List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -45,12 +50,12 @@ func TestListNodes(t *testing.T) {
func TestListNodesLabels(t *testing.T) {
labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String())
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
Query: simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: simple.Response{
StatusCode: 200,
Body: &api.NodeList{
Items: []api.Node{
@ -67,7 +72,7 @@ func TestListNodesLabels(t *testing.T) {
},
}
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
options := unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{selector}}
receivedNodeList, err := c.Nodes().List(options)
@ -75,22 +80,22 @@ func TestListNodesLabels(t *testing.T) {
}
func TestGetNode(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "1"),
},
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "node-1"}}},
Response: simple.Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "node-1"}}},
}
response, err := c.Setup(t).Nodes().Get("1")
c.Validate(t, response, err)
}
func TestGetNodeWithNoName(t *testing.T) {
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedNode, err := c.Setup(t).Nodes().Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedNode, err)
@ -111,12 +116,12 @@ func TestCreateNode(t *testing.T) {
Unschedulable: false,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Body: requestNode},
Response: Response{
Response: simple.Response{
StatusCode: 200,
Body: requestNode,
},
@ -126,12 +131,12 @@ func TestCreateNode(t *testing.T) {
}
func TestDeleteNode(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "DELETE",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Nodes().Delete("foo")
c.Validate(t, nil, err)
@ -153,12 +158,12 @@ func TestUpdateNode(t *testing.T) {
Unschedulable: true,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
},
Response: Response{StatusCode: 200, Body: requestNode},
Response: simple.Response{StatusCode: 200, Body: requestNode},
}
response, err := c.Setup(t).Nodes().Update(requestNode)
c.Validate(t, response, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -45,14 +50,14 @@ func TestPersistentVolumeCreate(t *testing.T) {
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: pv,
},
Response: Response{StatusCode: 200, Body: pv},
Response: simple.Response{StatusCode: 200, Body: pv},
}
response, err := c.Setup(t).PersistentVolumes().Create(pv)
@ -74,14 +79,14 @@ func TestPersistentVolumeGet(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolume},
Response: simple.Response{StatusCode: 200, Body: persistentVolume},
}
response, err := c.Setup(t).PersistentVolumes().Get("abc")
@ -96,14 +101,14 @@ func TestPersistentVolumeList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolumeList},
Response: simple.Response{StatusCode: 200, Body: persistentVolumeList},
}
response, err := c.Setup(t).PersistentVolumes().List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -124,9 +129,9 @@ func TestPersistentVolumeUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolume},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: persistentVolume},
}
response, err := c.Setup(t).PersistentVolumes().Update(persistentVolume)
c.Validate(t, response, err)
@ -151,33 +156,33 @@ func TestPersistentVolumeStatusUpdate(t *testing.T) {
Message: "foo",
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolume},
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: persistentVolume},
}
response, err := c.Setup(t).PersistentVolumes().UpdateStatus(persistentVolume)
c.Validate(t, response, err)
}
func TestPersistentVolumeDelete(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).PersistentVolumes().Delete("foo")
c.Validate(t, nil, err)
}
func TestPersistentVolumeWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).PersistentVolumes().Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -49,14 +54,14 @@ func TestPersistentVolumeClaimCreate(t *testing.T) {
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: pv,
},
Response: Response{StatusCode: 200, Body: pv},
Response: simple.Response{StatusCode: 200, Body: pv},
}
response, err := c.Setup(t).PersistentVolumeClaims(ns).Create(pv)
@ -82,14 +87,14 @@ func TestPersistentVolumeClaimGet(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
Response: simple.Response{StatusCode: 200, Body: persistentVolumeClaim},
}
response, err := c.Setup(t).PersistentVolumeClaims(ns).Get("abc")
@ -105,14 +110,14 @@ func TestPersistentVolumeClaimList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: persistentVolumeList},
Response: simple.Response{StatusCode: 200, Body: persistentVolumeList},
}
response, err := c.Setup(t).PersistentVolumeClaims(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -137,9 +142,9 @@ func TestPersistentVolumeClaimUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: persistentVolumeClaim},
}
response, err := c.Setup(t).PersistentVolumeClaims(ns).Update(persistentVolumeClaim)
c.Validate(t, response, err)
@ -167,12 +172,12 @@ func TestPersistentVolumeClaimStatusUpdate(t *testing.T) {
Phase: api.ClaimBound,
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: persistentVolumeClaim},
}
response, err := c.Setup(t).PersistentVolumeClaims(ns).UpdateStatus(persistentVolumeClaim)
c.Validate(t, response, err)
@ -180,21 +185,21 @@ func TestPersistentVolumeClaimStatusUpdate(t *testing.T) {
func TestPersistentVolumeClaimDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).PersistentVolumeClaims(ns).Delete("foo")
c.Validate(t, nil, err)
}
func TestPersistentVolumeClaimWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumeClaimsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).PersistentVolumeClaims(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -38,14 +43,14 @@ func TestPodTemplateCreate(t *testing.T) {
},
Template: api.PodTemplateSpec{},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: &podTemplate,
},
Response: Response{StatusCode: 200, Body: &podTemplate},
Response: simple.Response{StatusCode: 200, Body: &podTemplate},
}
response, err := c.Setup(t).PodTemplates(ns).Create(&podTemplate)
@ -61,14 +66,14 @@ func TestPodTemplateGet(t *testing.T) {
},
Template: api.PodTemplateSpec{},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: podTemplate},
Response: simple.Response{StatusCode: 200, Body: podTemplate},
}
response, err := c.Setup(t).PodTemplates(ns).Get("abc")
@ -87,14 +92,14 @@ func TestPodTemplateList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: podTemplateList},
Response: simple.Response{StatusCode: 200, Body: podTemplateList},
}
response, err := c.Setup(t).PodTemplates(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -110,9 +115,9 @@ func TestPodTemplateUpdate(t *testing.T) {
},
Template: api.PodTemplateSpec{},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: podTemplate},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: podTemplate},
}
response, err := c.Setup(t).PodTemplates(ns).Update(podTemplate)
c.Validate(t, response, err)
@ -120,21 +125,21 @@ func TestPodTemplateUpdate(t *testing.T) {
func TestPodTemplateDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).PodTemplates(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
func TestPodTemplateWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", getPodTemplatesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).PodTemplates(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import . "k8s.io/kubernetes/pkg/client/unversioned"
import (
"net/http"
@ -24,14 +26,15 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
"k8s.io/kubernetes/pkg/labels"
)
func TestListEmptyPods(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: http.StatusOK, Body: &api.PodList{}},
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: http.StatusOK, Body: &api.PodList{}},
}
podList, err := c.Setup(t).Pods(ns).List(unversioned.ListOptions{})
c.Validate(t, podList, err)
@ -39,9 +42,9 @@ func TestListEmptyPods(t *testing.T) {
func TestListPods(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: http.StatusOK,
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: http.StatusOK,
Body: &api.PodList{
Items: []api.Pod{
{
@ -66,12 +69,12 @@ func TestListPods(t *testing.T) {
func TestListPodsLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String())
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("pods", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
Query: simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: simple.Response{
StatusCode: http.StatusOK,
Body: &api.PodList{
Items: []api.Pod{
@ -91,7 +94,7 @@ func TestListPodsLabels(t *testing.T) {
},
}
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
options := unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{selector}}
receivedPodList, err := c.Pods(ns).List(options)
@ -100,9 +103,9 @@ func TestListPodsLabels(t *testing.T) {
func TestGetPod(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: http.StatusOK,
Body: &api.Pod{
Status: api.PodStatus{
@ -123,10 +126,10 @@ func TestGetPod(t *testing.T) {
func TestGetPodWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedPod, err := c.Setup(t).Pods(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedPod, err)
@ -134,9 +137,9 @@ func TestGetPodWithNoName(t *testing.T) {
func TestDeletePod(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: http.StatusOK},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: http.StatusOK},
}
err := c.Setup(t).Pods(ns).Delete("foo", nil)
c.Validate(t, nil, err)
@ -155,9 +158,9 @@ func TestCreatePod(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: simple.BuildQueryValues(nil), Body: requestPod},
Response: simple.Response{
StatusCode: http.StatusOK,
Body: requestPod,
},
@ -181,9 +184,9 @@ func TestUpdatePod(t *testing.T) {
Phase: api.PodRunning,
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: http.StatusOK, Body: requestPod},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: http.StatusOK, Body: requestPod},
}
receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
c.Validate(t, receivedPod, err)
@ -195,8 +198,8 @@ func TestPodGetLogs(t *testing.T) {
Follow: true,
Timestamps: true,
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("pods", ns, "podName") + "/log",
Query: url.Values{
@ -204,7 +207,7 @@ func TestPodGetLogs(t *testing.T) {
"timestamps": []string{"true"},
},
},
Response: Response{StatusCode: http.StatusOK},
Response: simple.Response{StatusCode: http.StatusOK},
}
body, err := c.Setup(t).Pods(ns).GetLogs("podName", opts).Stream()

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"testing"
@ -30,12 +35,12 @@ func getRCResourceName() string {
func TestListControllers(t *testing.T) {
ns := api.NamespaceAll
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Response: simple.Response{StatusCode: 200,
Body: &api.ReplicationControllerList{
Items: []api.ReplicationController{
{
@ -62,9 +67,9 @@ func TestListControllers(t *testing.T) {
func TestGetController(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "GET", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
@ -87,10 +92,10 @@ func TestGetController(t *testing.T) {
func TestGetControllerWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedPod, err := c.Setup(t).ReplicationControllers(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedPod, err)
@ -101,9 +106,9 @@ func TestUpdateController(t *testing.T) {
requestController := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
@ -129,9 +134,9 @@ func TestUpdateStatusController(t *testing.T) {
requestController := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo") + "/status", Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo") + "/status", Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
@ -156,9 +161,9 @@ func TestUpdateStatusController(t *testing.T) {
}
func TestDeleteController(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).ReplicationControllers(ns).Delete("foo")
c.Validate(t, nil, err)
@ -169,9 +174,9 @@ func TestCreateController(t *testing.T) {
requestController := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)},
Response: Response{
c := &simple.Client{
Request: simple.Request{Method: "POST", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: simple.BuildQueryValues(nil)},
Response: simple.Response{
StatusCode: 200,
Body: &api.ReplicationController{
ObjectMeta: api.ObjectMeta{

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -48,14 +53,14 @@ func TestResourceQuotaCreate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: resourceQuota,
},
Response: Response{StatusCode: 200, Body: resourceQuota},
Response: simple.Response{StatusCode: 200, Body: resourceQuota},
}
response, err := c.Setup(t).ResourceQuotas(ns).Create(resourceQuota)
@ -80,14 +85,14 @@ func TestResourceQuotaGet(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: resourceQuota},
Response: simple.Response{StatusCode: 200, Body: resourceQuota},
}
response, err := c.Setup(t).ResourceQuotas(ns).Get("abc")
@ -104,14 +109,14 @@ func TestResourceQuotaList(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil),
Query: simple.BuildQueryValues(nil),
Body: nil,
},
Response: Response{StatusCode: 200, Body: resourceQuotaList},
Response: simple.Response{StatusCode: 200, Body: resourceQuotaList},
}
response, err := c.Setup(t).ResourceQuotas(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
@ -136,9 +141,9 @@ func TestResourceQuotaUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: resourceQuota},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: resourceQuota},
}
response, err := c.Setup(t).ResourceQuotas(ns).Update(resourceQuota)
c.Validate(t, response, err)
@ -163,12 +168,12 @@ func TestResourceQuotaStatusUpdate(t *testing.T) {
},
},
}
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "PUT",
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: resourceQuota},
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: resourceQuota},
}
response, err := c.Setup(t).ResourceQuotas(ns).UpdateStatus(resourceQuota)
c.Validate(t, response, err)
@ -176,21 +181,21 @@ func TestResourceQuotaStatusUpdate(t *testing.T) {
func TestResourceQuotaDelete(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).ResourceQuotas(ns).Delete("foo")
c.Validate(t, nil, err)
}
func TestResourceQuotaWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("watch", getResourceQuotasResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
Response: simple.Response{StatusCode: 200},
}
_, err := c.Setup(t).ResourceQuotas(api.NamespaceAll).Watch(unversioned.ListOptions{})
c.Validate(t, nil, err)

View File

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package unversioned
package unversioned_test
import (
. "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
)
import (
"net/url"
@ -28,12 +33,12 @@ import (
func TestListServices(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200,
Body: &api.ServiceList{
Items: []api.Service{
{
@ -62,12 +67,12 @@ func TestListServices(t *testing.T) {
func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String())
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{StatusCode: 200,
Query: simple.BuildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: simple.Response{StatusCode: 200,
Body: &api.ServiceList{
Items: []api.Service{
{
@ -89,7 +94,7 @@ func TestListServicesLabels(t *testing.T) {
},
}
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
c.QueryValidator[labelSelectorQueryParamName] = simple.ValidateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
options := unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{selector}}
receivedServiceList, err := c.Services(ns).List(options)
@ -98,12 +103,12 @@ func TestListServicesLabels(t *testing.T) {
func TestGetService(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePath("services", ns, "1"),
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
}
response, err := c.Setup(t).Services(ns).Get("1")
c.Validate(t, response, err)
@ -111,10 +116,10 @@ func TestGetService(t *testing.T) {
func TestGetServiceWithNoName(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{Error: true}
c := &simple.Client{Error: true}
receivedPod, err := c.Setup(t).Services(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
if (err != nil) && (err.Error() != simple.NameRequiredError) {
t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
}
c.Validate(t, receivedPod, err)
@ -122,13 +127,13 @@ func TestGetServiceWithNoName(t *testing.T) {
func TestCreateService(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "POST",
Path: testapi.Default.ResourcePath("services", ns, ""),
Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}},
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
}
response, err := c.Setup(t).Services(ns).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
c.Validate(t, response, err)
@ -137,9 +142,9 @@ func TestCreateService(t *testing.T) {
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.Default.ResourcePath("services", ns, "service-1"), Body: svc, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: svc},
c := &simple.Client{
Request: simple.Request{Method: "PUT", Path: testapi.Default.ResourcePath("services", ns, "service-1"), Body: svc, Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200, Body: svc},
}
response, err := c.Setup(t).Services(ns).Update(svc)
c.Validate(t, response, err)
@ -147,9 +152,9 @@ func TestUpdateService(t *testing.T) {
func TestDeleteService(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("services", ns, "1"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
c := &simple.Client{
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath("services", ns, "1"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: 200},
}
err := c.Setup(t).Services(ns).Delete("1")
c.Validate(t, nil, err)
@ -158,25 +163,25 @@ func TestDeleteService(t *testing.T) {
func TestServiceProxyGet(t *testing.T) {
body := "OK"
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{
c := &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("proxy", "services", ns, "service-1") + "/foo",
Query: buildQueryValues(url.Values{"param-name": []string{"param-value"}}),
Query: simple.BuildQueryValues(url.Values{"param-name": []string{"param-value"}}),
},
Response: Response{StatusCode: 200, RawBody: &body},
Response: simple.Response{StatusCode: 200, RawBody: &body},
}
response, err := c.Setup(t).Services(ns).ProxyGet("", "service-1", "", "foo", map[string]string{"param-name": "param-value"}).DoRaw()
c.ValidateRaw(t, response, err)
// With scheme and port specified
c = &testClient{
Request: testRequest{
c = &simple.Client{
Request: simple.Request{
Method: "GET",
Path: testapi.Default.ResourcePathWithPrefix("proxy", "services", ns, "https:service-1:my-port") + "/foo",
Query: buildQueryValues(url.Values{"param-name": []string{"param-value"}}),
Query: simple.BuildQueryValues(url.Values{"param-name": []string{"param-value"}}),
},
Response: Response{StatusCode: 200, RawBody: &body},
Response: simple.Response{StatusCode: 200, RawBody: &body},
}
response, err = c.Setup(t).Services(ns).ProxyGet("https", "service-1", "my-port", "foo", map[string]string{"param-name": "param-value"}).DoRaw()
c.ValidateRaw(t, response, err)

View File

@ -0,0 +1,224 @@
/*
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.
*/
package simple
import (
"net/http/httptest"
"net/url"
"path"
"reflect"
"strings"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
)
const NameRequiredError = "resource name may not be empty"
type Request struct {
Method string
Path string
Header string
Query url.Values
Body runtime.Object
RawBody *string
}
type Response struct {
StatusCode int
Body runtime.Object
RawBody *string
}
type Client struct {
*client.Client
Request Request
Response Response
Error bool
Created bool
server *httptest.Server
handler *util.FakeHandler
// For query args, an optional function to validate the contents
// useful when the contents can change but still be correct.
// Maps from query arg key to validator.
// If no validator is present, string equality is used.
QueryValidator map[string]func(string, string) bool
}
func (c *Client) Setup(t *testing.T) *Client {
c.handler = &util.FakeHandler{
StatusCode: c.Response.StatusCode,
}
if responseBody := body(t, c.Response.Body, c.Response.RawBody); responseBody != nil {
c.handler.ResponseBody = *responseBody
}
c.server = httptest.NewServer(c.handler)
if c.Client == nil {
c.Client = client.NewOrDie(&client.Config{
Host: c.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
})
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
c.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{
Host: c.server.URL,
GroupVersion: testapi.Extensions.GroupVersion(),
})
}
c.QueryValidator = map[string]func(string, string) bool{}
return c
}
func (c *Client) Validate(t *testing.T, received runtime.Object, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !api.Semantic.DeepDerivative(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
}
}
func (c *Client) ValidateRaw(t *testing.T, received []byte, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
}
}
func (c *Client) ValidateCommon(t *testing.T, err error) {
defer c.server.Close()
if c.Error {
if err == nil {
t.Errorf("error expected for %#v, got none", c.Request)
}
return
}
if err != nil {
t.Errorf("no error expected for %#v, got: %v", c.Request, err)
}
if c.handler.RequestReceived == nil {
t.Errorf("handler had an empty request, %#v", c)
return
}
requestBody := body(t, c.Request.Body, c.Request.RawBody)
actualQuery := c.handler.RequestReceived.URL.Query()
t.Logf("got query: %v", actualQuery)
t.Logf("path: %v", c.Request.Path)
// 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(c.Request.Path), c.Request.Method, requestBody)
for key, values := range c.Request.Query {
validator, ok := c.QueryValidator[key]
if !ok {
switch key {
case unversioned.LabelSelectorQueryParam(testapi.Default.GroupVersion().String()):
validator = ValidateLabels
case unversioned.FieldSelectorQueryParam(testapi.Default.GroupVersion().String()):
validator = validateFields
default:
validator = func(a, b string) bool { return a == b }
}
}
observed := actualQuery.Get(key)
wanted := strings.Join(values, "")
if !validator(wanted, observed) {
t.Errorf("Unexpected query arg for key: %s. Expected %s, Received %s", key, wanted, observed)
}
}
if c.Request.Header != "" {
if c.handler.RequestReceived.Header.Get(c.Request.Header) == "" {
t.Errorf("header %q not found in request %#v", c.Request.Header, c.handler.RequestReceived)
}
}
if expected, received := requestBody, c.handler.RequestBody; expected != nil && *expected != received {
t.Errorf("bad body for request %#v: expected %s, got %s", c.Request, *expected, received)
}
}
// buildQueryValues is a convenience function for knowing if a namespace should be in a query param or not
func BuildQueryValues(query url.Values) url.Values {
v := url.Values{}
if query != nil {
for key, values := range query {
for _, value := range values {
v.Add(key, value)
}
}
}
return v
}
func ValidateLabels(a, b string) bool {
sA, eA := labels.Parse(a)
if eA != nil {
return false
}
sB, eB := labels.Parse(b)
if eB != nil {
return false
}
return sA.String() == sB.String()
}
func validateFields(a, b string) bool {
sA, _ := fields.ParseSelector(a)
sB, _ := fields.ParseSelector(b)
return sA.String() == sB.String()
}
func body(t *testing.T, obj runtime.Object, raw *string) *string {
if obj != nil {
fqKind, err := api.Scheme.ObjectKind(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
var bs []byte
if api.Scheme.Recognizes(testapi.Default.GroupVersion().WithKind(fqKind.Kind)) {
bs, err = testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else if api.Scheme.Recognizes(testapi.Extensions.GroupVersion().WithKind(fqKind.Kind)) {
bs, err = testapi.Extensions.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else {
t.Errorf("unexpected kind: %v", fqKind.Kind)
}
body := string(bs)
return &body
}
return raw
}