Switch from glide to govendor
This commit is contained in:
		
							
								
								
									
										28
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										28
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,28 +0,0 @@
 | 
			
		||||
// Copyright 2015 The Go Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed by a BSD-style
 | 
			
		||||
// license that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
// +build !plan9,go1.7
 | 
			
		||||
 | 
			
		||||
package ctxhttp
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/http/httptest"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"context"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestGo17Context(t *testing.T) {
 | 
			
		||||
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		io.WriteString(w, "ok")
 | 
			
		||||
	}))
 | 
			
		||||
	ctx := context.Background()
 | 
			
		||||
	resp, err := Get(ctx, http.DefaultClient, ts.URL)
 | 
			
		||||
	if resp == nil || err != nil {
 | 
			
		||||
		t.Fatalf("error received from client: %v %v", err, resp)
 | 
			
		||||
	}
 | 
			
		||||
	resp.Body.Close()
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										79
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										79
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,79 +0,0 @@
 | 
			
		||||
// Copyright 2015 The Go Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed by a BSD-style
 | 
			
		||||
// license that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
// +build !plan9,!go1.7
 | 
			
		||||
 | 
			
		||||
package ctxhttp
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/http/httptest"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/net/context"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// golang.org/issue/14065
 | 
			
		||||
func TestClosesResponseBodyOnCancel(t *testing.T) {
 | 
			
		||||
	defer func() { testHookContextDoneBeforeHeaders = nop }()
 | 
			
		||||
	defer func() { testHookDoReturned = nop }()
 | 
			
		||||
	defer func() { testHookDidBodyClose = nop }()
 | 
			
		||||
 | 
			
		||||
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
 | 
			
		||||
	defer ts.Close()
 | 
			
		||||
 | 
			
		||||
	ctx, cancel := context.WithCancel(context.Background())
 | 
			
		||||
 | 
			
		||||
	// closed when Do enters select case <-ctx.Done()
 | 
			
		||||
	enteredDonePath := make(chan struct{})
 | 
			
		||||
 | 
			
		||||
	testHookContextDoneBeforeHeaders = func() {
 | 
			
		||||
		close(enteredDonePath)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	testHookDoReturned = func() {
 | 
			
		||||
		// We now have the result (the Flush'd headers) at least,
 | 
			
		||||
		// so we can cancel the request.
 | 
			
		||||
		cancel()
 | 
			
		||||
 | 
			
		||||
		// But block the client.Do goroutine from sending
 | 
			
		||||
		// until Do enters into the <-ctx.Done() path, since
 | 
			
		||||
		// otherwise if both channels are readable, select
 | 
			
		||||
		// picks a random one.
 | 
			
		||||
		<-enteredDonePath
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sawBodyClose := make(chan struct{})
 | 
			
		||||
	testHookDidBodyClose = func() { close(sawBodyClose) }
 | 
			
		||||
 | 
			
		||||
	tr := &http.Transport{}
 | 
			
		||||
	defer tr.CloseIdleConnections()
 | 
			
		||||
	c := &http.Client{Transport: tr}
 | 
			
		||||
	req, _ := http.NewRequest("GET", ts.URL, nil)
 | 
			
		||||
	_, doErr := Do(ctx, c, req)
 | 
			
		||||
 | 
			
		||||
	select {
 | 
			
		||||
	case <-sawBodyClose:
 | 
			
		||||
	case <-time.After(5 * time.Second):
 | 
			
		||||
		t.Fatal("timeout waiting for body to close")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if doErr != ctx.Err() {
 | 
			
		||||
		t.Errorf("Do error = %v; want %v", doErr, ctx.Err())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type noteCloseConn struct {
 | 
			
		||||
	net.Conn
 | 
			
		||||
	onceClose sync.Once
 | 
			
		||||
	closefn   func()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *noteCloseConn) Close() error {
 | 
			
		||||
	c.onceClose.Do(c.closefn)
 | 
			
		||||
	return c.Conn.Close()
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										105
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										105
									
								
								vendor/golang.org/x/net/context/ctxhttp/ctxhttp_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,105 +0,0 @@
 | 
			
		||||
// Copyright 2015 The Go Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed by a BSD-style
 | 
			
		||||
// license that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
// +build !plan9
 | 
			
		||||
 | 
			
		||||
package ctxhttp
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/http/httptest"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/net/context"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	requestDuration = 100 * time.Millisecond
 | 
			
		||||
	requestBody     = "ok"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func okHandler(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	time.Sleep(requestDuration)
 | 
			
		||||
	io.WriteString(w, requestBody)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestNoTimeout(t *testing.T) {
 | 
			
		||||
	ts := httptest.NewServer(http.HandlerFunc(okHandler))
 | 
			
		||||
	defer ts.Close()
 | 
			
		||||
 | 
			
		||||
	ctx := context.Background()
 | 
			
		||||
	res, err := Get(ctx, nil, ts.URL)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	defer res.Body.Close()
 | 
			
		||||
	slurp, err := ioutil.ReadAll(res.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	if string(slurp) != requestBody {
 | 
			
		||||
		t.Errorf("body = %q; want %q", slurp, requestBody)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestCancelBeforeHeaders(t *testing.T) {
 | 
			
		||||
	ctx, cancel := context.WithCancel(context.Background())
 | 
			
		||||
 | 
			
		||||
	blockServer := make(chan struct{})
 | 
			
		||||
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		cancel()
 | 
			
		||||
		<-blockServer
 | 
			
		||||
		io.WriteString(w, requestBody)
 | 
			
		||||
	}))
 | 
			
		||||
	defer ts.Close()
 | 
			
		||||
	defer close(blockServer)
 | 
			
		||||
 | 
			
		||||
	res, err := Get(ctx, nil, ts.URL)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		res.Body.Close()
 | 
			
		||||
		t.Fatal("Get returned unexpected nil error")
 | 
			
		||||
	}
 | 
			
		||||
	if err != context.Canceled {
 | 
			
		||||
		t.Errorf("err = %v; want %v", err, context.Canceled)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestCancelAfterHangingRequest(t *testing.T) {
 | 
			
		||||
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		w.WriteHeader(http.StatusOK)
 | 
			
		||||
		w.(http.Flusher).Flush()
 | 
			
		||||
		<-w.(http.CloseNotifier).CloseNotify()
 | 
			
		||||
	}))
 | 
			
		||||
	defer ts.Close()
 | 
			
		||||
 | 
			
		||||
	ctx, cancel := context.WithCancel(context.Background())
 | 
			
		||||
	resp, err := Get(ctx, nil, ts.URL)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("unexpected error in Get: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Cancel befer reading the body.
 | 
			
		||||
	// Reading Request.Body should fail, since the request was
 | 
			
		||||
	// canceled before anything was written.
 | 
			
		||||
	cancel()
 | 
			
		||||
 | 
			
		||||
	done := make(chan struct{})
 | 
			
		||||
 | 
			
		||||
	go func() {
 | 
			
		||||
		b, err := ioutil.ReadAll(resp.Body)
 | 
			
		||||
		if len(b) != 0 || err == nil {
 | 
			
		||||
			t.Errorf(`Read got (%q, %v); want ("", error)`, b, err)
 | 
			
		||||
		}
 | 
			
		||||
		close(done)
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	select {
 | 
			
		||||
	case <-time.After(1 * time.Second):
 | 
			
		||||
		t.Errorf("Test timed out")
 | 
			
		||||
	case <-done:
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user