Simplify uuid util package

This commit is contained in:
Tobie Morgan Hitchcock 2017-11-27 11:34:59 +00:00
parent cfa573e7cf
commit 7fbc9feff9
5 changed files with 8 additions and 160 deletions

View file

@ -172,7 +172,7 @@ func setup() {
}
if opts.Node.UUID == "" {
opts.Node.UUID = opts.Node.Name + "-" + uuid.NewV4().String()
opts.Node.UUID = opts.Node.Name + "-" + uuid.New().String()
}
// --------------------------------------------------

View file

@ -246,7 +246,7 @@ func (s *socket) executeLive(e *executor, ctx context.Context, stm *sql.LiveStat
// query when sending push messages
// and when killing the query.
stm.ID = uuid.NewV4().String()
stm.ID = uuid.New().String()
// Store the live query on the socket.

View file

@ -15,13 +15,13 @@
package fake
import (
"github.com/satori/go.uuid"
"github.com/abcum/surreal/util/uuid"
)
func Uuid() string {
return uuid.NewV4().String()
return uuid.New().String()
}
func (f *Faker) Uuid() string {
return uuid.NewV4().String()
return uuid.New().String()
}

View file

@ -29,31 +29,11 @@ type UUID struct {
uuid.UUID
}
// NewV1 returns a new UUID (Version 1) based on current timestamp and MAC address.
func NewV1() *UUID {
return &UUID{uuid.NewV1()}
}
// NewV2 returns a new DCE Security UUID (Version 2) based on POSIX UID/GID.
func NewV2(domain byte) *UUID {
return &UUID{uuid.NewV2(domain)}
}
// NewV3 returns a new UUID (Version 3) based on MD5 hash of namespace UUID and name.
func NewV3(ns uuid.UUID, name string) *UUID {
return &UUID{uuid.NewV3(ns, name)}
}
// NewV4 returns a new UUID (Version 4) using 16 random bytes or panics.
func NewV4() *UUID {
func New() *UUID {
return &UUID{uuid.NewV4()}
}
// NewV5 returns a new UUID (Version 5) based on SHA-1 hash of namespace UUID and name.
func NewV5(ns uuid.UUID, name string) *UUID {
return &UUID{uuid.NewV5(ns, name)}
}
// Parse parses and checks for a valid UUID string, and returns nil if not valid.
func Parse(input string) *UUID {
id, err := uuid.FromString(input)

View file

@ -20,11 +20,11 @@ import (
. "github.com/smartystreets/goconvey/convey"
)
func TestNewV1(t *testing.T) {
func TestNew(t *testing.T) {
var str *UUID
str = NewV1()
str = New()
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
@ -33,135 +33,6 @@ func TestNewV1(t *testing.T) {
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 1", func() {
So(str.Version(), ShouldEqual, 1)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
}
func TestNewV2(t *testing.T) {
var str *UUID
str = NewV2(0)
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 2", func() {
So(str.Version(), ShouldEqual, 2)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
}
func TestNewV3(t *testing.T) {
var str *UUID
str = NewV3(NamespaceDNS, "abcum.com")
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 3", func() {
So(str.Version(), ShouldEqual, 3)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
str = NewV3(NamespaceURL, "https://abcum.com")
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 3", func() {
So(str.Version(), ShouldEqual, 3)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
}
func TestNewV4(t *testing.T) {
var str *UUID
str = NewV4()
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 4", func() {
So(str.Version(), ShouldEqual, 4)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
}
func TestNewV5(t *testing.T) {
var str *UUID
str = NewV5(NamespaceDNS, "abcum.com")
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 5", func() {
So(str.Version(), ShouldEqual, 5)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
str = NewV5(NamespaceURL, "https://abcum.com")
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
So(str, ShouldHaveSameTypeAs, &UUID{})
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 5", func() {
So(str.Version(), ShouldEqual, 5)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
@ -190,9 +61,6 @@ func TestParsing(t *testing.T) {
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be version 4", func() {
So(str.Version(), ShouldEqual, 4)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})