Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ func TestListS3ObjectsWithDashH(t *testing.T) {

putFile(t, s3client, bucket, "testfile1.txt", strings.Repeat("this is a file content", 10000))
putFile(t, s3client, bucket, "testfile2.txt", strings.Repeat("this is also a file content", 10000))
putFile(t, s3client, bucket, "testfile3.txt", "this is a small file")

cmd := s5cmd("ls", "-H", "s3://"+bucket)
result := icmd.RunCmd(cmd)
Expand All @@ -440,6 +441,7 @@ func TestListS3ObjectsWithDashH(t *testing.T) {
assertLines(t, result.Stdout(), map[int]compareFunc{
0: match(`^ 214.8K testfile1.txt$`),
1: match(`^ 263.7K testfile2.txt$`),
2: match(`^ 20B testfile3.txt$`),
}, trimMatch(dateRe), alignment(true))
}

Expand Down
2 changes: 1 addition & 1 deletion strutil/strutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func HumanizeBytes(b int64) string {
}
}
if suffix == "" {
return strconv.FormatInt(b, 10)
return strconv.FormatInt(b, 10) + "B"
}

return fmt.Sprintf("%.1f%s", float64(b)/float64(div), suffix)
Expand Down
26 changes: 26 additions & 0 deletions strutil/strutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ func TestCapitalizeFirstLetter(t *testing.T) {
}
}

func TestHumanizeBytes(t *testing.T) {
tests := []struct {
b int64
want string
}{
{0, "0B"},
{1, "1B"},
{999, "999B"},
{1023, "1023B"},
{1024, "1024B"},
{1025, "1.0K"},
{1536, "1.5K"},
{1 << 20, "1024.0K"},
{(1 << 20) + 1, "1.0M"},
{5 * (1 << 30), "5.0G"},
{3 * (1 << 40), "3.0T"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := HumanizeBytes(tt.b); got != tt.want {
t.Errorf("HumanizeBytes(%d) = %q, want %q", tt.b, got, tt.want)
}
})
}
}

func Test_WildCardToRegexp(t *testing.T) {
t.Parallel()
tests := []struct {
Expand Down
Loading