published by bot

(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d9467519245c3858ac58c5fa91ec9e5b16c1f507
This commit is contained in:
Kubernetes Publisher
2017-01-18 15:19:42 +00:00
parent 0e140df9af
commit 8fa0506b26
167 changed files with 8232 additions and 5860 deletions

View File

@@ -18,6 +18,7 @@ package rest
import (
"bytes"
"context"
"errors"
"fmt"
"io"
@@ -33,6 +34,7 @@ import (
"testing"
"time"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
@@ -41,7 +43,6 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api"
apierrors "k8s.io/client-go/pkg/api/errors"
"k8s.io/client-go/pkg/api/testapi"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/util/clock"
@@ -1217,7 +1218,7 @@ func BenchmarkCheckRetryClosesBody(b *testing.B) {
}
func TestDoRequestNewWayReader(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
reqBodyExpected, _ := runtime.Encode(testapi.Default.Codec(), reqObj)
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
@@ -1257,7 +1258,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
}
func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
reqBodyExpected, _ := runtime.Encode(testapi.Default.Codec(), reqObj)
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
@@ -1297,7 +1298,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
}
func TestDoRequestNewWayFile(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
reqBodyExpected, err := runtime.Encode(testapi.Default.Codec(), reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -1354,7 +1355,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
}
func TestWasCreated(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
reqBodyExpected, err := runtime.Encode(testapi.Default.Codec(), reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -1491,7 +1492,7 @@ func TestUnacceptableParamNames(t *testing.T) {
func TestBody(t *testing.T) {
const data = "test payload"
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
obj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
bodyExpected, _ := runtime.Encode(testapi.Default.Codec(), obj)
f, err := ioutil.TempFile("", "test_body")
@@ -1555,9 +1556,9 @@ func TestWatch(t *testing.T) {
t watch.EventType
obj runtime.Object
}{
{watch.Added, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "first"}}},
{watch.Modified, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "second"}}},
{watch.Deleted, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "last"}}},
{watch.Added, &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "first"}}},
{watch.Modified, &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "second"}}},
{watch.Deleted, &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "last"}}},
}
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -1651,3 +1652,32 @@ func testRESTClient(t testing.TB, srv *httptest.Server) *RESTClient {
}
return client
}
func TestDoContext(t *testing.T) {
receivedCh := make(chan struct{})
block := make(chan struct{})
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
close(receivedCh)
<-block
w.WriteHeader(http.StatusOK)
}))
defer testServer.Close()
defer close(block)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
<-receivedCh
cancel()
}()
c := testRESTClient(t, testServer)
_, err := c.Verb("GET").
Context(ctx).
Prefix("foo").
DoRaw()
if err == nil {
t.Fatal("Expected context cancellation error")
}
}