Add a test for adding and querying UUIDs and instants.

This commit is contained in:
Richard Newman 2017-04-28 12:37:51 -07:00
parent b03e89fb31
commit 4d008925f0
2 changed files with 51 additions and 0 deletions

View file

@ -17,6 +17,7 @@ members = []
rustc_version = "0.1.7"
[dependencies]
chrono = "0.3"
clap = "2.19.3"
error-chain = "0.8.1"
nickel = "0.9.0"

View file

@ -8,15 +8,22 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
extern crate chrono;
extern crate time;
extern crate mentat;
extern crate mentat_core;
extern crate mentat_db;
use std::str::FromStr;
use chrono::FixedOffset;
use mentat_core::{
TypedValue,
ValueType,
UTC,
Uuid,
};
use mentat::{
@ -28,6 +35,8 @@ use mentat::{
q_once,
};
use mentat::conn::Conn;
use mentat::errors::{
Error,
ErrorKind,
@ -204,3 +213,44 @@ fn test_unbound_inputs() {
_ => panic!("Expected unbound variables."),
}
}
#[test]
fn test_instants_and_uuids() {
// We assume, perhaps foolishly, that the clocks on test machines won't lose more than an
// hour while this test is running.
let start = UTC::now() + FixedOffset::west(60 * 60);
let mut c = new_connection("").expect("Couldn't open conn.");
let mut conn = Conn::connect(&mut c).expect("Couldn't open DB.");
conn.transact(&mut c, r#"[
[:db/add "s" :db/ident :foo/uuid]
[:db/add "s" :db/valueType :db.type/uuid]
[:db/add "s" :db/cardinality :db.cardinality/one]
]"#).unwrap();
conn.transact(&mut c, r#"[
[:db/add "u" :foo/uuid #uuid "cf62d552-6569-4d1b-b667-04703041dfc4"]
]"#).unwrap();
// We don't yet support getting the tx from a pattern, so run wild.
let r = conn.q_once(&mut c,
r#"[:find [?x ?u ?when]
:where [?x :foo/uuid ?u]
[?tx :db/txInstant ?when]]"#, None);
match r {
Result::Ok(QueryResults::Tuple(Some(vals))) => {
let mut vals = vals.into_iter();
match (vals.next(), vals.next(), vals.next(), vals.next()) {
(Some(TypedValue::Ref(e)),
Some(TypedValue::Uuid(u)),
Some(TypedValue::Instant(t)),
None) => {
assert!(e > 39); // There are at least this many entities in the store.
assert_eq!(Ok(u), Uuid::from_str("cf62d552-6569-4d1b-b667-04703041dfc4"));
assert!(t > start);
},
_ => panic!("Unexpected results."),
}
},
_ => panic!("Expected query to work."),
}
}