Skip to content

Commit

Permalink
Add tests + fix missing newlines in ndjson
Browse files Browse the repository at this point in the history
  • Loading branch information
n-e committed Mar 20, 2024
1 parent c47553a commit 17bd557
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Push

on:
push:
Expand All @@ -18,23 +18,31 @@ jobs:
platform:
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
command: both

- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04
command: build

- target: aarch64-apple-darwin
os: macos-14
command: build

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Start PG for the tests
run: docker compose up -d
if: ${{ matrix.platform.command == 'both' }}

- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
target: ${{ matrix.platform.target }}
args: "--release"
strip: true
command: ${{ matrix.platform.command }}

- name: Upload binary
uses: actions/upload-artifact@v4
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## (main) - XXXX-XX-XX

- Add tests
- Fix missing newlines in NDJSON

## 0.2.0 - 2024-03-20

- Add linux aarch64 support
Expand Down
101 changes: 101 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
assert_cmd = "2.0.14"
clap = { version = "4.5.3", features = ["derive"] }
native-tls = { version = "0.2.11", features = ["vendored"] }
postgres = "0.19.7"
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn main() -> Result<(), Box<dyn Error>> {
iter.for_each(|row| {
let data: String = row.get(0);
out.write_all(data.as_bytes()).unwrap();
out.write_all(b"\n").unwrap();
Ok(())
})?;

Expand Down
53 changes: 53 additions & 0 deletions tests/extract_json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use assert_cmd::prelude::*;
use std::process::Command;

macro_rules! test_extract_json {
($name: ident, $in: expr, $out: expr) => {
#[test]
fn $name() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("pgextract")?;
let out = cmd
.args([
"extract",
"-u",
"postgres://postgres:example@localhost",
"-f",
"ndjson",
$in,
])
.unwrap();

assert_eq!(String::from_utf8(out.stdout).unwrap(), $out);
Ok(())
}
};
}

test_extract_json!(
two_lines,
"select * from (values ('a'),('b')) as t(col)",
r#"{"col":"a"}
{"col":"b"}
"#
);

test_extract_json!(
text,
"select 'a'::text col",
r#"{"col":"a"}
"#
);

test_extract_json!(
int,
"select 1234::bigint col",
r#"{"col":1234}
"#
);

test_extract_json!(
date,
"select timestamptz '2023-01-01T12:23:45Z' col",
r#"{"col":"2023-01-01T12:23:45+00:00"}
"#
);

0 comments on commit 17bd557

Please sign in to comment.