Skip to content

Commit

Permalink
style: remove debug comments and adjust whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
4o4x committed Jul 5, 2024
1 parent c56f6c0 commit 6cdc4f6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 74 deletions.
20 changes: 2 additions & 18 deletions command/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,11 @@ func NewHeadCommand() *cli.Command {
return err
},
Action: func(c *cli.Context) (err error) {

//print the command name
//fmt.Println(c.Command.FullName())

defer stat.Collect(c.Command.FullName(), &err)()

//fmt.Println("head command")

op := c.Command.Name
//fmt.Println("op: ", op)
fullCommand := commandFromContext(c)

//print the command name
//fmt.Println("fullCommand: ", fullCommand)

src, err := url.New(c.Args().Get(0), url.WithVersion(c.String("version-id")),
url.WithRaw(c.Bool("raw")))
if err != nil {
Expand All @@ -99,15 +89,14 @@ func NewHeadCommand() *cli.Command {
src: src,
op: op,
fullCommand: fullCommand,
//flag
//flags
showEtag: c.Bool("etag"),
humanize: c.Bool("humanize"),
showStorageClass: c.Bool("storage-class"),
showFullPath: c.Bool("show-fullpath"),

storageOpts: NewStorageOpts(c),
}.Run(c.Context)

},
}
cmd.BashComplete = getBashCompleteFn(cmd, true, false)
Expand Down Expand Up @@ -149,15 +138,10 @@ func (h Head) Run(ctx context.Context) error {
log.Info(msg)

return nil

}

object, metadata, err := client.HeadObject(ctx, h.src)

//print the metadata all fields

//fmt.Println("metadata: ", metadata)

if err != nil {
printError(h.fullCommand, h.op, err)
return err
Expand Down Expand Up @@ -192,7 +176,7 @@ func (m HeadObjectMessage) String() string {
return m.Object.URL.String()
}
var etag string
// date and storage fiels
// date and storage fields
var listFormat = "%19s %2s"

// align etag
Expand Down
2 changes: 1 addition & 1 deletion command/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (l ListMessage) String() string {
return l.Object.URL.String()
}
var etag string
// date and storage fiels
// date and storage fields
var listFormat = "%19s %2s"

// align etag
Expand Down
13 changes: 1 addition & 12 deletions e2e/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"gotest.tools/v3/icmd"
)

//head (without anything -> error)
// head (without anything -> error)

