Skip to content

Commit

Permalink
Skip geometry and crunchy_map tests if extensions are not available (#73
Browse files Browse the repository at this point in the history
)

Closes #59
  • Loading branch information
aykut-bozkurt authored Nov 9, 2024
1 parent e501587 commit e7f0fbf
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ mod tests {
test_assert(test_result.expected, test_result.result);
}

fn extension_exists(extension_name: &str) -> bool {
let query = format!(
"select count(*) = 1 from pg_available_extensions where name = '{}'",
extension_name
);

Spi::get_one(&query).unwrap().unwrap()
}

#[pg_test]
fn test_int2() {
let test_table = TestTable::<i16>::new("int2".into());
Expand Down Expand Up @@ -687,8 +696,12 @@ mod tests {
}

#[pg_test]
#[ignore = "enable when we install crunchy_map package on CI"]
fn test_map() {
// Skip the test if crunchy_map extension is not available
if !extension_exists("crunchy_map") {
return;
}

Spi::run("DROP EXTENSION IF EXISTS crunchy_map; CREATE EXTENSION crunchy_map;").unwrap();

Spi::run("SELECT crunchy_map.create('int','text');").unwrap();
Expand All @@ -704,8 +717,12 @@ mod tests {
}

#[pg_test]
#[ignore = "enable when we install crunchy_map package on CI"]
fn test_map_array() {
// Skip the test if crunchy_map extension is not available
if !extension_exists("crunchy_map") {
return;
}

Spi::run("DROP EXTENSION IF EXISTS crunchy_map; CREATE EXTENSION crunchy_map;").unwrap();

Spi::run("SELECT crunchy_map.create('int','text');").unwrap();
Expand Down Expand Up @@ -734,9 +751,14 @@ mod tests {

#[pg_test]
#[should_panic(expected = "MapArray entries cannot contain nulls")]
#[ignore = "enable when we install crunchy_map package on CI"]
fn test_map_null_entries() {
Spi::run("CREATE EXTENSION crunchy_map;").unwrap();
// Skip the test if crunchy_map extension is not available
if !extension_exists("crunchy_map") {
// let the test pass
panic!("MapArray entries cannot contain nulls");
}

Spi::run("DROP EXTENSION IF EXISTS crunchy_map; CREATE EXTENSION crunchy_map;").unwrap();

Spi::run("SELECT crunchy_map.create('int','text');").unwrap();

Expand All @@ -755,9 +777,14 @@ mod tests {
#[should_panic(
expected = "Found unmasked nulls for non-nullable StructArray field \\\"key\\\""
)]
#[ignore = "enable when we install crunchy_map package on CI"]
fn test_map_null_entry_key() {
Spi::run("CREATE EXTENSION crunchy_map;").unwrap();
// Skip the test if crunchy_map extension is not available
if !extension_exists("crunchy_map") {
// let the test pass
panic!("Found unmasked nulls for non-nullable StructArray field \\\"key\\\"");
}

Spi::run("DROP EXTENSION IF EXISTS crunchy_map; CREATE EXTENSION crunchy_map;").unwrap();

Spi::run("SELECT crunchy_map.create('int','text');").unwrap();

Expand Down Expand Up @@ -1198,6 +1225,11 @@ mod tests {

#[pg_test]
fn test_geometry() {
// Skip the test if postgis extension is not available
if !extension_exists("postgis") {
return;
}

let query = "DROP EXTENSION IF EXISTS postgis; CREATE EXTENSION postgis;";
Spi::run(query).unwrap();

Expand All @@ -1211,6 +1243,11 @@ mod tests {

#[pg_test]
fn test_geometry_array() {
// Skip the test if postgis extension is not available
if !extension_exists("postgis") {
return;
}

let query = "DROP EXTENSION IF EXISTS postgis; CREATE EXTENSION postgis;";
Spi::run(query).unwrap();

Expand Down

0 comments on commit e7f0fbf

Please sign in to comment.