diff options
author | Keuin <[email protected]> | 2023-07-30 19:04:12 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-30 19:04:12 +0800 |
commit | 3fad4189646cca5d6db99ccfe79be695ef765d03 (patch) | |
tree | 6ab1c57a7a954dfd08afba9d2c4ab582382e0eb0 /common/pretty/duration_test.go | |
parent | d60bdefcabbc7fc0e0bbb690045222896f688f3f (diff) |
Refactor: extract pretty duration to a function. Create `pretty` package for creating human friendly stringsv0.5.1
Diffstat (limited to 'common/pretty/duration_test.go')
-rw-r--r-- | common/pretty/duration_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/common/pretty/duration_test.go b/common/pretty/duration_test.go new file mode 100644 index 0000000..94ea2c5 --- /dev/null +++ b/common/pretty/duration_test.go @@ -0,0 +1,65 @@ +package pretty + +import ( + "testing" + "time" +) + +func TestDuration(t *testing.T) { + type args struct { + duration time.Duration + } + tests := []struct { + name string + args args + want string + }{ + { + name: "zero", + args: args{0}, + want: "00:00:00", + }, + { + name: "1s", + args: args{time.Second}, + want: "00:00:01", + }, + { + name: "2s", + args: args{time.Second * 2}, + want: "00:00:02", + }, + { + name: "59s", + args: args{time.Second * 59}, + want: "00:00:59", + }, + { + name: "1m", + args: args{time.Second * 60}, + want: "00:01:00", + }, + { + name: "1m1s", + args: args{time.Second * 61}, + want: "00:01:01", + }, + { + name: "1h", + args: args{time.Second * 3600}, + want: "01:00:00", + }, + { + name: "54h7m13s", + args: args{time.Hour*54 + time.Minute*7 + time.Second*13}, + want: "54:07:13", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Duration(tt.args.duration); got != tt.want { + t.Errorf("Duration() = %v, want %v", got, tt.want) + } + }) + } +} |