surrealpatch/util/uuid/uuid_test.go

73 lines
1.7 KiB
Go
Raw Normal View History

2016-03-15 12:17:30 +00:00
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-05-17 21:35:36 +00:00
package uuid
2016-03-15 12:17:30 +00:00
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
2017-11-27 11:34:59 +00:00
func TestNew(t *testing.T) {
2016-03-15 12:17:30 +00:00
2016-05-17 21:35:36 +00:00
var str *UUID
2016-03-15 12:17:30 +00:00
2017-11-27 11:34:59 +00:00
str = New()
2016-03-15 12:17:30 +00:00
Convey(str.String(), t, func() {
Convey("Should be a UUID", func() {
2016-05-17 21:35:36 +00:00
So(str, ShouldHaveSameTypeAs, &UUID{})
2016-03-15 12:17:30 +00:00
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
})
}
func TestParsing(t *testing.T) {
2016-05-17 21:35:36 +00:00
var str *UUID
2016-03-15 12:17:30 +00:00
str = Parse("thiswill-notbe-parsed-as-successful")
2016-03-15 12:17:30 +00:00
Convey("Parse thiswill-notbe-parsed-as-successful", t, func() {
Convey("Should be nil", func() {
So(str, ShouldBeNil)
2016-03-15 12:17:30 +00:00
})
})
str = Parse("1400A118-2749-4605-833C-E7437488BCBF")
2016-03-15 12:17:30 +00:00
Convey("Parse 1400A118-2749-4605-833C-E7437488BCBF", t, func() {
2016-03-15 12:17:30 +00:00
Convey("Should be a UUID", func() {
2016-05-17 21:35:36 +00:00
So(str, ShouldHaveSameTypeAs, &UUID{})
2016-03-15 12:17:30 +00:00
})
Convey("Should not be nil", func() {
So(str, ShouldNotBeNil)
})
Convey("Should be of length 36", func() {
So(str.String(), ShouldHaveLength, 36)
})
Convey("Should be exactly `1400a118-2749-4605-833c-e7437488bcbf`", func() {
So(str.String(), ShouldEqual, "1400a118-2749-4605-833c-e7437488bcbf")
})
})
}