@@ -2,6 +2,7 @@ package uuid
2
2
3
3
import (
4
4
"testing"
5
+ "time"
5
6
6
7
"github.com/google/uuid"
7
8
@@ -106,7 +107,26 @@ func Test_generate(t *testing.T) {
106
107
t .Error ("want error" )
107
108
}
108
109
109
- hash := []struct {
110
+ var tstamp time.Time
111
+ var version uuid.Version
112
+ err = db .QueryRow (`
113
+ SELECT
114
+ column1,
115
+ uuid_extract_version(column1),
116
+ uuid_extract_timestamp(column1)
117
+ FROM (VALUES (uuid(7)))
118
+ ` ).Scan (& u , & version , & tstamp )
119
+ if err != nil {
120
+ t .Fatal (err )
121
+ }
122
+ if got := u .Version (); got != version {
123
+ t .Errorf ("got %d, want %d" , got , version )
124
+ }
125
+ if got := time .Unix (u .Time ().UnixTime ()); ! got .Equal (tstamp ) {
126
+ t .Errorf ("got %v, want %v" , got , tstamp )
127
+ }
128
+
129
+ tests := []struct {
110
130
ver uuid.Version
111
131
ns any
112
132
data string
@@ -120,7 +140,7 @@ func Test_generate(t *testing.T) {
120
140
{3 , "url" , "https://www.php.net" , uuid .MustParse ("3f703955-aaba-3e70-a3cb-baff6aa3b28f" )},
121
141
{5 , "url" , "https://www.php.net" , uuid .MustParse ("a8f6ae40-d8a7-58f0-be05-a22f94eca9ec" )},
122
142
}
123
- for _ , tt := range hash {
143
+ for _ , tt := range tests {
124
144
err = db .QueryRow (`SELECT uuid(?, ?, ?)` , tt .ver , tt .ns , tt .data ).Scan (& u )
125
145
if err != nil {
126
146
t .Fatal (err )
@@ -142,14 +162,14 @@ func Test_convert(t *testing.T) {
142
162
defer db .Close ()
143
163
144
164
var u uuid.UUID
145
- lits := []string {
165
+ tests := []string {
146
166
"'6ba7b8119dad11d180b400c04fd430c8'" ,
147
167
"'6ba7b811-9dad-11d1-80b4-00c04fd430c8'" ,
148
168
"'{6ba7b811-9dad-11d1-80b4-00c04fd430c8}'" ,
149
169
"X'6ba7b8119dad11d180b400c04fd430c8'" ,
150
170
}
151
171
152
- for _ , tt := range lits {
172
+ for _ , tt := range tests {
153
173
err = db .QueryRow (`SELECT uuid_str(` + tt + `)` ).Scan (& u )
154
174
if err != nil {
155
175
t .Fatal (err )
@@ -159,7 +179,7 @@ func Test_convert(t *testing.T) {
159
179
}
160
180
}
161
181
162
- for _ , tt := range lits {
182
+ for _ , tt := range tests {
163
183
err = db .QueryRow (`SELECT uuid_blob(` + tt + `)` ).Scan (& u )
164
184
if err != nil {
165
185
t .Fatal (err )
@@ -178,4 +198,14 @@ func Test_convert(t *testing.T) {
178
198
if err == nil {
179
199
t .Fatal ("want error" )
180
200
}
201
+
202
+ err = db .QueryRow (`SELECT uuid_extract_version(X'cafe')` ).Scan (& u )
203
+ if err == nil {
204
+ t .Fatal ("want error" )
205
+ }
206
+
207
+ err = db .QueryRow (`SELECT uuid_extract_timestamp(X'cafe')` ).Scan (& u )
208
+ if err == nil {
209
+ t .Fatal ("want error" )
210
+ }
181
211
}
0 commit comments