aboutsummaryrefslogtreecommitdiffsponsor
path: root/internal/service/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/service/config_test.go')
-rw-r--r--internal/service/config_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/service/config_test.go b/internal/service/config_test.go
new file mode 100644
index 0000000..c9af1e7
--- /dev/null
+++ b/internal/service/config_test.go
@@ -0,0 +1,54 @@
+package service
+
+import (
+ "encoding/json"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestDurationMarshal(t *testing.T) {
+ tests := []struct {
+ arg Duration
+ exp string
+ }{
+ {
+ Duration{time.Second},
+ "\"1s\"",
+ },
+ {
+ Duration{time.Minute},
+ "\"1m0s\"",
+ },
+ }
+
+ for _, test := range tests {
+ v, err := json.Marshal(test.arg)
+ require.NoError(t, err)
+ require.Equal(t, test.exp, string(v))
+ }
+}
+
+func TestDurationUnmarshal(t *testing.T) {
+ tests := []struct {
+ arg string
+ exp Duration
+ }{
+ {
+ "\"1s\"",
+ Duration{time.Second},
+ },
+ {
+ "\"1m0s\"",
+ Duration{time.Minute},
+ },
+ }
+
+ for _, test := range tests {
+ var v Duration
+ err := json.Unmarshal([]byte(test.arg), &v)
+ require.NoError(t, err)
+ require.Equal(t, test.exp.Duration, v.Duration)
+ }
+}