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

Function TestProtocolDataTypes

tests/integration/protocol_test.go:391–474  ·  view source on GitHub ↗

TestProtocolDataTypes tests that various data types are correctly transmitted

(t *testing.T)

Source from the content-addressed store, hash-verified

389
390// TestProtocolDataTypes tests that various data types are correctly transmitted
391func TestProtocolDataTypes(t *testing.T) {
392 t.Run("integer", func(t *testing.T) {
393 var val int64
394 err := testHarness.DuckgresDB.QueryRow("SELECT 9223372036854775807").Scan(&val)
395 if err != nil {
396 t.Fatalf("Query failed: %v", err)
397 }
398 if val != 9223372036854775807 {
399 t.Errorf("Expected 9223372036854775807, got %d", val)
400 }
401 })
402
403 t.Run("float", func(t *testing.T) {
404 var val float64
405 err := testHarness.DuckgresDB.QueryRow("SELECT 3.14159265358979::DOUBLE PRECISION").Scan(&val)
406 if err != nil {
407 t.Fatalf("Query failed: %v", err)
408 }
409 if val < 3.14 || val > 3.15 {
410 t.Errorf("Expected ~3.14, got %f", val)
411 }
412 })
413
414 t.Run("boolean_true", func(t *testing.T) {
415 var val bool
416 err := testHarness.DuckgresDB.QueryRow("SELECT TRUE").Scan(&val)
417 if err != nil {
418 t.Fatalf("Query failed: %v", err)
419 }
420 if !val {
421 t.Error("Expected true")
422 }
423 })
424
425 t.Run("boolean_false", func(t *testing.T) {
426 var val bool
427 err := testHarness.DuckgresDB.QueryRow("SELECT FALSE").Scan(&val)
428 if err != nil {
429 t.Fatalf("Query failed: %v", err)
430 }
431 if val {
432 t.Error("Expected false")
433 }
434 })
435
436 t.Run("text", func(t *testing.T) {
437 var val string
438 err := testHarness.DuckgresDB.QueryRow("SELECT 'hello, world!'::TEXT").Scan(&val)
439 if err != nil {
440 t.Fatalf("Query failed: %v", err)
441 }
442 if val != "hello, world!" {
443 t.Errorf("Expected 'hello, world!', got %q", val)
444 }
445 })
446
447 t.Run("bytes", func(t *testing.T) {
448 skipIfKnown(t)

Callers

nothing calls this directly

Calls 4

skipIfKnownFunction · 0.85
RunMethod · 0.65
ScanMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected