1 // Copyright 2015 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestScan(t *testing.T) {
13 var stringTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
14 var byteTest []byte = Parse(stringTest)
15 var badTypeTest int = 6
16 var invalidTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d4"
21 err := (&uuid).Scan(stringTest)
26 err = (&uuid).Scan([]byte(stringTest))
31 err = (&uuid).Scan(byteTest)
38 err = (&uuid).Scan(badTypeTest)
40 t.Error("int correctly parsed and shouldn't have")
42 if !strings.Contains(err.Error(), "unable to scan type") {
43 t.Error("attempting to parse an int returned an incorrect error message")
46 // invalid/incomplete uuids
48 err = (&uuid).Scan(invalidTest)
50 t.Error("invalid uuid was parsed without error")
52 if !strings.Contains(err.Error(), "invalid UUID") {
53 t.Error("attempting to parse an invalid UUID returned an incorrect error message")
56 err = (&uuid).Scan(byteTest[:len(byteTest)-2])
58 t.Error("invalid byte uuid was parsed without error")
60 if !strings.Contains(err.Error(), "invalid UUID") {
61 t.Error("attempting to parse an invalid byte UUID returned an incorrect error message")
68 err = (&uuid).Scan(emptySlice)
74 t.Error("UUID was not nil after scanning empty byte slice")
78 var emptyString string
79 err = (&uuid).Scan(emptyString)
85 t.Error("UUID was not nil after scanning empty string")
89 func TestValue(t *testing.T) {
90 stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
91 uuid := Parse(stringTest)
92 val, _ := uuid.Value()
93 if val != stringTest {
94 t.Error("Value() did not return expected string")