mirror

Mirror free and open-source projects you like with minimal effort
git clone git://git.server.ky/slackcoder/mirror
Log | Files | Refs | README

config_test.go (810B)


      1 package service
      2 
      3 import (
      4 	"encoding/json"
      5 	"testing"
      6 	"time"
      7 
      8 	"github.com/stretchr/testify/require"
      9 )
     10 
     11 func TestDurationMarshal(t *testing.T) {
     12 	tests := []struct {
     13 		arg Duration
     14 		exp string
     15 	}{
     16 		{
     17 			Duration{time.Second},
     18 			"\"1s\"",
     19 		},
     20 		{
     21 			Duration{time.Minute},
     22 			"\"1m0s\"",
     23 		},
     24 	}
     25 
     26 	for _, test := range tests {
     27 		v, err := json.Marshal(test.arg)
     28 		require.NoError(t, err)
     29 		require.Equal(t, test.exp, string(v))
     30 	}
     31 }
     32 
     33 func TestDurationUnmarshal(t *testing.T) {
     34 	tests := []struct {
     35 		arg string
     36 		exp Duration
     37 	}{
     38 		{
     39 			"\"1s\"",
     40 			Duration{time.Second},
     41 		},
     42 		{
     43 			"\"1m0s\"",
     44 			Duration{time.Minute},
     45 		},
     46 	}
     47 
     48 	for _, test := range tests {
     49 		var v Duration
     50 		err := json.Unmarshal([]byte(test.arg), &v)
     51 		require.NoError(t, err)
     52 		require.Equal(t, test.exp.Duration, v.Duration)
     53 	}
     54 }