Skip to content

Commit

Permalink
all: format all source code files with gofumpt and -extra option (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj authored Jun 3, 2024
1 parent 19db7d5 commit ba58ec7
Show file tree
Hide file tree
Showing 54 changed files with 159 additions and 118 deletions.
11 changes: 8 additions & 3 deletions blob/azureblob/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,15 @@ type reader struct {
func (r *reader) Read(p []byte) (int, error) {
return r.body.Read(p)
}

func (r *reader) Close() error {
return r.body.Close()
}

func (r *reader) Attributes() *driver.ReaderAttributes {
return &r.attrs
}

func (r *reader) As(i interface{}) bool {
p, ok := i.(*azblobblob.DownloadStreamResponse)
if !ok {
Expand Down Expand Up @@ -742,7 +745,8 @@ func (b *bucket) ListPaged(ctx context.Context, opts *driver.ListOptions) (*driv
*v = *blobPrefix
}
return ok
}})
},
})
}
for _, blobInfo := range segment.BlobItems {
blobInfo := blobInfo // capture loop variable for use in AsFunc
Expand All @@ -758,7 +762,8 @@ func (b *bucket) ListPaged(ctx context.Context, opts *driver.ListOptions) (*driv
*v = *blobInfo
}
return ok
}})
},
})
}
if resp.NextMarker != nil {
page.NextPageToken = []byte(*resp.NextMarker)
Expand Down Expand Up @@ -857,7 +862,7 @@ func unescapeKey(key string) string {
}

// NewTypedWriter implements driver.NewTypedWriter.
func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *bucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
key = escapeKey(key, false)
blobClient := b.client.NewBlockBlobClient(key)
if opts.BufferSize == 0 {
Expand Down
6 changes: 4 additions & 2 deletions blob/blob_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
)

// Ensure that Bucket implements various io/fs interfaces.
var _ = fs.FS(&Bucket{})
var _ = fs.SubFS(&Bucket{})
var (
_ = fs.FS(&Bucket{})
_ = fs.SubFS(&Bucket{})
)

// iofsFileInfo describes a single file in an io/fs.FS.
// It implements fs.FileInfo and fs.DirEntry.
Expand Down
4 changes: 2 additions & 2 deletions blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type loaderBucket struct {
r stubReader
}

func (b *loaderBucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *loaderBucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
return &b.w, nil
}

Expand Down Expand Up @@ -381,7 +381,7 @@ func (b *erroringBucket) NewRangeReader(ctx context.Context, key string, offset,
return nil, errFake
}

func (b *erroringBucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *erroringBucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
if key == "work" {
return &erroringWriter{}, nil
}
Expand Down
12 changes: 12 additions & 0 deletions blob/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (b *prefixedBucket) ErrorAs(err error, i interface{}) bool { return b.base
func (b *prefixedBucket) Attributes(ctx context.Context, key string) (*Attributes, error) {
return b.base.Attributes(ctx, b.prefix+key)
}

func (b *prefixedBucket) ListPaged(ctx context.Context, opts *ListOptions) (*ListPage, error) {
var myopts ListOptions
if opts != nil {
Expand All @@ -404,21 +405,26 @@ func (b *prefixedBucket) ListPaged(ctx context.Context, opts *ListOptions) (*Lis
}
return page, nil
}

func (b *prefixedBucket) NewRangeReader(ctx context.Context, key string, offset, length int64, opts *ReaderOptions) (Reader, error) {
return b.base.NewRangeReader(ctx, b.prefix+key, offset, length, opts)
}

func (b *prefixedBucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *WriterOptions) (Writer, error) {
if key == "" {
return nil, errors.New("invalid key (empty string)")
}
return b.base.NewTypedWriter(ctx, b.prefix+key, contentType, opts)
}

func (b *prefixedBucket) Copy(ctx context.Context, dstKey, srcKey string, opts *CopyOptions) error {
return b.base.Copy(ctx, b.prefix+dstKey, b.prefix+srcKey, opts)
}

func (b *prefixedBucket) Delete(ctx context.Context, key string) error {
return b.base.Delete(ctx, b.prefix+key)
}

func (b *prefixedBucket) SignedURL(ctx context.Context, key string, opts *SignedURLOptions) (string, error) {
return b.base.SignedURL(ctx, b.prefix+key, opts)
}
Expand All @@ -441,21 +447,27 @@ func (b *singleKeyBucket) ErrorAs(err error, i interface{}) bool { return b.bas
func (b *singleKeyBucket) Attributes(ctx context.Context, _ string) (*Attributes, error) {
return b.base.Attributes(ctx, b.key)
}

func (b *singleKeyBucket) ListPaged(ctx context.Context, opts *ListOptions) (*ListPage, error) {
return nil, errors.New("List not supported for SingleKey buckets")
}

func (b *singleKeyBucket) NewRangeReader(ctx context.Context, _ string, offset, length int64, opts *ReaderOptions) (Reader, error) {
return b.base.NewRangeReader(ctx, b.key, offset, length, opts)
}

func (b *singleKeyBucket) NewTypedWriter(ctx context.Context, _, contentType string, opts *WriterOptions) (Writer, error) {
return b.base.NewTypedWriter(ctx, b.key, contentType, opts)
}

func (b *singleKeyBucket) Copy(ctx context.Context, dstKey, _ string, opts *CopyOptions) error {
return b.base.Copy(ctx, dstKey, b.key, opts)
}

func (b *singleKeyBucket) Delete(ctx context.Context, _ string) error {
return b.base.Delete(ctx, b.key)
}

func (b *singleKeyBucket) SignedURL(ctx context.Context, _ string, opts *SignedURLOptions) (string, error) {
return b.base.SignedURL(ctx, b.key, opts)
}
Expand Down
5 changes: 2 additions & 3 deletions blob/drivertest/drivertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ func testCopy(t *testing.T, newHarness HarnessMaker) {
contentEncoding = "identity"
contentLanguage = "en"
)
var contents = []byte("Hello World")
contents := []byte("Hello World")

ctx := context.Background()
t.Run("NonExistentSourceFails", func(t *testing.T) {
Expand Down Expand Up @@ -2371,7 +2371,6 @@ func testKeys(t *testing.T, newHarness HarnessMaker) {
t.Errorf("copied got %q want %q", string(got), string(content))
}
}

})
}
}
Expand Down Expand Up @@ -2618,7 +2617,7 @@ func testAs(t *testing.T, newHarness HarnessMaker, st AsTest) {
key = dir + "/as-test"
copyKey = dir + "/as-test-copy"
)
var content = []byte("hello world")
content := []byte("hello world")
ctx := context.Background()

h, err := newHarness(ctx, t)
Expand Down
2 changes: 1 addition & 1 deletion blob/fileblob/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExampleOpenBucket() {

// The directory you pass to fileblob.OpenBucket must exist first.
const myDir = "path/to/local/directory"
if err := os.MkdirAll(myDir, 0777); err != nil {
if err := os.MkdirAll(myDir, 0o777); err != nil {
log.Fatal(err)
}

Expand Down
7 changes: 3 additions & 4 deletions blob/fileblob/fileblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func openBucket(dir string, opts *Options) (driver.Bucket, error) {
opts = &Options{}
}
if opts.DirFileMode == 0 {
opts.DirFileMode = os.FileMode(0777)
opts.DirFileMode = os.FileMode(0o777)
}

absdir, err := filepath.Abs(dir)
Expand Down Expand Up @@ -396,7 +396,6 @@ func (b *bucket) forKey(key string) (string, os.FileInfo, *xattrs, error) {

// ListPaged implements driver.ListPaged.
func (b *bucket) ListPaged(ctx context.Context, opts *driver.ListOptions) (*driver.ListPage, error) {

var pageToken string
if len(opts.PageToken) > 0 {
pageToken = string(opts.PageToken)
Expand Down Expand Up @@ -701,7 +700,7 @@ func createTemp(path string, noTempDir bool) (*os.File, error) {
name = filepath.Join(os.TempDir(), filepath.Base(path))
}
name += "." + strconv.FormatInt(time.Now().UnixNano(), 16) + ".tmp"
f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666)
if os.IsExist(err) {
if try++; try < 10000 {
continue
Expand All @@ -713,7 +712,7 @@ func createTemp(path string, noTempDir bool) (*os.File, error) {
}

// NewTypedWriter implements driver.NewTypedWriter.
func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *bucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
path, err := b.path(key)
if err != nil {
return nil, err
Expand Down
11 changes: 8 additions & 3 deletions blob/fileblob/fileblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,23 @@ func (verifyAs) BucketCheck(b *blob.Bucket) error {
}
return nil
}

func (verifyAs) BeforeRead(as func(interface{}) bool) error {
var f *os.File
if !as(&f) {
return errors.New("BeforeRead.As failed")
}
return nil
}

func (verifyAs) BeforeWrite(as func(interface{}) bool) error {
var f *os.File
if !as(&f) {
return errors.New("BeforeWrite.As failed")
}
return nil
}

func (verifyAs) BeforeCopy(as func(interface{}) bool) error {
var f *os.File
if !as(&f) {
Expand All @@ -317,13 +320,15 @@ func (verifyAs) AttributesCheck(attrs *blob.Attributes) error {
}
return nil
}

func (verifyAs) ReaderCheck(r *blob.Reader) error {
var ior io.Reader
if !r.As(&ior) {
return errors.New("Reader.As failed")
}
return nil
}

func (verifyAs) ListObjectCheck(o *blob.ListObject) error {
var fi os.FileInfo
if !o.As(&fi) {
Expand Down Expand Up @@ -353,15 +358,15 @@ func TestOpenBucketFromURL(t *testing.T) {
if err := os.MkdirAll(filepath.Join(dir, subdir), os.ModePerm); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "myfile.txt"), []byte("hello world"), 0666); err != nil {
if err := os.WriteFile(filepath.Join(dir, "myfile.txt"), []byte("hello world"), 0o666); err != nil {
t.Fatal(err)
}
// To avoid making another temp dir, use the bucket directory to hold the secret key file.
secretKeyPath := filepath.Join(dir, "secret.key")
if err := os.WriteFile(secretKeyPath, []byte("secret key"), 0666); err != nil {
if err := os.WriteFile(secretKeyPath, []byte("secret key"), 0o666); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, subdir, "myfileinsubdir.txt"), []byte("hello world in subdir"), 0666); err != nil {
if err := os.WriteFile(filepath.Join(dir, subdir, "myfileinsubdir.txt"), []byte("hello world in subdir"), 0o666); err != nil {
t.Fatal(err)
}
// Convert dir to a URL path, adding a leading "/" if needed on Windows.
Expand Down
2 changes: 1 addition & 1 deletion blob/gcsblob/gcsblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func unescapeKey(key string) string {
}

// NewTypedWriter implements driver.NewTypedWriter.
func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *bucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
key = escapeKey(key)
bkt := b.client.Bucket(b.name)
obj := bkt.Object(key)
Expand Down
11 changes: 7 additions & 4 deletions blob/gcsblob/gcsblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func TestOpenBucketFromURL(t *testing.T) {
t.Fatal(err)
}
defer os.Remove(pkFile.Name())
if err := os.WriteFile(pkFile.Name(), []byte("key"), 0666); err != nil {
if err := os.WriteFile(pkFile.Name(), []byte("key"), 0o666); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -687,7 +687,8 @@ func TestReadDefaultCredentials(t *testing.T) {
WantPrivateKey []byte
}{
// Variant A: service account file
{`{
{
`{
"type": "service_account",
"project_id": "project-id",
"private_key_id": "key-id",
Expand All @@ -703,7 +704,8 @@ func TestReadDefaultCredentials(t *testing.T) {
[]byte("-----BEGIN PRIVATE KEY-----\nprivate-key\n-----END PRIVATE KEY-----\n"),
},
// Variant A: credentials file absent a private key (stripped)
{`{
{
`{
"google": {},
"client_email": "service-account-email",
"client_id": "client-id"
Expand All @@ -712,7 +714,8 @@ func TestReadDefaultCredentials(t *testing.T) {
[]byte(""),
},
// Variant B: obtained through the REST API
{`{
{
`{
"name": "projects/project-id/serviceAccounts/service-account-email/keys/key-id",
"privateKeyType": "TYPE_GOOGLE_CREDENTIALS_FILE",
"privateKeyData": "private-key",
Expand Down
9 changes: 6 additions & 3 deletions blob/gcsblob/iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ func TestIAMCredentialsClient(t *testing.T) {
wantOutput []byte
requestErr error
}{
{"happy path: signing", nil,
{
"happy path: signing", nil,
mockIAMClient{},
[]byte("payload"), []byte(mockSignature), nil,
},
{"won't connect", errors.New("Missing role: serviceAccountTokenCreator"),
{
"won't connect", errors.New("Missing role: serviceAccountTokenCreator"),
mockIAMClient{},
[]byte("payload"), nil, nil,
},
{"request fails", nil,
{
"request fails", nil,
mockIAMClient{requestErr: context.Canceled},
[]byte("payload"), nil, context.Canceled,
},
Expand Down
2 changes: 1 addition & 1 deletion blob/memblob/memblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (r *reader) Attributes() *driver.ReaderAttributes {
func (r *reader) As(i interface{}) bool { return false }

// NewTypedWriter implements driver.NewTypedWriter.
func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *bucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
if key == "" {
return nil, errors.New("invalid key (empty string)")
}
Expand Down
2 changes: 1 addition & 1 deletion blob/s3blob/s3blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func unescapeKey(key string) string {
}

// NewTypedWriter implements driver.NewTypedWriter.
func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
func (b *bucket) NewTypedWriter(ctx context.Context, key, contentType string, opts *driver.WriterOptions) (driver.Writer, error) {
key = escapeKey(key)
if b.useV2 {
uploaderV2 := s3managerv2.NewUploader(b.clientV2, func(u *s3managerv2.Uploader) {
Expand Down
1 change: 0 additions & 1 deletion docstore/awsdynamodb/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func BenchmarkPutVSTransact(b *testing.B) {
}
})
})

}
}

Expand Down
1 change: 0 additions & 1 deletion docstore/awsdynamodb/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func (d decoder) AsFloat() (float64, bool) {
return 0, false
}
return f, true

}

func (d decoder) AsComplex() (complex128, bool) {
Expand Down
6 changes: 4 additions & 2 deletions docstore/awsdynamodb/dynamo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func newHarness(ctx context.Context, t *testing.T) (drivertest.Harness, error) {
}

func (*harness) BeforeDoTypes() []interface{} {
return []interface{}{&dyn.BatchGetItemInput{}, &dyn.TransactWriteItemsInput{},
&dyn.PutItemInput{}, &dyn.DeleteItemInput{}, &dyn.UpdateItemInput{}}
return []interface{}{
&dyn.BatchGetItemInput{}, &dyn.TransactWriteItemsInput{},
&dyn.PutItemInput{}, &dyn.DeleteItemInput{}, &dyn.UpdateItemInput{},
}
}

func (*harness) BeforeQueryTypes() []interface{} {
Expand Down
Loading

0 comments on commit ba58ec7

Please sign in to comment.