mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-04 19:50:19 +00:00
enable tests
This commit is contained in:
parent
ae6d2774a8
commit
c48454563c
910
Cargo.lock
generated
910
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -28,4 +28,4 @@ mod errors;
|
||||
mod fce_wit_interfaces;
|
||||
|
||||
pub use errors::*;
|
||||
pub use fce_wit_interfaces::*;
|
||||
pub use self::fce_wit_interfaces::*;
|
||||
|
@ -26,3 +26,8 @@ boolinator = "2.4.0"
|
||||
parity-wasm = "0.41.0"
|
||||
pwasm-utils = "0.12.0"
|
||||
log = "0.4.8"
|
||||
|
||||
[dev-dependencies]
|
||||
reqwest = "0.10.4"
|
||||
bytes = "0.5.4"
|
||||
tokio = { version = "0.2.20", features = ["blocking", "macros"] }
|
||||
|
@ -15,11 +15,10 @@
|
||||
*/
|
||||
|
||||
mod downloader;
|
||||
|
||||
use fce::{Config, FCEService, FCE};
|
||||
use fce::{FCE, IValue};
|
||||
|
||||
const REDIS_DOWNLOAD_URL: &str =
|
||||
"https://github.com/fluencelabs/redis/releases/download/0.8.0_w/redis.wasm";
|
||||
"https://github.com/fluencelabs/redis/releases/download/0.9.0_w/redis.wasm";
|
||||
const SQLITE_DOWNLOAD_URL: &str =
|
||||
"https://github.com/fluencelabs/sqlite/releases/download/0.4.0_w/sqlite3.wasm";
|
||||
|
||||
@ -29,78 +28,69 @@ async fn redis() {
|
||||
|
||||
let mut fce = FCE::new();
|
||||
let module_name = "redis";
|
||||
let config = Config::default();
|
||||
let config = <_>::default();
|
||||
|
||||
fce.register_module(module_name, wasm_bytes.as_ref(), config)
|
||||
fce.load_module(module_name, wasm_bytes.as_ref(), config)
|
||||
.unwrap_or_else(|e| panic!("can't create FCE: {:?}", e));
|
||||
|
||||
let result1 = fce
|
||||
.invoke(module_name, "SET A 10".as_bytes())
|
||||
.call(module_name, "invoke", &[IValue::String(String::from("SET A 10"))])
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result2 = fce
|
||||
.invoke(module_name, "SADD B 20".as_bytes())
|
||||
.call(module_name, "invoke", &[IValue::String(String::from("SADD B 20"))])
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result3 = fce
|
||||
.invoke(module_name, "GET A".as_bytes())
|
||||
.call(module_name, "invoke", &[IValue::String(String::from("GET A"))])
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result4 = fce
|
||||
.invoke(module_name, "SMEMBERS B".as_bytes())
|
||||
.call(module_name, "invoke", &[IValue::String(String::from("SMEMBERS B"))])
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result5 = fce
|
||||
.invoke(
|
||||
module_name,
|
||||
"eval \"redis.call('incr', 'A') return redis.call('get', 'A') * 8 + 5\" 0".as_bytes(),
|
||||
)
|
||||
.call(module_name, "invoke", &[IValue::String(String::from("eval \"redis.call('incr', 'A') return redis.call('get', 'A') * 8 + 5\" 0"))])
|
||||
.expect("error while FCE invocation");
|
||||
|
||||
let result1 = String::from_utf8(result1.outcome).expect("incorrect result obtained");
|
||||
let result2 = String::from_utf8(result2.outcome).expect("incorrect result obtained");
|
||||
let result3 = String::from_utf8(result3.outcome).expect("incorrect result obtained");
|
||||
let result4 = String::from_utf8(result4.outcome).expect("incorrect result obtained");
|
||||
let result5 = String::from_utf8(result5.outcome).expect("incorrect result obtained");
|
||||
|
||||
assert_eq!(result1, "+OK\r\n");
|
||||
assert_eq!(result2, ":1\r\n");
|
||||
assert_eq!(result3, "$2\r\n10\r\n");
|
||||
assert_eq!(result4, "*1\r\n$2\r\n20\r\n");
|
||||
assert_eq!(result5, ":93\r\n");
|
||||
assert_eq!(result1, vec![IValue::String(String::from("+OK\r\n"))]);
|
||||
assert_eq!(result2, vec![IValue::String(String::from(":1\r\n"))]);
|
||||
assert_eq!(result3, vec![IValue::String(String::from("$2\r\n10\r\n"))]);
|
||||
assert_eq!(result4, vec![IValue::String(String::from("*1\r\n$2\r\n20\r\n"))]);
|
||||
assert_eq!(result5, vec![IValue::String(String::from(":93\r\n"))]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn sqlite() {
|
||||
let wasm_bytes = downloader::download(SQLITE_DOWNLOAD_URL).await;
|
||||
|
||||
let mut fce = FCE::new();
|
||||
let module_name = "sqlite";
|
||||
let config = Config::default();
|
||||
let config = <_>::default();
|
||||
|
||||
fce.register_module(module_name, wasm_bytes.as_ref(), config)
|
||||
fce.load_module(module_name, wasm_bytes.as_ref(), config)
|
||||
.unwrap_or_else(|e| panic!("can't create FCE: {:?}", e));
|
||||
|
||||
let result1 = fce
|
||||
.invoke(
|
||||
.call(
|
||||
module_name,
|
||||
"CREATE VIRTUAL TABLE users USING FTS5(body)".as_bytes(),
|
||||
"invoke",
|
||||
&[IValue::String(String::from("CREATE VIRTUAL TABLE users USING FTS5(body)"))],
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result2 = fce
|
||||
.invoke(
|
||||
.call(
|
||||
module_name,
|
||||
"INSERT INTO users(body) VALUES('AB'), ('BC'), ('CD'), ('DE')".as_bytes(),
|
||||
"invoke",
|
||||
&[IValue::String(String::from("INSERT INTO users(body) VALUES('AB'), ('BC'), ('CD'), ('DE')"))],
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
let result3 = fce
|
||||
.invoke(
|
||||
.call(
|
||||
module_name,
|
||||
"SELECT * FROM users WHERE users MATCH 'A* OR B*'".as_bytes(),
|
||||
"invoke",
|
||||
&[IValue::String(String::from("SELECT * FROM users WHERE users MATCH 'A* OR B*"))],
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("error while FCE invocation: {:?}", e));
|
||||
|
||||
let result1 = String::from_utf8(result1.outcome).expect("incorrect result obtained");
|
||||
let result2 = String::from_utf8(result2.outcome).expect("incorrect result obtained");
|
||||
let result3 = String::from_utf8(result3.outcome).expect("incorrect result obtained");
|
||||
|
||||
assert_eq!(result1, "OK");
|
||||
assert_eq!(result2, "OK");
|
||||
assert_eq!(result3, "AB|BC");
|
||||
assert_eq!(result1, vec![IValue::String(String::from("OK"))]);
|
||||
assert_eq!(result2, vec![IValue::String(String::from("OK"))]);
|
||||
assert_eq!(result3, vec![IValue::String(String::from("AB|BC"))]);
|
||||
}
|
@ -39,7 +39,7 @@ pub fn put(file_path: String) -> String {
|
||||
let timeout = std::env::var(TIMEOUT_ENV_NAME).unwrap_or_else(|_| "1s".to_string());
|
||||
let cmd = format!("add --timeout {} -Q {}", timeout, file_path);
|
||||
|
||||
ipfs(cmd)
|
||||
unsafe { ipfs(cmd) }
|
||||
}
|
||||
|
||||
/// Get file by provided hash from IPFS, saves it to a temporary file and returns a path to it.
|
||||
@ -55,7 +55,7 @@ pub fn get(hash: String) -> String {
|
||||
timeout, result_file_path, hash
|
||||
);
|
||||
|
||||
ipfs(cmd);
|
||||
unsafe { ipfs(cmd) };
|
||||
|
||||
RESULT_FILE_PATH.to_string()
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ pub fn put(file_content: Vec<u8>) -> String {
|
||||
return format!("file can't be written: {}", e);
|
||||
}
|
||||
|
||||
ipfs_put(rpc_tmp_filepath)
|
||||
unsafe { ipfs_put(rpc_tmp_filepath) }
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn get(hash: String) -> Vec<u8> {
|
||||
log::info!("get called with hash: {}", hash);
|
||||
|
||||
let file_path = ipfs_get(hash);
|
||||
let file_path = unsafe { ipfs_get(hash) };
|
||||
fs::read(file_path).unwrap_or_else(|_| b"error while reading file".to_vec())
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub fn invoke() -> TestRecord {
|
||||
field_12: Vec::new(),
|
||||
};
|
||||
|
||||
mutate_struct(test_record)
|
||||
unsafe { mutate_struct(test_record) }
|
||||
}
|
||||
|
||||
#[fce]
|
||||
|
Loading…
Reference in New Issue
Block a user