Skip to content

Commit

Permalink
Merge pull request kubernetes#19685 from resouer/testing
Browse files Browse the repository at this point in the history
Replace fake handler using testing pkg
  • Loading branch information
mikedanese committed Jan 16, 2016
2 parents abf81b6 + 98222b4 commit 936c8cd
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 37 deletions.
6 changes: 3 additions & 3 deletions pkg/client/cache/listwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

func parseSelectorOrDie(s string) fields.Selector {
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestListWatchesCanList(t *testing.T) {
},
}
for _, item := range table {
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestListWatchesCanWatch(t *testing.T) {
}

for _, item := range table {
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand Down
11 changes: 6 additions & 5 deletions pkg/client/unversioned/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/httpstream"
"k8s.io/kubernetes/pkg/util/intstr"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
"k8s.io/kubernetes/pkg/watch"
watchjson "k8s.io/kubernetes/pkg/watch/json"
)
Expand Down Expand Up @@ -698,7 +699,7 @@ func TestDoRequestNewWay(t *testing.T) {
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -867,7 +868,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -908,7 +909,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -964,7 +965,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -1010,7 +1011,7 @@ func TestWasCreated(t *testing.T) {
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 201,
ResponseBody: string(expectedBody),
T: t,
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/unversioned/restclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

func TestDoRequestSuccess(t *testing.T) {
status := &unversioned.Status{Status: unversioned.StatusSuccess}
expectedBody, _ := testapi.Default.Codec().Encode(status)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestDoRequestFailed(t *testing.T) {
Details: &unversioned.StatusDetails{},
}
expectedBody, _ := testapi.Default.Codec().Encode(status)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 404,
ResponseBody: string(expectedBody),
T: t,
Expand Down Expand Up @@ -111,7 +112,7 @@ func TestDoRequestFailed(t *testing.T) {
func TestDoRequestCreated(t *testing.T) {
status := &unversioned.Status{Status: unversioned.StatusSuccess}
expectedBody, _ := testapi.Default.Codec().Encode(status)
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 201,
ResponseBody: string(expectedBody),
T: t,
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/unversioned/testclient/simple/simple_testclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

const NameRequiredError = "resource name may not be empty"
Expand All @@ -58,7 +58,7 @@ type Client struct {
Error bool
Created bool
server *httptest.Server
handler *util.FakeHandler
handler *utiltesting.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.
Expand All @@ -67,7 +67,7 @@ type Client struct {
}

func (c *Client) Setup(t *testing.T) *Client {
c.handler = &util.FakeHandler{
c.handler = &utiltesting.FakeHandler{
StatusCode: c.Response.StatusCode,
}
if responseBody := body(t, c.Response.Body, c.Response.RawBody); responseBody != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/controller_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

// NewFakeControllerExpectationsLookup creates a fake store for PodExpectations.
Expand Down Expand Up @@ -184,7 +185,7 @@ func TestControllerExpectations(t *testing.T) {
func TestCreatePods(t *testing.T) {
ns := api.NamespaceDefault
body := runtime.EncodeOrDie(testapi.Default.Codec(), &api.Pod{ObjectMeta: api.ObjectMeta{Name: "empty_pod"}})
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/endpoint/endpoints_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

func addPods(store cache.Store, namespace string, nPods int, nPorts int, nNotReady int) {
Expand Down Expand Up @@ -73,8 +73,8 @@ type serverResponse struct {
obj interface{}
}

func makeTestServer(t *testing.T, namespace string, endpointsResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
fakeEndpointsHandler := util.FakeHandler{
func makeTestServer(t *testing.T, namespace string, endpointsResponse serverResponse) (*httptest.Server, *utiltesting.FakeHandler) {
fakeEndpointsHandler := utiltesting.FakeHandler{
StatusCode: endpointsResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Default.Codec(), endpointsResponse.obj.(runtime.Object)),
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/controller/replication/replication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
"k8s.io/kubernetes/pkg/watch"
)

Expand Down Expand Up @@ -210,7 +211,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {

func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
// Setup a fake server to listen for requests, and run the rc manager in steady state
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: "",
}
Expand Down Expand Up @@ -252,7 +253,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {

func TestControllerUpdateReplicas(t *testing.T) {
// This is a happy server just to record the PUT request we expect for status.Replicas
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: "",
}
Expand Down Expand Up @@ -292,7 +293,7 @@ func TestControllerUpdateReplicas(t *testing.T) {

func TestSyncReplicationControllerDormancy(t *testing.T) {
// Setup a test server so we can lie about the current state of pods
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: "",
}
Expand Down Expand Up @@ -552,7 +553,7 @@ func TestUpdatePods(t *testing.T) {

func TestControllerUpdateRequeue(t *testing.T) {
// This server should force a requeue of the controller because it fails to update status.Replicas.
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/client/kubelet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/probe"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

func TestHTTPKubeletClient(t *testing.T) {
Expand All @@ -34,7 +34,7 @@ func TestHTTPKubeletClient(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}

fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/config/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"k8s.io/kubernetes/pkg/api/validation"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
)

func TestURLErrorNotExistNoUpdate(t *testing.T) {
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestExtractInvalidPods(t *testing.T) {
if err != nil {
t.Fatalf("%s: Some weird json problem: %v", testCase.desc, err)
}
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(data),
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
if err != nil {
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
}
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(data),
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestURLWithHeader(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected json marshalling error: %v", err)
}
fakeHandler := util.FakeHandler{
fakeHandler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: string(data),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package testing

import (
"io/ioutil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package testing

import (
"bytes"
Expand Down
14 changes: 7 additions & 7 deletions plugin/pkg/scheduler/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
utiltesting "k8s.io/kubernetes/pkg/util/testing"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
latestschedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api/latest"
)

func TestCreate(t *testing.T) {
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand All @@ -56,7 +56,7 @@ func TestCreateFromConfig(t *testing.T) {
var configData []byte
var policy schedulerapi.Policy

handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestCreateFromEmptyConfig(t *testing.T) {
var configData []byte
var policy schedulerapi.Policy

handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestDefaultErrorFunc(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: apitesting.DeepEqualSafePodSpec(),
}
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: runtime.EncodeOrDie(testapi.Default.Codec(), testPod),
T: t,
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestBind(t *testing.T) {
}

for _, item := range table {
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 200,
ResponseBody: "",
T: t,
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestBackoff(t *testing.T) {
// is of name "foo-scheduler". A pod must be picked up by at most one of the two
// schedulers.
func TestResponsibleForPod(t *testing.T) {
handler := util.FakeHandler{
handler := utiltesting.FakeHandler{
StatusCode: 500,
ResponseBody: "",
T: t,
Expand Down

0 comments on commit 936c8cd

Please sign in to comment.