mirror of
https://github.com/restic/restic.git
synced 2025-10-27 05:30:50 +00:00
Update dependencies
This commit is contained in:
6
vendor/github.com/kurin/blazer/base/base.go
generated
vendored
6
vendor/github.com/kurin/blazer/base/base.go
generated
vendored
@@ -83,6 +83,12 @@ func Action(err error) ErrAction {
|
||||
return AttemptNewUpload
|
||||
}
|
||||
return ReAuthenticate
|
||||
case 400:
|
||||
// See restic/restic#1207
|
||||
if e.method == "b2_upload_file" && strings.HasPrefix(e.msg, "more than one upload using auth token") {
|
||||
return AttemptNewUpload
|
||||
}
|
||||
return Punt
|
||||
case 408:
|
||||
return AttemptNewUpload
|
||||
case 429, 500, 503:
|
||||
|
||||
119
vendor/github.com/kurin/blazer/base/integration_test.go
generated
vendored
119
vendor/github.com/kurin/blazer/base/integration_test.go
generated
vendored
@@ -20,13 +20,15 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"context"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -268,6 +270,121 @@ func TestStorage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// This slow motion train wreck of a type exists to axe a net connection after
|
||||
// N bytes have been written. Because of the specific bug it's built to test,
|
||||
// it can't just *close* the connection, so it just sleeps forever.
|
||||
type wonkyNetConn struct {
|
||||
net.Conn
|
||||
ctx context.Context // implode once cancelled
|
||||
die *bool // only implode once
|
||||
n int // bytes to allow before imploding, roughly
|
||||
i int // bytes written
|
||||
}
|
||||
|
||||
func (w *wonkyNetConn) Write(b []byte) (int, error) {
|
||||
if w.i > w.n && w.ctx.Err() != nil && *w.die {
|
||||
*w.die = false
|
||||
select {}
|
||||
}
|
||||
n, err := w.Conn.Write(b)
|
||||
w.i += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func newWonkyNetConn(ctx context.Context, die *bool, n int, netw, addr string) (net.Conn, error) {
|
||||
conn, err := net.Dial(netw, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &wonkyNetConn{
|
||||
Conn: conn,
|
||||
ctx: ctx,
|
||||
n: n,
|
||||
die: die,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func makeBadDialContext(ctx context.Context) func(context.Context, string, string) (net.Conn, error) {
|
||||
die := true
|
||||
return func(noCtx context.Context, network, addr string) (net.Conn, error) {
|
||||
return newWonkyNetConn(ctx, &die, 10000, network, addr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadUpload(t *testing.T) {
|
||||
id := os.Getenv(apiID)
|
||||
key := os.Getenv(apiKey)
|
||||
if id == "" || key == "" {
|
||||
t.Skipf("B2_ACCOUNT_ID or B2_SECRET_KEY unset; skipping integration tests")
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
octx, ocancel := context.WithCancel(ctx)
|
||||
defer ocancel()
|
||||
|
||||
badTransport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: makeBadDialContext(octx),
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
}
|
||||
|
||||
b2, err := AuthorizeAccount(ctx, id, key, Transport(badTransport))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bname := id + "-" + bucketName
|
||||
bucket, err := b2.CreateBucket(ctx, bname, "", nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := bucket.DeleteBucket(ctx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
ue, err := bucket.GetUploadURL(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
smallFile := io.LimitReader(zReader{}, 1024*50) // 50k
|
||||
hash := sha1.New()
|
||||
buf := &bytes.Buffer{}
|
||||
w := io.MultiWriter(hash, buf)
|
||||
if _, err := io.Copy(w, smallFile); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
smallSHA1 := fmt.Sprintf("%x", hash.Sum(nil))
|
||||
ocancel()
|
||||
go func() {
|
||||
ue.UploadFile(ctx, buf, buf.Len(), smallFileName, "application/octet-stream", smallSHA1, nil)
|
||||
t.Fatal("this ought not to be reachable")
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second) // give this a chance to hang
|
||||
|
||||
// Do the whole thing again with the same upload auth, before the remote end
|
||||
// notices we're gone.
|
||||
smallFile = io.LimitReader(zReader{}, 1024*50) // 50k again
|
||||
buf.Reset()
|
||||
if _, err := io.Copy(buf, smallFile); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
file, err := ue.UploadFile(ctx, buf, buf.Len(), smallFileName, "application/octet-stream", smallSHA1, nil)
|
||||
if err == nil {
|
||||
t.Error("expected an error, got none")
|
||||
if err := file.DeleteFileVersion(ctx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
if Action(err) != AttemptNewUpload {
|
||||
t.Error("Action(%v): got %v, want AttemptNewUpload", err, Action(err))
|
||||
}
|
||||
}
|
||||
|
||||
func compareFileAndInfo(t *testing.T, info *FileInfo, name, sha1 string, imap map[string]string) {
|
||||
if info.Name != name {
|
||||
t.Errorf("got %q, want %q", info.Name, name)
|
||||
|
||||
2
vendor/github.com/kurin/blazer/internal/blog/blog.go
generated
vendored
2
vendor/github.com/kurin/blazer/internal/blog/blog.go
generated
vendored
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
// Package blog implements a private logger, in the manner of glog, without
|
||||
// poluting the flag namespace or leaving files all over /tmp.
|
||||
// polluting the flag namespace or leaving files all over /tmp.
|
||||
//
|
||||
// It has almost no features, and a bunch of global state.
|
||||
package blog
|
||||
|
||||
Reference in New Issue
Block a user