test: add get_sstock_from_db_since_epoch() test
This commit is contained in:
parent
5c69ba27b2
commit
500f5d3927
|
@ -120,4 +120,39 @@ mod test {
|
|||
Err(err) => panic!("TEST_CMD_GET_STOCK_FAILED: {}", err)
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cmd_get_stock_from_db_since_epoch() {
|
||||
/* create global state */
|
||||
let mut state: GlobalState = GlobalState::default();
|
||||
|
||||
/* create stock to be tested */
|
||||
create_stock(&mut state, "baba").unwrap();
|
||||
|
||||
/* insert some data into the stock */
|
||||
let mut client = db_connect(&mut state, DB_USER, DB_PASS).unwrap();
|
||||
client.execute("INSERT INTO asset_schema.baba VALUES (1, 999, 4, 50, 50, 10)", &[]).unwrap();
|
||||
client.execute("INSERT INTO asset_schema.baba VALUES (2, 999, 5, 50, 50, 10)", &[]).unwrap();
|
||||
client.execute("INSERT INTO asset_schema.baba VALUES (3, 999, 6, 50, 50, 10)", &[]).unwrap();
|
||||
client.execute("INSERT INTO asset_schema.baba VALUES (4, 999, 7, 50, 50, 10)", &[]).unwrap();
|
||||
client.execute("INSERT INTO asset_schema.baba VALUES (5, 999, 8, 50, 50, 10)", &[]).unwrap();
|
||||
|
||||
/* test get_stock_from_db_since_epoch() */
|
||||
match get_stock_from_db_since_epoch(&mut state, "baba".into(), 6) {
|
||||
Ok(vals) => {
|
||||
/* confirm that the data is correct */
|
||||
let mut counter = 6;
|
||||
for val in vals {
|
||||
assert_eq!(val.id, counter-3);
|
||||
assert_eq!(val.isin, "999".to_string());
|
||||
assert_eq!(val.time_epoch, counter);
|
||||
assert_eq!(val.ask_price, 50);
|
||||
assert_eq!(val.bid_price, 50);
|
||||
assert_eq!(val.volume, 10);
|
||||
counter += 1;
|
||||
}
|
||||
},
|
||||
Err(err) => panic!("TEST_CMD_GET_STOCK_SINCE_EPOCH: {}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user