MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestEncodeDecodeUUID

Function TestEncodeDecodeUUID

server/types_test.go:1164–1210  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1162}
1163
1164func TestEncodeDecodeUUID(t *testing.T) {
1165 // Test encoding from []byte (DuckDB scan type)
1166 rawBytes := []byte{0xa0, 0xee, 0xbc, 0x99, 0x9c, 0x0b, 0x4e, 0xf8, 0xbb, 0x6d, 0x6b, 0xb9, 0xbd, 0x38, 0x0a, 0x11}
1167 encoded := encodeUUID(rawBytes)
1168 if len(encoded) != 16 {
1169 t.Fatalf("encodeUUID([]byte) length = %d, want 16", len(encoded))
1170 }
1171 for i, b := range rawBytes {
1172 if encoded[i] != b {
1173 t.Errorf("encodeUUID([]byte)[%d] = %02x, want %02x", i, encoded[i], b)
1174 }
1175 }
1176
1177 // Test encoding from string
1178 encoded2 := encodeUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
1179 if len(encoded2) != 16 {
1180 t.Fatalf("encodeUUID(string) length = %d, want 16", len(encoded2))
1181 }
1182 for i, b := range rawBytes {
1183 if encoded2[i] != b {
1184 t.Errorf("encodeUUID(string)[%d] = %02x, want %02x", i, encoded2[i], b)
1185 }
1186 }
1187
1188 // Test decode round-trip
1189 decoded, err := decodeUUID(encoded)
1190 if err != nil {
1191 t.Fatalf("decodeUUID error: %v", err)
1192 }
1193 if decoded != "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" {
1194 t.Errorf("decodeUUID = %q, want %q", decoded, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
1195 }
1196
1197 // Test invalid lengths
1198 if _, err := decodeUUID([]byte{1, 2, 3}); err == nil {
1199 t.Error("decodeUUID(3 bytes) should error")
1200 }
1201 if result := encodeUUID([]byte{1, 2, 3}); result != nil {
1202 t.Error("encodeUUID(3 bytes) should return nil")
1203 }
1204 if result := encodeUUID("not-a-uuid"); result != nil {
1205 t.Error("encodeUUID(invalid string) should return nil")
1206 }
1207 if result := encodeUUID(12345); result != nil {
1208 t.Error("encodeUUID(int) should return nil")
1209 }
1210}
1211
1212func TestEncodeDecodeTime(t *testing.T) {
1213 tests := []struct {

Callers

nothing calls this directly

Calls 3

encodeUUIDFunction · 0.85
decodeUUIDFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected