Skip to content

Commit

Permalink
OIJOIJOJOIJ
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed May 8, 2024
1 parent 723aa27 commit 78c9362
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/validation-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:
name: Rust Validation

env:
RUSTDOCFLAGS: -D warnings
RUSTFLAGS: -D warnings -C debuginfo=1
# RUSTDOCFLAGS: -D warnings
# RUSTFLAGS: -D warnings -C debuginfo=1
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions udf-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ generic-array = "1.0.0"
sha2 = "0.10.8"
udf = { path = "../udf", features = ["mock", "logging-debug"] }
uuid = { version = "1.8.0", features = ["v1", "v3", "v4", "v5", "fast-rng"] }
mysql = "25.0.0"

[dev-dependencies]
diesel = { version = "2.1.6", default-features = false, features = ["mysql"] }
lazy_static = "1.4.0"
mysql = "25.0.0"

[features]
# Used to optionally enable integration tests
Expand Down
31 changes: 15 additions & 16 deletions udf-examples/tests/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
mod backend;

use backend::get_db_connection;
use diesel::dsl::sql;
use diesel::prelude::*;
use diesel::sql_types::Text;
use mysql::prelude::*;

const SETUP: &[&str] = &[
"create or replace function udf_attribute
Expand All @@ -22,18 +20,19 @@ const SETUP: &[&str] = &[
"insert into test_attribute (val) values (2)",
];

// #[test]
// fn test_basic() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_basic() {
let conn = &mut get_db_connection(&SETUP);

// let res: String =
// sql::<Text>("select udf_attribute(1, 'string', val, 3.2) from test_attribute")
// .get_result(conn)
// .expect("bad result");
// assert_eq!(res, "1, 'string', val, 3.2");
let res: String = conn
.query_first("select udf_attribute(1, 'string', val, 3.2) from test_attribute")
.unwrap()
.unwrap();
assert_eq!(res, "1, 'string', val, 3.2");

// let res: String = sql::<Text>("select attr(1, 'string', val, 3.2) from test_attribute")
// .get_result(conn)
// .expect("bad result");
// assert_eq!(res, "1, 'string', val, 3.2");
// }
let res: String = conn
.query_first("select attr(1, 'string', val, 3.2) from test_attribute")
.unwrap()
.unwrap();
assert_eq!(res, "1, 'string', val, 3.2");
}
1 change: 0 additions & 1 deletion udf-examples/tests/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::collections::HashSet;
use std::env;
use std::sync::{Mutex, OnceLock};

use lazy_static::lazy_static;
use mysql::prelude::*;
use mysql::{Pool, PooledConn};

Expand Down
58 changes: 28 additions & 30 deletions udf-examples/tests/is_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
mod backend;

use backend::get_db_connection;
use diesel::dsl::sql;
use diesel::prelude::*;
use diesel::result::Error as DieselError;
use diesel::sql_types::Text;
use mysql::prelude::*;

const SETUP: [&str; 3] = [
const SETUP: &[&str] = &[
"create or replace function is_const
returns string
soname 'libudf_examples.so'",
Expand All @@ -20,37 +17,38 @@ const SETUP: [&str; 3] = [
"insert into test_is_const (val) values (2)",
];

// #[test]
// fn test_true() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_true() {
let conn = &mut get_db_connection(&SETUP);

// let res: String = sql::<Text>("select is_const(1)")
// .get_result(conn)
// .expect("bad result");
let res: String = conn.query_first("select is_const(1)").unwrap().unwrap();

// assert_eq!(res, "const");
// }
assert_eq!(res, "const");
}

// #[test]
// fn test_false() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_false() {
let conn = &mut get_db_connection(&SETUP);

// let res: String = sql::<Text>("select is_const(val) from test_is_const")
// .get_result(conn)
// .expect("bad result");
let res: String = conn
.query_first("select is_const(val) from test_is_const")
.unwrap()
.unwrap();

// assert_eq!(res, "not const");
// }
assert_eq!(res, "not const");
}

// #[test]
// fn test_too_many_args() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_too_many_args() {
let conn = &mut get_db_connection(&SETUP);

// let res = sql::<Text>("select is_const(1, 2)").get_result::<String>(conn);
let res: String = conn.query_first("select is_const(1, 2)").unwrap().unwrap();

// let Err(DieselError::DatabaseError(_, info)) = res else {
// panic!("Got unexpected response: {res:?}");
// };
panic!("{res:?}");

// assert!(info.message().contains("only accepts one argument"));
// }
// let Err(DieselError::DatabaseError(_, info)) = res else {
// panic!("Got unexpected response: {res:?}");
// };

// assert!(info.message().contains("only accepts one argument"));
}
42 changes: 21 additions & 21 deletions udf-examples/tests/lipsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ const SETUP: &[&str] = &["create or replace function lipsum
returns string
soname 'libudf_examples.so'"];

// #[test]
// fn test_short() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_short() {
let conn = &mut get_db_connection(&SETUP);

// let res: Option<String> = conn.query_first("select lipsum(10)").unwrap().unwrap();
let res: Option<String> = conn.query_first("select lipsum(10)").unwrap().unwrap();

// assert!(res.unwrap().split_whitespace().count() == 10);
// }
assert!(res.unwrap().split_whitespace().count() == 10);
}

// #[test]
// fn test_short_seed() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_short_seed() {
let conn = &mut get_db_connection(&SETUP);

// let res: Option<String> = conn
// .query_first("select lipsum(10, 12345)")
// .unwrap()
// .unwrap();
let res: Option<String> = conn
.query_first("select lipsum(10, 12345)")
.unwrap()
.unwrap();

// assert!(res.unwrap().split_whitespace().count() == 10);
// }
assert!(res.unwrap().split_whitespace().count() == 10);
}

// #[test]
// fn test_long() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_long() {
let conn = &mut get_db_connection(&SETUP);

// let res: Option<String> = conn.query_first("select lipsum(5000)").unwrap().unwrap();
// assert!(res.unwrap().split_whitespace().count() == 5000);
// }
let res: Option<String> = conn.query_first("select lipsum(5000)").unwrap().unwrap();
assert!(res.unwrap().split_whitespace().count() == 5000);
}
21 changes: 10 additions & 11 deletions udf-examples/tests/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
mod backend;

use backend::get_db_connection;
use diesel::dsl::sql;
use diesel::prelude::*;
use diesel::sql_types::Integer;
use mysql::prelude::*;

const SETUP: [&str; 3] = [
"create or replace aggregate function udf_median
Expand All @@ -19,13 +17,14 @@ const SETUP: [&str; 3] = [
"insert into test_median (val) values (2), (1), (3), (4), (-3), (7), (-1)",
];

// #[test]
// fn test_empty() {
// let conn = &mut get_db_connection(&SETUP);
#[test]
fn test_empty() {
let conn = &mut get_db_connection(&SETUP);

// let res: i32 = sql::<Integer>("select udf_median(val) from test_median")
// .get_result(conn)
// .expect("bad result");
let res: i32 = conn
.query_first("select udf_median(val) from test_median")
.unwrap()
.unwrap();

// assert_eq!(res, 2);
// }
assert_eq!(res, 2);
}

0 comments on commit 78c9362

Please sign in to comment.