featurebase/server/config_test.go
2022-01-21 10:57:05 -07:00

43 lines
896 B
Go

// Copyright 2021 Molecula Corp. All rights reserved.
package server_test
import (
"reflect"
"testing"
"time"
"github.com/molecula/featurebase/v3/server"
"github.com/molecula/featurebase/v3/toml"
)
func Test_ValidateConfig(t *testing.T) {
c := server.NewConfig()
c.MustValidate()
}
func TestDuration(t *testing.T) {
d := toml.Duration(time.Second * 182)
if d.String() != "3m2s" {
t.Fatalf("Unexpected time Duration %s", d)
}
b := []byte{51, 109, 50, 115}
v, _ := d.MarshalText()
if !reflect.DeepEqual(b, v) {
t.Fatalf("Unexpected marshalled value %v", v)
}
v, _ = d.MarshalTOML()
if !reflect.DeepEqual(b, v) {
t.Fatalf("Unexpected marshalled value %v", v)
}
err := d.UnmarshalText([]byte("3m2s"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
v, _ = d.MarshalText()
if !reflect.DeepEqual(b, v) {
t.Fatalf("Unexpected marshalled value %v", v)
}
}