vendor: update all dependencies

This commit is contained in:
Nick Craig-Wood
2018-03-19 15:51:38 +00:00
parent 940df88eb2
commit d64789528d
4309 changed files with 1327230 additions and 1001070 deletions
+17
View File
@@ -0,0 +1,17 @@
// Copyright 2018 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 go1.8
package gensupport
import (
"io"
"net/http"
)
// SetGetBody sets the GetBody field of req to f.
func SetGetBody(req *http.Request, f func() (io.ReadCloser, error)) {
req.GetBody = f
}
+1 -1
View File
@@ -493,7 +493,7 @@ func TestParseJSONTag(t *testing.T) {
t.Fatalf("parsing json:\n got err: %v\ntag: %q", err, tc.tag)
}
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("parseJSONTage:\ngot :%s\nwant:%s", got, tc.want)
t.Errorf("parseJSONTage:\ngot :%v\nwant:%v", got, tc.want)
}
}
}
+36 -4
View File
@@ -5,12 +5,14 @@
package gensupport
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/textproto"
"strings"
"google.golang.org/api/googleapi"
)
@@ -251,11 +253,11 @@ func (mi *MediaInfo) UploadType() string {
}
// UploadRequest sets up an HTTP request for media upload. It adds headers
// as necessary, and returns a replacement for the body.
func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newBody io.Reader, cleanup func()) {
// as necessary, and returns a replacement for the body and a function for http.Request.GetBody.
func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newBody io.Reader, getBody func() (io.ReadCloser, error), cleanup func()) {
cleanup = func() {}
if mi == nil {
return body, cleanup
return body, nil, cleanup
}
var media io.Reader
if mi.media != nil {
@@ -269,7 +271,17 @@ func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newB
media, _, _, _ = mi.buffer.Chunk()
}
if media != nil {
fb := readerFunc(body)
fm := readerFunc(media)
combined, ctype := CombineBodyMedia(body, "application/json", media, mi.mType)
if fb != nil && fm != nil {
getBody = func() (io.ReadCloser, error) {
rb := ioutil.NopCloser(fb())
rm := ioutil.NopCloser(fm())
r, _ := CombineBodyMedia(rb, "application/json", rm, mi.mType)
return r, nil
}
}
cleanup = func() { combined.Close() }
reqHeaders.Set("Content-Type", ctype)
body = combined
@@ -277,7 +289,27 @@ func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newB
if mi.buffer != nil && mi.mType != "" && !mi.singleChunk {
reqHeaders.Set("X-Upload-Content-Type", mi.mType)
}
return body, cleanup
return body, getBody, cleanup
}
// readerFunc returns a function that always returns an io.Reader that has the same
// contents as r, provided that can be done without consuming r. Otherwise, it
// returns nil.
// See http.NewRequest (in net/http/request.go).
func readerFunc(r io.Reader) func() io.Reader {
switch r := r.(type) {
case *bytes.Buffer:
buf := r.Bytes()
return func() io.Reader { return bytes.NewReader(buf) }
case *bytes.Reader:
snapshot := *r
return func() io.Reader { r := snapshot; return &r }
case *strings.Reader:
snapshot := *r
return func() io.Reader { r := snapshot; return &r }
default:
return nil
}
}
// ResumableUpload returns an appropriately configured ResumableUpload value if the
+70 -1
View File
@@ -6,6 +6,7 @@ package gensupport
import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
"net/http"
@@ -267,6 +268,75 @@ func TestUploadRequest(t *testing.T) {
}
}
func TestUploadRequestGetBody(t *testing.T) {
// Test that a single chunk results in a getBody function that is non-nil, and
// that produces the same content as the original body.
// Mock out rand.Reader so we use the same multipart boundary every time.
rr := rand.Reader
rand.Reader = &nullReader{1000}
defer func() {
rand.Reader = rr
}()
for _, test := range []struct {
desc string
r io.Reader
chunkSize int
wantGetBody bool
wantContentType string
wantUploadType string
}{
{
desc: "chunk size of zero: no getBody",
r: &nullReader{10},
chunkSize: 0,
wantGetBody: false,
},
{
desc: "chunk size == data size: 1 chunk, getBody",
r: &nullReader{googleapi.MinUploadChunkSize},
chunkSize: 1,
wantGetBody: true,
},
{
desc: "chunk size < data size: MediaBuffer, >1 chunk, no getBody",
// No getBody here, because the initial request contains no media data
// Note that ChunkSize = 1 is rounded up to googleapi.MinUploadChunkSize.
r: &nullReader{2 * googleapi.MinUploadChunkSize},
chunkSize: 1,
wantGetBody: false,
},
} {
mi := NewInfoFromMedia(test.r, []googleapi.MediaOption{googleapi.ChunkSize(test.chunkSize)})
r, getBody, _ := mi.UploadRequest(http.Header{}, bytes.NewBuffer([]byte("body")))
if got, want := (getBody != nil), test.wantGetBody; got != want {
t.Errorf("%s: getBody: got %t, want %t", test.desc, got, want)
continue
}
if getBody == nil {
continue
}
want, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 3; i++ {
rc, err := getBody()
if err != nil {
t.Fatal(err)
}
got, err := ioutil.ReadAll(rc)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Errorf("%s, %d:\ngot:\n%s\nwant:\n%s", test.desc, i, string(got), string(want))
}
}
}
}
func TestResumableUpload(t *testing.T) {
for _, test := range []struct {
desc string
@@ -275,7 +345,6 @@ func TestResumableUpload(t *testing.T) {
wantUploadType string
wantResumableUpload bool
}{
{
desc: "chunk size of zero: don't use a MediaBuffer; upload as a single chunk",
r: strings.NewReader("12345"),
+14
View File
@@ -0,0 +1,14 @@
// Copyright 2018 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 !go1.8
package gensupport
import (
"io"
"net/http"
)
func SetGetBody(req *http.Request, f func() (io.ReadCloser, error)) {}
+2 -2
View File
@@ -78,7 +78,7 @@ func TestRetry(t *testing.T) {
t.Errorf("%s: Retry returned err %v", tt.desc, err)
}
if got := resp.StatusCode; got != tt.wantStatus {
t.Errorf("%s: Retry returned response with StatusCode=%d; want %d", got, tt.wantStatus)
t.Errorf("%s: Retry returned response with StatusCode=%d; want %d", tt.desc, got, tt.wantStatus)
}
if len(tt.respStatus) != 0 {
t.Errorf("%s: f was not called enough; status codes remaining: %v", tt.desc, tt.respStatus)
@@ -120,7 +120,7 @@ func TestRetryClosesBody(t *testing.T) {
want := i != 2 // Only the last response should not be closed.
got := resp.Body.(*checkCloseReader).closed
if got != want {
t.Errorf("response[%d].Body closed = %t, want %t", got, want)
t.Errorf("response[%d].Body closed = %t, want %t", i, got, want)
}
}
}