2022-04-20 06:58:21 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
2022-06-21 19:14:29 +02:00
|
|
|
#[cfg(feature = "database")]
|
2022-04-20 06:58:21 +02:00
|
|
|
#[test]
|
|
|
|
fn can_query_single_table() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.db
|
2022-06-21 19:14:29 +02:00
|
|
|
| into db
|
|
|
|
| query "select * from strings"
|
2022-04-20 06:58:21 +02:00
|
|
|
| where x =~ ell
|
|
|
|
| length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "4");
|
|
|
|
}
|
|
|
|
|
2022-06-21 19:14:29 +02:00
|
|
|
#[cfg(feature = "database")]
|
2022-04-20 06:58:21 +02:00
|
|
|
#[test]
|
|
|
|
fn invalid_sql_fails() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.db
|
2022-06-21 19:14:29 +02:00
|
|
|
| into db
|
|
|
|
| query "select *asdfasdf"
|
2022-04-20 06:58:21 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("syntax error"));
|
|
|
|
}
|
|
|
|
|
2022-06-21 19:14:29 +02:00
|
|
|
#[cfg(feature = "database")]
|
2022-04-20 06:58:21 +02:00
|
|
|
#[test]
|
|
|
|
fn invalid_input_fails() {
|
|
|
|
let actual = nu!(
|
2022-04-24 11:29:21 +02:00
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
2022-04-20 06:58:21 +02:00
|
|
|
r#"
|
2022-06-21 19:14:29 +02:00
|
|
|
"foo" | into db | query "select * from asdf"
|
2022-04-20 06:58:21 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-04-24 11:29:21 +02:00
|
|
|
assert!(actual.err.contains("can't convert string"));
|
2022-04-20 06:58:21 +02:00
|
|
|
}
|