move client/unversioned/fake.go to its own package

This commit is contained in:
Chao Xu 2015-09-11 13:47:53 -07:00
parent fbde485548
commit ac5481d089
21 changed files with 320 additions and 284 deletions

View File

@ -1,69 +0,0 @@
/*
Copyright 2014 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 unversioned
import (
"net/http"
"net/url"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/runtime"
)
type HTTPClientFunc func(*http.Request) (*http.Response, error)
func (f HTTPClientFunc) Do(req *http.Request) (*http.Response, error) {
return f(req)
}
// FakeRESTClient provides a fake RESTClient interface.
type FakeRESTClient struct {
Client HTTPClient
Codec runtime.Codec
Req *http.Request
Resp *http.Response
Err error
}
func (c *FakeRESTClient) Get() *Request {
return NewRequest(c, "GET", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *FakeRESTClient) Put() *Request {
return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *FakeRESTClient) Patch(_ api.PatchType) *Request {
return NewRequest(c, "PATCH", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *FakeRESTClient) Post() *Request {
return NewRequest(c, "POST", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *FakeRESTClient) Delete() *Request {
return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) {
c.Req = req
if c.Client != HTTPClient(nil) {
return c.Client.Do(req)
}
return c.Resp, c.Err
}

View File

@ -0,0 +1,70 @@
/*
Copyright 2014 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 fake
import (
"net/http"
"net/url"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
)
type HTTPClientFunc func(*http.Request) (*http.Response, error)
func (f HTTPClientFunc) Do(req *http.Request) (*http.Response, error) {
return f(req)
}
// RESTClient provides a fake RESTClient interface.
type RESTClient struct {
Client unversioned.HTTPClient
Codec runtime.Codec
Req *http.Request
Resp *http.Response
Err error
}
func (c *RESTClient) Get() *unversioned.Request {
return unversioned.NewRequest(c, "GET", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *RESTClient) Put() *unversioned.Request {
return unversioned.NewRequest(c, "PUT", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *RESTClient) Patch(_ api.PatchType) *unversioned.Request {
return unversioned.NewRequest(c, "PATCH", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *RESTClient) Post() *unversioned.Request {
return unversioned.NewRequest(c, "POST", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *RESTClient) Delete() *unversioned.Request {
return unversioned.NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
}
func (c *RESTClient) Do(req *http.Request) (*http.Response, error) {
c.Req = req
if c.Client != unversioned.HTTPClient(nil) {
return c.Client.Do(req)
}
return c.Resp, c.Err
}

View File

@ -0,0 +1,112 @@
/*
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 unversioned_test
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
func objBody(object interface{}) io.ReadCloser {
output, err := json.MarshalIndent(object, "", "")
if err != nil {
panic(err)
}
return ioutil.NopCloser(bytes.NewReader([]byte(output)))
}
func TestNegotiateVersion(t *testing.T) {
tests := []struct {
name, version, expectedVersion string
serverVersions []string
clientVersions []string
config *unversioned.Config
expectErr bool
}{
{
name: "server supports client default",
version: "version1",
config: &unversioned.Config{},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "server falls back to client supported",
version: testapi.Default.Version(),
config: &unversioned.Config{},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "explicit version supported",
version: "",
config: &unversioned.Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: testapi.Default.Version(),
expectErr: false,
},
{
name: "explicit version not supported",
version: "",
config: &unversioned.Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "",
expectErr: true,
},
}
codec := testapi.Default.Codec()
for _, test := range tests {
fakeClient := &fake.RESTClient{
Codec: codec,
Resp: &http.Response{
StatusCode: 200,
Body: objBody(&api.APIVersions{Versions: test.serverVersions}),
},
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: objBody(&api.APIVersions{Versions: test.serverVersions})}, nil
}),
}
c := unversioned.NewOrDie(test.config)
c.Client = fakeClient.Client
response, err := unversioned.NegotiateVersion(c, test.config, test.version, test.clientVersions)
if err == nil && test.expectErr {
t.Errorf("expected error, got nil for [%s].", test.name)
}
if err != nil && !test.expectErr {
t.Errorf("unexpected error for [%s]: %v.", test.name, err)
}
if response != test.expectedVersion {
t.Errorf("expected version %s, got %s.", test.expectedVersion, response)
}
}
}

View File

@ -17,16 +17,11 @@ limitations under the License.
package unversioned
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"reflect"
"strings"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
)
@ -379,84 +374,3 @@ func TestSetKubernetesDefaultsUserAgent(t *testing.T) {
t.Errorf("no user agent set: %#v", config)
}
}
func objBody(object interface{}) io.ReadCloser {
output, err := json.MarshalIndent(object, "", "")
if err != nil {
panic(err)
}
return ioutil.NopCloser(bytes.NewReader([]byte(output)))
}
func TestNegotiateVersion(t *testing.T) {
tests := []struct {
name, version, expectedVersion string
serverVersions []string
clientVersions []string
config *Config
expectErr bool
}{
{
name: "server supports client default",
version: "version1",
config: &Config{},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "server falls back to client supported",
version: testapi.Default.Version(),
config: &Config{},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "explicit version supported",
version: "",
config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: testapi.Default.Version(),
expectErr: false,
},
{
name: "explicit version not supported",
version: "",
config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "",
expectErr: true,
},
}
codec := testapi.Default.Codec()
for _, test := range tests {
fakeClient := &FakeRESTClient{
Codec: codec,
Resp: &http.Response{
StatusCode: 200,
Body: objBody(&api.APIVersions{Versions: test.serverVersions}),
},
Client: HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: objBody(&api.APIVersions{Versions: test.serverVersions})}, nil
}),
}
c := NewOrDie(test.config)
c.Client = fakeClient.Client
response, err := NegotiateVersion(c, test.config, test.version, test.clientVersions)
if err == nil && test.expectErr {
t.Errorf("expected error, got nil for [%s].", test.name)
}
if err != nil && !test.expectErr {
t.Errorf("unexpected error for [%s]: %v.", test.name, err)
}
if response != test.expectedVersion {
t.Errorf("expected version %s, got %s.", test.expectedVersion, response)
}
}
}

View File

@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
)
@ -420,9 +421,9 @@ func TestAnnotateObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.Method {
case "GET":
switch req.URL.Path {
@ -467,9 +468,9 @@ func TestAnnotateObjectFromFile(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.Method {
case "GET":
switch req.URL.Path {
@ -515,9 +516,9 @@ func TestAnnotateMultipleObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.Method {
case "GET":
switch req.URL.Path {

View File

@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
type fakeRemoteAttach struct {
@ -76,9 +77,9 @@ func TestPodAndContainerAttach(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { return nil, nil }),
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { return nil, nil }),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{}
@ -129,9 +130,9 @@ func TestAttach(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)

View File

@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/validation"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
@ -200,7 +201,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
},
Client: func() (*client.Client, error) {
// Swap out the HTTP client out of the client with the fake's version.
fakeClient := t.Client.(*client.FakeRESTClient)
fakeClient := t.Client.(*fake.RESTClient)
c := client.NewOrDie(t.ClientConfig)
c.Client = fakeClient.Client
return c, t.Err
@ -261,7 +262,7 @@ func stringBody(body string) io.ReadCloser {
func ExamplePrintReplicationControllerWithNamespace() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, []string{})
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: nil,
}
@ -303,7 +304,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
func ExamplePrintPodWithWideFormat() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, false, []string{})
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: nil,
}
@ -430,7 +431,7 @@ func newAllPhasePodList() *api.PodList {
func ExamplePrintPodHideTerminated() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, []string{})
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: nil,
}
@ -450,7 +451,7 @@ func ExamplePrintPodHideTerminated() {
func ExamplePrintPodShowAll() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, true, []string{})
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: nil,
}
@ -472,7 +473,7 @@ func ExamplePrintPodShowAll() {
func ExamplePrintServiceWithNamespacesAndLabels() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, []string{"l1"})
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: nil,
}

View File

@ -22,7 +22,7 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
)
@ -42,9 +42,9 @@ func TestCreateObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers" && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &rc.Items[0])}, nil
@ -73,9 +73,9 @@ func TestCreateMultipleObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services" && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil
@ -108,9 +108,9 @@ func TestCreateDirectory(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services" && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil

View File

@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
func TestDeleteObjectByTuple(t *testing.T) {
@ -33,9 +33,9 @@ func TestDeleteObjectByTuple(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master-controller" && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -65,9 +65,9 @@ func TestDeleteNamedObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master-controller" && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -97,9 +97,9 @@ func TestDeleteObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -127,9 +127,9 @@ func TestDeleteObject(t *testing.T) {
func TestDeleteObjectNotFound(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 404, Body: stringBody("")}, nil
@ -157,9 +157,9 @@ func TestDeleteObjectNotFound(t *testing.T) {
func TestDeleteObjectIgnoreNotFound(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 404, Body: stringBody("")}, nil
@ -194,9 +194,9 @@ func TestDeleteAllNotFound(t *testing.T) {
notFoundError := &errors.NewNotFound("Service", "foo").(*errors.StatusError).ErrStatus
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services" && m == "GET":
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
@ -236,9 +236,9 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
notFoundError := &errors.NewNotFound("Service", "foo").(*errors.StatusError).ErrStatus
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services" && m == "GET":
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
@ -271,9 +271,9 @@ func TestDeleteMultipleObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -305,9 +305,9 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 404, Body: stringBody("")}, nil
@ -342,9 +342,9 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
_, svc, rc := testData()
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/baz" && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -378,9 +378,9 @@ func TestDeleteDirectory(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case strings.HasPrefix(p, "/namespaces/test/services/") && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil
@ -411,9 +411,9 @@ func TestDeleteMultipleSelector(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/pods" && m == "GET":
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {

View File

@ -22,7 +22,7 @@ import (
"net/http"
"testing"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
@ -30,7 +30,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
d := &testDescriber{Output: "test output"}
f, tf, codec := NewTestFactory()
tf.Describer = d
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &internalType{Name: "foo"})},
}
@ -54,9 +54,9 @@ func TestDescribeObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
d := &testDescriber{Output: "test output"}
tf.Describer = d
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "GET":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -87,7 +87,7 @@ func TestDescribeListObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
d := &testDescriber{Output: "test output"}
tf.Describer = d
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, pods)},
}

View File

@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
type fakeRemoteExecutor struct {
@ -97,9 +98,9 @@ func TestPodAndContainer(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { return nil, nil }),
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { return nil, nil }),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{}
@ -153,9 +154,9 @@ func TestExec(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)

View File

@ -23,7 +23,7 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
)
@ -213,9 +213,9 @@ func TestRunExposeService(t *testing.T) {
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.calls[m] && m == "GET":
return &http.Response{StatusCode: test.status, Body: objBody(codec, test.input)}, nil
@ -287,9 +287,9 @@ func TestRunExposeServiceFromFile(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.calls[m] && m == "GET":
return &http.Response{StatusCode: test.status, Body: objBody(codec, test.input)}, nil

View File

@ -30,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/watch"
@ -122,7 +123,7 @@ func testComponentStatusData() *api.ComponentStatusList {
func TestGetUnknownSchemaObject(t *testing.T) {
f, tf, codec := NewTestFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &internalType{Name: "foo"})},
}
@ -183,18 +184,18 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
}
for k, test := range testCases {
apiCodec := runtime.CodecFor(api.Scheme, testapi.Default.Version())
regularClient := &client.FakeRESTClient{
regularClient := &fake.RESTClient{
Codec: apiCodec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: objBody(apiCodec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})}, nil
}),
}
f, tf, codec := NewMixedFactory(regularClient)
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: objBody(codec, &internalType{Name: "foo"})}, nil
}),
}
@ -235,7 +236,7 @@ func TestGetSchemaObject(t *testing.T) {
tf.Typer = api.Scheme
codec := testapi.Default.Codec()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})},
}
@ -256,7 +257,7 @@ func TestGetObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])},
}
@ -282,7 +283,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])},
}
@ -309,7 +310,7 @@ func TestGetListObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, pods)},
}
@ -335,7 +336,7 @@ func TestGetAllListObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, pods)},
}
@ -362,7 +363,7 @@ func TestGetListComponentStatus(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, statuses)},
}
@ -388,9 +389,9 @@ func TestGetMultipleTypeObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods":
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
@ -424,9 +425,9 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods":
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
@ -484,9 +485,9 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
}
@ -533,9 +534,9 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/nodes/foo":
return &http.Response{StatusCode: 200, Body: objBody(codec, node)}, nil
@ -620,9 +621,9 @@ func TestWatchSelector(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
}
@ -662,9 +663,9 @@ func TestWatchResource(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/foo":
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods[0])}, nil
@ -700,9 +701,9 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/cassandra":
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods[0])}, nil
@ -739,9 +740,9 @@ func TestWatchOnlyResource(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/foo":
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods[0])}, nil

View File

@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
)
@ -326,9 +327,9 @@ func TestLabelErrors(t *testing.T) {
func TestLabelForResourceFromFile(t *testing.T) {
pods, _, _ := testData()
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.Method {
case "GET":
switch req.URL.Path {
@ -373,9 +374,9 @@ func TestLabelForResourceFromFile(t *testing.T) {
func TestLabelMultipleObjects(t *testing.T) {
pods, _, _ := testData()
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.Method {
case "GET":
switch req.URL.Path {

View File

@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
func TestSelectContainer(t *testing.T) {
@ -165,9 +166,9 @@ func TestLog(t *testing.T) {
for _, test := range tests {
logContent := "test log content"
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)

View File

@ -21,7 +21,7 @@ import (
"net/http"
"testing"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
func TestPatchObject(t *testing.T) {
@ -29,9 +29,9 @@ func TestPatchObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services/frontend" && (m == "PATCH" || m == "GET"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil
@ -61,9 +61,9 @@ func TestPatchObjectFromFile(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services/frontend" && (m == "PATCH" || m == "GET"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil

View File

@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
type fakePortForwarder struct {
@ -64,9 +65,9 @@ func TestPortForward(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)
@ -126,9 +127,9 @@ func TestPortForwardWithPFlag(t *testing.T) {
}
for _, test := range tests {
f, tf, codec := NewAPIFactory()
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)

View File

@ -22,7 +22,7 @@ import (
"strings"
"testing"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
)
func TestReplaceObject(t *testing.T) {
@ -30,9 +30,9 @@ func TestReplaceObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && (m == "GET" || m == "PUT" || m == "DELETE"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -73,9 +73,9 @@ func TestReplaceMultipleObject(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && (m == "GET" || m == "PUT" || m == "DELETE"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
@ -120,9 +120,9 @@ func TestReplaceDirectory(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case strings.HasPrefix(p, "/namespaces/test/services/") && (m == "GET" || m == "PUT" || m == "DELETE"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil
@ -167,9 +167,9 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
tf.Client = &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
return &http.Response{StatusCode: 404, Body: stringBody("")}, nil

View File

@ -32,7 +32,7 @@ import (
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/watch"
@ -54,15 +54,15 @@ func watchBody(events ...watch.Event) string {
func fakeClient() ClientMapper {
return ClientMapperFunc(func(*meta.RESTMapping) (RESTClient, error) {
return &client.FakeRESTClient{}, nil
return &fake.RESTClient{}, nil
})
}
func fakeClientWith(testName string, t *testing.T, data map[string]string) ClientMapper {
return ClientMapperFunc(func(*meta.RESTMapping) (RESTClient, error) {
return &client.FakeRESTClient{
return &fake.RESTClient{
Codec: testapi.Default.Codec(),
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
p := req.URL.Path
q := req.URL.RawQuery
if len(q) != 0 {

View File

@ -28,7 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
)
@ -92,7 +92,7 @@ func TestHelperDelete(t *testing.T) {
},
}
for _, test := range tests {
client := &client.FakeRESTClient{
client := &fake.RESTClient{
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
@ -131,7 +131,7 @@ func TestHelperCreate(t *testing.T) {
grace := int64(30)
tests := []struct {
Resp *http.Response
RespFunc client.HTTPClientFunc
RespFunc fake.HTTPClientFunc
HttpErr error
Modify bool
Object runtime.Object
@ -183,7 +183,7 @@ func TestHelperCreate(t *testing.T) {
},
}
for i, test := range tests {
client := &client.FakeRESTClient{
client := &fake.RESTClient{
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
@ -269,7 +269,7 @@ func TestHelperGet(t *testing.T) {
},
}
for _, test := range tests {
client := &client.FakeRESTClient{
client := &fake.RESTClient{
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
@ -340,7 +340,7 @@ func TestHelperList(t *testing.T) {
},
}
for _, test := range tests {
client := &client.FakeRESTClient{
client := &fake.RESTClient{
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
@ -386,7 +386,7 @@ func TestHelperReplace(t *testing.T) {
grace := int64(30)
tests := []struct {
Resp *http.Response
RespFunc client.HTTPClientFunc
RespFunc fake.HTTPClientFunc
HttpErr error
Overwrite bool
Object runtime.Object
@ -443,7 +443,7 @@ func TestHelperReplace(t *testing.T) {
},
}
for i, test := range tests {
client := &client.FakeRESTClient{
client := &fake.RESTClient{
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,

View File

@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
@ -1052,9 +1053,9 @@ func TestUpdateWithRetries(t *testing.T) {
{StatusCode: 500, Body: objBody(codec, &api.ReplicationController{})},
{StatusCode: 200, Body: objBody(codec, rc)},
}
fakeClient := &client.FakeRESTClient{
fakeClient := &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == testapi.Default.ResourcePath("replicationcontrollers", "default", "rc") && m == "PUT":
update := updates[0]
@ -1143,9 +1144,9 @@ func TestAddDeploymentHash(t *testing.T) {
seen := sets.String{}
updatedRc := false
fakeClient := &client.FakeRESTClient{
fakeClient := &fake.RESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
Client: fake.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == testapi.Default.ResourcePath("pods", "default", "") && m == "GET":
if req.URL.RawQuery != "labelSelector=foo%3Dbar" {