MCPcopy
hub / github.com/google/uuid / TestScan

Function TestScan

sql_test.go:12–104  ·  sql_test.go::TestScan
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestScan(t *testing.T) {
13 stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
14 badTypeTest := 6
15 invalidTest := "f47ac10b-58cc-0372-8567-0e02b2c3d4"
16
17 byteTest := make([]byte, 16)
18 byteTestUUID := MustParse(stringTest)
19 copy(byteTest, byteTestUUID[:])
20
21 // sunny day tests
22
23 var uuid UUID
24 err := (&uuid).Scan(stringTest)
25 if err != nil {
26 t.Fatal(err)
27 }
28
29 err = (&uuid).Scan([]byte(stringTest))
30 if err != nil {
31 t.Fatal(err)
32 }
33
34 err = (&uuid).Scan(byteTest)
35 if err != nil {
36 t.Fatal(err)
37 }
38
39 // bad type tests
40
41 err = (&uuid).Scan(badTypeTest)
42 if err == nil {
43 t.Error("int correctly parsed and shouldn't have")
44 }
45 if !strings.Contains(err.Error(), "unable to scan type") {
46 t.Error("attempting to parse an int returned an incorrect error message")
47 }
48
49 // invalid/incomplete uuids
50
51 err = (&uuid).Scan(invalidTest)
52 if err == nil {
53 t.Error("invalid uuid was parsed without error")
54 }
55 if !strings.Contains(err.Error(), "invalid UUID") {
56 t.Error("attempting to parse an invalid UUID returned an incorrect error message")
57 }
58
59 err = (&uuid).Scan(byteTest[:len(byteTest)-2])
60 if err == nil {
61 t.Error("invalid byte uuid was parsed without error")
62 }
63 if !strings.Contains(err.Error(), "invalid UUID") {
64 t.Error("attempting to parse an invalid byte UUID returned an incorrect error message")
65 }
66
67 // empty tests
68
69 uuid = UUID{}

Callers

nothing calls this directly

Calls 3

MustParseFunction · 0.85
ScanMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected