1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-02 22:21:19 +00:00
v2fly/infra/conf/duration_test.go
2021-09-04 11:12:04 +01:00

34 lines
628 B
Go

package conf_test
import (
"encoding/json"
"testing"
"time"
"github.com/v2fly/v2ray-core/v4/infra/conf"
)
type testWithDuration struct {
Duration conf.Duration
}
func TestDurationJSON(t *testing.T) {
expected := &testWithDuration{
Duration: conf.Duration(time.Hour),
}
data, err := json.Marshal(expected)
if err != nil {
t.Error(err)
return
}
actual := &testWithDuration{}
err = json.Unmarshal(data, &actual)
if err != nil {
t.Error(err)
return
}
if actual.Duration != expected.Duration {
t.Errorf("expected: %s, actual: %s", time.Duration(expected.Duration), time.Duration(actual.Duration))
}
}