vendor: update all dependencies
This commit is contained in:
+51
-12
@@ -15,11 +15,14 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
@@ -28,36 +31,72 @@ import (
|
||||
)
|
||||
|
||||
type fakeTransport struct {
|
||||
gotReq *http.Request
|
||||
gotReq *http.Request
|
||||
results []transportResult
|
||||
}
|
||||
|
||||
type transportResult struct {
|
||||
res *http.Response
|
||||
err error
|
||||
}
|
||||
|
||||
func (t *fakeTransport) addResult(res *http.Response, err error) {
|
||||
t.results = append(t.results, transportResult{res, err})
|
||||
}
|
||||
|
||||
func (t *fakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
t.gotReq = req
|
||||
return nil, fmt.Errorf("error handling request")
|
||||
if len(t.results) == 0 {
|
||||
return nil, fmt.Errorf("error handling request")
|
||||
}
|
||||
result := t.results[0]
|
||||
t.results = t.results[1:]
|
||||
return result.res, result.err
|
||||
}
|
||||
|
||||
func TestErrorOnObjectsInsertCall(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
hc := &http.Client{Transport: &fakeTransport{}}
|
||||
client, err := NewClient(ctx, option.WithHTTPClient(hc))
|
||||
if err != nil {
|
||||
t.Fatalf("error when creating client: %v", err)
|
||||
|
||||
doWrite := func(hc *http.Client) *Writer {
|
||||
client, err := NewClient(ctx, option.WithHTTPClient(hc))
|
||||
if err != nil {
|
||||
t.Fatalf("error when creating client: %v", err)
|
||||
}
|
||||
wc := client.Bucket("bucketname").Object("filename1").NewWriter(ctx)
|
||||
wc.ContentType = "text/plain"
|
||||
|
||||
// We can't check that the Write fails, since it depends on the write to the
|
||||
// underling fakeTransport failing which is racy.
|
||||
wc.Write([]byte("hello world"))
|
||||
return wc
|
||||
}
|
||||
wc := client.Bucket("bucketname").Object("filename1").NewWriter(ctx)
|
||||
wc.ContentType = "text/plain"
|
||||
|
||||
// We can't check that the Write fails, since it depends on the write to the
|
||||
// underling fakeTransport failing which is racy.
|
||||
wc.Write([]byte("hello world"))
|
||||
|
||||
wc := doWrite(&http.Client{Transport: &fakeTransport{}})
|
||||
// Close must always return an error though since it waits for the transport to
|
||||
// have closed.
|
||||
if err := wc.Close(); err == nil {
|
||||
t.Errorf("expected error on close, got nil")
|
||||
}
|
||||
|
||||
// Retry on 5xx
|
||||
ft := &fakeTransport{}
|
||||
ft.addResult(&http.Response{
|
||||
StatusCode: 503,
|
||||
Body: ioutil.NopCloser(&bytes.Buffer{}),
|
||||
}, nil)
|
||||
ft.addResult(&http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(strings.NewReader("{}")),
|
||||
}, nil)
|
||||
wc = doWrite(&http.Client{Transport: ft})
|
||||
if err := wc.Close(); err != nil {
|
||||
t.Errorf("got %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryption(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ft := &fakeTransport{}
|
||||
hc := &http.Client{Transport: ft}
|
||||
|
||||
Reference in New Issue
Block a user