mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Added Duration tests
This commit is contained in:
parent
4b53ec1f9c
commit
cfedda29ef
3 changed files with 38 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue