mirror of
https://github.com/restic/restic.git
synced 2025-10-27 17:40:58 +00:00
Update dependencies
Among others, this updates minio-go, so that the new "eu-west-3" zone for AWS is supported.
This commit is contained in:
46
vendor/cloud.google.com/go/internal/testutil/cmp.go
generated
vendored
46
vendor/cloud.google.com/go/internal/testutil/cmp.go
generated
vendored
@@ -15,11 +15,7 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -55,45 +51,3 @@ func Diff(x, y interface{}, opts ...cmp.Option) string {
|
||||
opts = append(opts[:len(opts):len(opts)], defaultCmpOptions...)
|
||||
return cmp.Diff(x, y, opts...)
|
||||
}
|
||||
|
||||
// TODO(jba): remove the code below when cmpopts becomes available.
|
||||
|
||||
// IgnoreUnexported returns an Option that only ignores the immediate unexported
|
||||
// fields of a struct, including anonymous fields of unexported types.
|
||||
// In particular, unexported fields within the struct's exported fields
|
||||
// of struct types, including anonymous fields, will not be ignored unless the
|
||||
// type of the field itself is also passed to IgnoreUnexported.
|
||||
func IgnoreUnexported(typs ...interface{}) cmp.Option {
|
||||
ux := newUnexportedFilter(typs...)
|
||||
return cmp.FilterPath(ux.filter, cmp.Ignore())
|
||||
}
|
||||
|
||||
type unexportedFilter struct{ m map[reflect.Type]bool }
|
||||
|
||||
func newUnexportedFilter(typs ...interface{}) unexportedFilter {
|
||||
ux := unexportedFilter{m: make(map[reflect.Type]bool)}
|
||||
for _, typ := range typs {
|
||||
t := reflect.TypeOf(typ)
|
||||
if t == nil || t.Kind() != reflect.Struct {
|
||||
panic(fmt.Sprintf("invalid struct type: %T", typ))
|
||||
}
|
||||
ux.m[t] = true
|
||||
}
|
||||
return ux
|
||||
}
|
||||
func (xf unexportedFilter) filter(p cmp.Path) bool {
|
||||
if len(p) < 2 {
|
||||
return false
|
||||
}
|
||||
sf, ok := p[len(p)-1].(cmp.StructField)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return xf.m[p[len(p)-2].Type()] && !isExported(sf.Name())
|
||||
}
|
||||
|
||||
// isExported reports whether the identifier is exported.
|
||||
func isExported(id string) bool {
|
||||
r, _ := utf8.DecodeRuneInString(id)
|
||||
return unicode.IsUpper(r)
|
||||
}
|
||||
|
||||
36
vendor/cloud.google.com/go/internal/testutil/context.go
generated
vendored
36
vendor/cloud.google.com/go/internal/testutil/context.go
generated
vendored
@@ -16,6 +16,7 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@@ -23,6 +24,7 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
"golang.org/x/oauth2/jwt"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -59,13 +61,35 @@ func TokenSourceEnv(ctx context.Context, envVar string, scopes ...string) oauth2
|
||||
}
|
||||
return ts
|
||||
}
|
||||
jsonKey, err := ioutil.ReadFile(key)
|
||||
conf, err := jwtConfigFromFile(key, scopes)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot read the JSON key file, err: %v", err)
|
||||
}
|
||||
conf, err := google.JWTConfigFromJSON(jsonKey, scopes...)
|
||||
if err != nil {
|
||||
log.Fatalf("google.JWTConfigFromJSON: %v", err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
return conf.TokenSource(ctx)
|
||||
}
|
||||
|
||||
// JWTConfig reads the JSON private key file whose name is in the default
|
||||
// environment variable, and returns the jwt.Config it contains. It ignores
|
||||
// scopes.
|
||||
// If the environment variable is empty, it returns (nil, nil).
|
||||
func JWTConfig() (*jwt.Config, error) {
|
||||
return jwtConfigFromFile(os.Getenv(envPrivateKey), nil)
|
||||
}
|
||||
|
||||
// jwtConfigFromFile reads the given JSON private key file, and returns the
|
||||
// jwt.Config it contains.
|
||||
// If the filename is empty, it returns (nil, nil).
|
||||
func jwtConfigFromFile(filename string, scopes []string) (*jwt.Config, error) {
|
||||
if filename == "" {
|
||||
return nil, nil
|
||||
}
|
||||
jsonKey, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Cannot read the JSON key file, err: %v", err)
|
||||
}
|
||||
conf, err := google.JWTConfigFromJSON(jsonKey, scopes...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("google.JWTConfigFromJSON: %v", err)
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
31
vendor/cloud.google.com/go/internal/testutil/server.go
generated
vendored
31
vendor/cloud.google.com/go/internal/testutil/server.go
generated
vendored
@@ -18,8 +18,10 @@ package testutil
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
// A Server is an in-process gRPC server, listening on a system-chosen port on
|
||||
@@ -71,3 +73,32 @@ func (s *Server) Close() {
|
||||
s.Gsrv.Stop()
|
||||
s.l.Close()
|
||||
}
|
||||
|
||||
// PageBounds converts an incoming page size and token from an RPC request into
|
||||
// slice bounds and the outgoing next-page token.
|
||||
//
|
||||
// PageBounds assumes that the complete, unpaginated list of items exists as a
|
||||
// single slice. In addition to the page size and token, PageBounds needs the
|
||||
// length of that slice.
|
||||
//
|
||||
// PageBounds's first two return values should be used to construct a sub-slice of
|
||||
// the complete, unpaginated slice. E.g. if the complete slice is s, then
|
||||
// s[from:to] is the desired page. Its third return value should be set as the
|
||||
// NextPageToken field of the RPC response.
|
||||
func PageBounds(pageSize int, pageToken string, length int) (from, to int, nextPageToken string, err error) {
|
||||
from, to = 0, length
|
||||
if pageToken != "" {
|
||||
from, err = strconv.Atoi(pageToken)
|
||||
if err != nil {
|
||||
return 0, 0, "", grpc.Errorf(codes.InvalidArgument, "bad page token: %v", err)
|
||||
}
|
||||
if from >= length {
|
||||
return length, length, "", nil
|
||||
}
|
||||
}
|
||||
if pageSize > 0 && from+pageSize < length {
|
||||
to = from + pageSize
|
||||
nextPageToken = strconv.Itoa(to)
|
||||
}
|
||||
return from, to, nextPageToken, nil
|
||||
}
|
||||
|
||||
44
vendor/cloud.google.com/go/internal/testutil/server_test.go
generated
vendored
44
vendor/cloud.google.com/go/internal/testutil/server_test.go
generated
vendored
@@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
@@ -33,3 +34,46 @@ func TestNewServer(t *testing.T) {
|
||||
conn.Close()
|
||||
srv.Close()
|
||||
}
|
||||
|
||||
func TestPageBounds(t *testing.T) {
|
||||
const length = 10
|
||||
for _, test := range []struct {
|
||||
size int
|
||||
tok string
|
||||
wantFrom int
|
||||
wantTo int
|
||||
wantTok string
|
||||
}{
|
||||
{5, "",
|
||||
0, 5, "5"},
|
||||
{11, "",
|
||||
0, 10, ""},
|
||||
{5, "2",
|
||||
2, 7, "7"},
|
||||
{5, "8",
|
||||
8, 10, ""},
|
||||
{11, "8",
|
||||
8, 10, ""},
|
||||
{1, "11",
|
||||
10, 10, ""},
|
||||
} {
|
||||
gotFrom, gotTo, gotTok, err := PageBounds(test.size, test.tok, length)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := gotFrom, test.wantFrom; got != want {
|
||||
t.Errorf("%+v: from: got %d, want %d", test, got, want)
|
||||
}
|
||||
if got, want := gotTo, test.wantTo; got != want {
|
||||
t.Errorf("%+v: to: got %d, want %d", test, got, want)
|
||||
}
|
||||
if got, want := gotTok, test.wantTok; got != want {
|
||||
t.Errorf("%+v: got %q, want %q", test, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
_, _, _, err := PageBounds(4, "xyz", 5)
|
||||
if grpc.Code(err) != codes.InvalidArgument {
|
||||
t.Errorf("want invalid argument, got <%v>", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user