Skip to content

Commit

Permalink
test/lang: add ruby language tests
Browse files Browse the repository at this point in the history
To ensure that type mapping with the pg gem works as desired.
  • Loading branch information
benesch committed Nov 11, 2023
1 parent 9ca2580 commit 7a8aa17
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ copyright_files=$(grep -vE \
-e '(^|/)Cargo\.lock$' \
-e '^about\.toml$' \
-e '^deny\.toml$' \
-e '(^|/)Gemfile\.lock$' \
-e '^netlify\.toml$' \
-e '^rustfmt\.toml$' \
-e '^clippy\.toml$' \
Expand Down
12 changes: 12 additions & 0 deletions ci/test/pipeline.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ steps:
agents:
queue: linux-x86_64

- id: lang-ruby
label: ":ruby: tests"
depends_on: build-x86_64
timeout_in_minutes: 10
inputs: [test/lang/ruby]
artifact_paths: junit_*.xml
plugins:
- ./ci/plugins/mzcompose:
composition: ruby
agents:
queue: linux-x86_64

- id: deploy-website
label: Deploy website
depends_on: lint-docs
Expand Down
6 changes: 2 additions & 4 deletions src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5011,14 +5011,12 @@ mod tests {
Some(pgmeta) => (pgmeta.typinput_oid, pgmeta.typreceive_oid),
};
assert_eq!(
typinput_oid,
pg_ty.input,
typinput_oid, pg_ty.input,
"type {} has typinput OID {:?} in mz but {:?} in pg",
ty.name, typinput_oid, pg_ty.input,
);
assert_eq!(
typreceive_oid,
pg_ty.receive,
typreceive_oid, pg_ty.receive,
"type {} has typreceive OID {:?} in mz but {:?} in pg",
ty.name, typreceive_oid, pg_ty.receive,
);
Expand Down
2 changes: 2 additions & 0 deletions test/lang/ruby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle
vendor
3 changes: 3 additions & 0 deletions test/lang/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"
gem "pg", "~> 1.5.4"
gem "test-unit", "~> 3.6.1"
18 changes: 18 additions & 0 deletions test/lang/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
pg (1.5.4)
power_assert (2.0.3)
test-unit (3.6.1)
power_assert

PLATFORMS
aarch64-linux
arm64-darwin-22

DEPENDENCIES
pg (~> 1.5.4)
test-unit (~> 3.6.1)

BUNDLED WITH
2.4.10
14 changes: 14 additions & 0 deletions test/lang/ruby/mzcompose
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# mzcompose — runs Docker Compose with Materialize customizations.

exec "$(dirname "$0")"/../../../bin/pyactivate -m materialize.cli.mzcompose "$@"
32 changes: 32 additions & 0 deletions test/lang/ruby/mzcompose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

from materialize.mzcompose.composition import Composition, Service
from materialize.mzcompose.services.materialized import Materialized

SERVICES = [
Materialized(),
Service(
name="ruby",
config={
"image": "ruby:3.2.2-bookworm",
"volumes": [
"../../../:/workdir",
],
"environment": [
"PGHOST=materialized",
],
},
),
]


def workflow_default(c: Composition) -> None:
c.up("materialized")
c.run("ruby", "/workdir/test/lang/ruby/test.sh")
45 changes: 45 additions & 0 deletions test/lang/ruby/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

require "bundler/setup"
require "pg"
require "test/unit"


class MaterializeTest < Test::Unit::TestCase
def connect
PG.connect(
host: ENV["PGHOST"] || "localhost",
port: (ENV["PGPORT"] || 6875).to_i,
dbname: ENV["PGDATABASE"] || "materialize",
user: ENV["PGUSER"] || "materialize",
)
end

def test_type_map_all_strings
conn = connect
conn.exec("VALUES ('a'::text, 1::integer, '2023-01-01T01:23:45'::timestamp), ('b', NULL, NULL) ORDER BY 1") do |result|
assert_equal(result.collect.to_a, [
{"column1" => "a", "column2" => "1", "column3" => "2023-01-01 01:23:45"},
{"column1" => "b", "column2" => nil, "column3" => nil}
])
end
end

def test_type_map_basic_type_map
conn = connect
conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn)
conn.exec("VALUES ('a'::text, 1::integer, '2023-01-01T01:23:45'::timestamp), ('b', NULL, NULL) ORDER BY 1") do |result|
assert_equal(result.collect.to_a, [
{"column1" => "a", "column2" => 1, "column3" => Time.new(2023, 1, 1, 1, 23, 45)},
{"column1" => "b", "column2" => nil, "column3" => nil}
])
end
end
end
26 changes: 26 additions & 0 deletions test/lang/ruby/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# test.sh — run Ruby language tests.

set -euo pipefail

cd "$(dirname "$0")/../../.."

. misc/shlib/shlib.bash

cd test/lang/ruby

bundle install

try ruby test.rb

try_status_report

0 comments on commit 7a8aa17

Please sign in to comment.