Skip to content
Merged
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
33 changes: 33 additions & 0 deletions duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ func ExampleHumanDuration() {
fmt.Println(HumanDuration(24 * 30 * 24 * time.Hour))
fmt.Println(HumanDuration(24*30*24*time.Hour + 2*7*24*time.Hour))
fmt.Println(HumanDuration(3*365*24*time.Hour + 2*30*24*time.Hour))

// Output:
// Less than a second
// 47 seconds
// About a minute
// 3 minutes
// 35 minutes
// 35 minutes
// About an hour
// 2 hours
// 3 hours
// 4 hours
// 4 hours
// 24 hours
// 36 hours
// 2 days
// 7 days
// 13 days
// 2 weeks
// 2 weeks
// 3 weeks
// 4 weeks
// 4 weeks
// 4 weeks
// 6 weeks
// 2 months
// 3 months
// 5 months
// 13 months
// 23 months
// 24 months
// 2 years
// 3 years
}

func TestHumanDuration(t *testing.T) {
Expand Down
57 changes: 55 additions & 2 deletions size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ func ExampleBytesSize() {
fmt.Println(BytesSize(3.42 * GiB))
fmt.Println(BytesSize(5.372 * TiB))
fmt.Println(BytesSize(2.22 * PiB))

// Output:
// 1KiB
// 1MiB
// 1MiB
// 2MiB
// 3.42GiB
// 5.372TiB
// 2.22PiB
}

func ExampleHumanSize() {
Expand All @@ -27,6 +36,16 @@ func ExampleHumanSize() {
fmt.Println(HumanSize(float64(3.42 * GB)))
fmt.Println(HumanSize(float64(5.372 * TB)))
fmt.Println(HumanSize(float64(2.22 * PB)))

// Output:
// 1kB
// 1.024kB
// 1MB
// 1.049MB
// 2MB
// 3.42GB
// 5.372TB
// 2.22PB
}

func ExampleFromHumanSize() {
Expand All @@ -41,6 +60,19 @@ func ExampleFromHumanSize() {
fmt.Println(FromHumanSize("32Gb"))
fmt.Println(FromHumanSize("32Tb"))
fmt.Println(FromHumanSize("32Pb"))

// Output:
// 32 <nil>
// 32 <nil>
// 32 <nil>
// 32000 <nil>
// 32000 <nil>
// 32000 <nil>
// 32000 <nil>
// 32000000 <nil>
// 32000000000 <nil>
// 32000000000000 <nil>
// 32000000000000000 <nil>
}

func ExampleRAMInBytes() {
Expand All @@ -57,6 +89,21 @@ func ExampleRAMInBytes() {
fmt.Println(RAMInBytes("32Pb"))
fmt.Println(RAMInBytes("32PB"))
fmt.Println(RAMInBytes("32P"))

// Output:
// 32 <nil>
// 32 <nil>
// 32 <nil>
// 32768 <nil>
// 32768 <nil>
// 32768 <nil>
// 32768 <nil>
// 33554432 <nil>
// 34359738368 <nil>
// 35184372088832 <nil>
// 36028797018963968 <nil>
// 36028797018963968 <nil>
// 36028797018963968 <nil>
}

func TestBytesSize(t *testing.T) {
Expand Down Expand Up @@ -197,8 +244,14 @@ func BenchmarkParseSize(b *testing.B) {
"", "32", "32b", "32 B", "32k", "32.5 K", "32kb", "32 Kb",
"32.8Mb", "32.9Gb", "32.777Tb", "32Pb", "0.3Mb", "-1",
} {
FromHumanSize(s)
RAMInBytes(s)
_, err := FromHumanSize(s)
if err != nil {
b.Fatal(err)
}
_, err = RAMInBytes(s)
if err != nil {
b.Fatal(err)
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions ulimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ func ExampleParseUlimit() {
fmt.Println(ParseUlimit("nofile=1024"))
fmt.Println(ParseUlimit("cpu=2:4"))
fmt.Println(ParseUlimit("cpu=6"))

// Output:
// nofile=512:1024 <nil>
// nofile=1024:1024 <nil>
// cpu=2:4 <nil>
// cpu=6:6 <nil>
}

func TestParseUlimitValid(t *testing.T) {
Expand Down