test.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. require "bundler/setup"
  10. require "pg"
  11. require "test/unit"
  12. class MaterializeTest < Test::Unit::TestCase
  13. def connect
  14. PG.connect(
  15. host: ENV["PGHOST"] || "localhost",
  16. port: (ENV["PGPORT"] || 6875).to_i,
  17. dbname: ENV["PGDATABASE"] || "materialize",
  18. user: ENV["PGUSER"] || "materialize",
  19. )
  20. end
  21. def test_type_map_all_strings
  22. conn = connect
  23. conn.exec("VALUES ('a'::text, 1::integer, '2023-01-01T01:23:45'::timestamp), ('b', NULL, NULL) ORDER BY 1") do |result|
  24. assert_equal(result.collect.to_a, [
  25. {"column1" => "a", "column2" => "1", "column3" => "2023-01-01 01:23:45"},
  26. {"column1" => "b", "column2" => nil, "column3" => nil}
  27. ])
  28. end
  29. end
  30. def test_type_map_basic_type_map
  31. conn = connect
  32. conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn)
  33. conn.exec("VALUES ('a'::text, 1::integer, '2023-01-01T01:23:45'::timestamp), ('b', NULL, NULL) ORDER BY 1") do |result|
  34. assert_equal(result.collect.to_a, [
  35. {"column1" => "a", "column2" => 1, "column3" => Time.new(2023, 1, 1, 1, 23, 45)},
  36. {"column1" => "b", "column2" => nil, "column3" => nil}
  37. ])
  38. end
  39. end
  40. end