From cfedda29ef9e634094dcf871bbe5fc47c4a7cdec Mon Sep 17 00:00:00 2001 From: Michael Baird Date: Wed, 12 Jul 2017 09:07:38 -0500 Subject: [PATCH] Added Duration tests --- config.go | 1 + config_test.go | 36 ++++++++++++++++++++++++++++++++++++ fragment_test.go | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 8607c3c86..30c1ebdd3 100644 --- a/config.go +++ b/config.go @@ -153,6 +153,7 @@ func (d Duration) MarshalText() (text []byte, err error) { return []byte(d.String()), nil } +// MarshalTOML write duration into valid TOML. func (d Duration) MarshalTOML() ([]byte, error) { return []byte(d.String()), nil } diff --git a/config_test.go b/config_test.go index 9f7767a4e..78c4a6127 100644 --- a/config_test.go +++ b/config_test.go @@ -1,7 +1,9 @@ package pilosa_test import ( + "reflect" "testing" + "time" "github.com/pilosa/pilosa" ) @@ -49,4 +51,38 @@ func Test_NewConfig(t *testing.T) { if err := c.Validate(); err != pilosa.ErrConfigGossipSeed { t.Fatal(err) } + + c.Cluster.GossipSeed = "localhost:14000" + if err := c.Validate(); err != nil { + t.Fatal(err) + } +} + +func TestDuration(t *testing.T) { + d := pilosa.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("5")) + if err.Error() != "time: missing unit in duration 5" { + t.Fatalf("expected time: missing unit in duration: %s", err) + } + + err = d.UnmarshalText([]byte("3m2s")) + v, _ = d.MarshalText() + if !reflect.DeepEqual(b, v) { + t.Fatalf("Unexpected marshalled value %v", v) + } } diff --git a/fragment_test.go b/fragment_test.go index 74ee91eeb..7ba243e0a 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -497,7 +497,7 @@ func TestFragment_Checksum(t *testing.T) { // Ensure new checksum is different. if chksum := f.Checksum(); bytes.Equal(chksum, orig) { - t.Fatalf("expected checksum to change: %x", chksum, orig) + t.Fatalf("expected checksum to change: %x - %x", chksum, orig) } }