func TestHead(t *testing.T) {
t.Parallel()
Expand All @@ -21,8 +21,6 @@ func TestHead(t *testing.T) {
result.Assert(t, icmd.Expected{ExitCode: 1})
}

// ------------------ Bucket Tests ------------------

// head bucket

func TestHeadBucket(t *testing.T) {
Expand Down Expand Up @@ -65,8 +63,6 @@ func TestHeadBucketJSON(t *testing.T) {
cmd := s5cmd("--json", "head", fmt.Sprintf("s3://%v", bucket))
result := icmd.RunCmd(cmd)

//{"created_at":"2021/09/01 00:00:00","name":"bucket"}

result.Assert(t, icmd.Expected{ExitCode: 0, Out: fmt.Sprintf(`{"created_at":"%v","name":"%v"}`, "0001-01-01T00:00:00Z", bucket)})
}

Expand Down Expand Up @@ -130,8 +126,6 @@ func TestHeadBucketStorageClass(t *testing.T) {
result.Assert(t, icmd.Expected{ExitCode: 0, Out: bucket})
}

// ------------------ Object Tests ------------------

// head object

func TestHeadObjectOutput(t *testing.T) {
Expand All @@ -151,7 +145,6 @@ func TestHeadObjectOutput(t *testing.T) {
sizePattern := `\d+`
s3urlPattern := `myfile.txt`

// Beklenen çıktıyı regex pattern'ları ile oluşturuyoruz
expectedOutput := fmt.Sprintf(
`%s\s+%s\s+%s\s+%s`,
datePattern,
Expand All @@ -160,7 +153,6 @@ func TestHeadObjectOutput(t *testing.T) {
s3urlPattern,
)

// Regex ile eşleştirme yaparak sonucu kontrol ediyoruz
match, err := regexp.MatchString(expectedOutput, result.Combined())
if err != nil {
t.Fatalf("regex match failed: %v", err)
Expand All @@ -170,7 +162,6 @@ func TestHeadObjectOutput(t *testing.T) {
t.Errorf("expected output to match:\n%s\nbut got:\n%s", expectedOutput, result.Combined())
}

// Çıkış kodunu kontrol ediyoruz
result.Assert(t, icmd.Expected{ExitCode: 0})
}

Expand Down Expand Up @@ -298,8 +289,6 @@ func TestHeadObjectEtag(t *testing.T) {
cmd := s5cmd("head", "--etag", fmt.Sprintf("s3://%v/file.txt", bucket))
result := icmd.RunCmd(cmd)

// 2024/07/03 13:13:15 STANDART 9a0364b9e99bb480dd25e1f0284c8555 7 file.txt

datePattern := `\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`
storageClassPattern := `(?:STANDART|)`
sizePattern := `\d+`
Expand Down
4 changes: 2 additions & 2 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestRunWildcardCountGreaterEqualThanWorkerCount(t *testing.T) {
assertLines(t, result.Stderr(), map[int]compareFunc{})
}

/*func TestRunSpecialCharactersInPrefix(t *testing.T) {
func TestRunSpecialCharactersInPrefix(t *testing.T) {
t.Parallel()

bucket := s3BucketFromTestName(t)
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestRunWildcardCountGreaterEqualThanWorkerCount(t *testing.T) {
}, sortInput(true))

assertLines(t, result.Stderr(), map[int]compareFunc{})
}*/
}

func TestRunDryRun(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 0 additions & 2 deletions storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ func (s *S3) GetBucketVersioning(ctx context.Context, bucket string) (string, er
}

func (s *S3) HeadBucket(ctx context.Context, url *url.URL) (*Bucket, error) {

output, err := s.api.HeadBucketWithContext(ctx, &s3.HeadBucketInput{
Bucket: aws.String(url.Bucket),
})
Expand All @@ -1181,7 +1180,6 @@ func (s *S3) HeadBucket(ctx context.Context, url *url.URL) (*Bucket, error) {
}

func (s *S3) HeadObject(ctx context.Context, url *url.URL) (*Object, map[string]string, error) {

input := &s3.HeadObjectInput{
Bucket: aws.String(url.Bucket),
Key: aws.String(url.Path),
Expand Down
78 changes: 39 additions & 39 deletions storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,45 +1257,6 @@ func TestAWSLogLevel(t *testing.T) {
}
}

func valueAtPath(i interface{}, s string) interface{} {
v, err := awsutil.ValuesAtPath(i, s)
if err != nil || len(v) == 0 {
return nil
}
if _, ok := v[0].(io.Reader); ok {
return v[0]
}

if rv := reflect.ValueOf(v[0]); rv.Kind() == reflect.Ptr {
return rv.Elem().Interface()
}

return v[0]
}

// tempError is a wrapper error type that implements anonymous
// interface getting checked in url.Error.Temporary;
//
// interface { Temporary() bool }
//
// see: https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/url/url.go#L38-L43
//
// AWS SDK checks if the underlying error in received url.Error implements it;
// see: https://github.com/aws/aws-sdk-go/blob/b8fe768e4ce7f8f7c002bd7b27f4f5a8723fb1a5/aws/request/retryer.go#L191-L208
//
// It's used to mimic errors like tls.permanentError that would
// be received in a url.Error when the connection timed out.
type tempError struct {
err error
temp bool
}

func (e tempError) Error() string { return e.err.Error() }

func (e tempError) Temporary() bool { return e.temp }

func (e *tempError) Unwrap() error { return e.err }

func TestS3HeadObject(t *testing.T) {
testcases := []struct {
name string
Expand Down Expand Up @@ -1350,3 +1311,42 @@ func TestS3HeadObject(t *testing.T) {
})
}
}

func valueAtPath(i interface{}, s string) interface{} {
v, err := awsutil.ValuesAtPath(i, s)
if err != nil || len(v) == 0 {
return nil
}
if _, ok := v[0].(io.Reader); ok {
return v[0]
}

if rv := reflect.ValueOf(v[0]); rv.Kind() == reflect.Ptr {
return rv.Elem().Interface()
}

return v[0]
}

// tempError is a wrapper error type that implements anonymous
// interface getting checked in url.Error.Temporary;
//
// interface { Temporary() bool }
//
// see: https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/url/url.go#L38-L43
//
// AWS SDK checks if the underlying error in received url.Error implements it;
// see: https://github.com/aws/aws-sdk-go/blob/b8fe768e4ce7f8f7c002bd7b27f4f5a8723fb1a5/aws/request/retryer.go#L191-L208
//
// It's used to mimic errors like tls.permanentError that would
// be received in a url.Error when the connection timed out.
type tempError struct {
err error
temp bool
}

func (e tempError) Error() string { return e.err.Error() }

func (e tempError) Temporary() bool { return e.temp }

func (e *tempError) Unwrap() error { return e.err }

0 comments on commit 6cdc4f6

Please sign in to comment.