influxdb/snowflake/id_test.go

28 lines
475 B
Go
Raw Normal View History

package snowflake
import (
2018-08-01 18:54:32 +00:00
"bytes"
"testing"
"github.com/influxdata/platform"
)
2018-08-01 18:54:32 +00:00
func TestIDLength(t *testing.T) {
gen := NewIDGenerator()
id := gen.ID()
2018-08-01 18:54:32 +00:00
if len(id) != 8 {
t.Fail()
}
}
func TestToFromString(t *testing.T) {
gen := NewIDGenerator()
id := gen.ID()
var clone platform.ID
if err := clone.DecodeFromString(id.String()); err != nil {
t.Error(err)
2018-08-01 18:54:32 +00:00
} else if !bytes.Equal(id, clone) {
t.Errorf("id started as %x but got back %x", id, clone)
}
}