2020-05-14 11:57:26 +02:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-02-22 16:33:33 +01:00
|
|
|
func TestDuration(t *testing.T) {
|
2020-05-14 11:57:26 +02:00
|
|
|
t.Run("empty", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "0s", d.String())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("0", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("0")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "0s", d.String())
|
|
|
|
})
|
|
|
|
|
2023-02-22 16:33:33 +01:00
|
|
|
t.Run("0.5", func(t *testing.T) {
|
|
|
|
d := Duration("0.5")
|
|
|
|
assert.Equal(t, "500ms", d.String())
|
|
|
|
})
|
|
|
|
|
2020-05-14 11:57:26 +02:00
|
|
|
t.Run("2.41 s", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("2.41 s")
|
|
|
|
assert.Equal(t, "2.41s", d.String())
|
2020-05-14 11:57:26 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("0.41 s", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("0.41 s")
|
|
|
|
assert.Equal(t, "410ms", d.String())
|
2020-05-14 11:57:26 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("41 s", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("41 s")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "41s", d.String())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("0:0:1", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("0:0:1")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "1s", d.String())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("0:04:25", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("0:04:25")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "4m25s", d.String())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("0001:04:25", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("0001:04:25")
|
2020-05-14 11:57:26 +02:00
|
|
|
assert.Equal(t, "1h4m25s", d.String())
|
|
|
|
})
|
2021-02-25 16:03:07 +01:00
|
|
|
|
|
|
|
t.Run("invalid", func(t *testing.T) {
|
2023-02-22 16:33:33 +01:00
|
|
|
d := Duration("01:04:25:67")
|
2021-02-25 16:03:07 +01:00
|
|
|
assert.Equal(t, "0s", d.String())
|
|
|
|
})
|
2020-05-14 11:57:26 +02:00
|
|
|
}
|