|
| 1 | +mod utils; |
| 2 | + |
| 3 | +#[cfg(test)] |
| 4 | +mod e2e_go_plugins { |
| 5 | + |
| 6 | + use crate::utils::*; |
| 7 | + |
| 8 | + use rexpect::spawn; |
| 9 | + |
| 10 | + const TEST_TIMEOUT: u64 = 10000; |
| 11 | + |
| 12 | + /** |
| 13 | + * Lets us change the target directory for the plugins and repl logic. |
| 14 | + * |
| 15 | + * See the justfile for examples where we switch to testing both plugins from the filesystem and from the HTTP server. |
| 16 | + */ |
| 17 | + fn build_command(plugin_files: &[&str], repl_logic_file: &str) -> String { |
| 18 | + let prefix = |
| 19 | + std::env::var("WASM_TARGET_DIR").unwrap_or("target/wasm32-wasip1/debug".to_string()); |
| 20 | + let mut command = String::from("target/debug/pluginlab"); |
| 21 | + command.push_str(format!(" --repl-logic {}/{}", prefix, repl_logic_file).as_str()); |
| 22 | + plugin_files.iter().for_each(|file| { |
| 23 | + command.push_str(format!(" --plugins {}", file).as_str()); |
| 24 | + }); |
| 25 | + println!("Running command: {}", command); |
| 26 | + command |
| 27 | + } |
| 28 | + |
| 29 | + #[test] |
| 30 | + fn test_echo_plugin() { |
| 31 | + let project_root = find_project_root(); |
| 32 | + println!("Setting current directory to: {:?}", project_root); |
| 33 | + std::env::set_current_dir(&project_root).unwrap(); |
| 34 | + let mut session = spawn( |
| 35 | + &format!( |
| 36 | + "{} --dir tmp/filesystem --allow-read", |
| 37 | + &build_command( |
| 38 | + &["go_modules/plugin-echo/plugin-echo-go.wasm"], |
| 39 | + "repl_logic_guest.wasm" |
| 40 | + ) |
| 41 | + ), |
| 42 | + Some(TEST_TIMEOUT), |
| 43 | + ) |
| 44 | + .expect("Can't launch pluginlab with plugin greet"); |
| 45 | + |
| 46 | + session |
| 47 | + .exp_string("[Host] Starting REPL host...") |
| 48 | + .expect("Didn't see startup message"); |
| 49 | + session |
| 50 | + .exp_string("[Host] Loading plugin:") |
| 51 | + .expect("Didn't see plugin loading message"); |
| 52 | + session |
| 53 | + .exp_string("repl(0)>") |
| 54 | + .expect("Didn't see REPL prompt"); |
| 55 | + session |
| 56 | + .send_line("echogo hello") |
| 57 | + .expect("Failed to send command"); |
| 58 | + session |
| 59 | + .exp_string("hello\r\nrepl(0)>") |
| 60 | + .expect("Didn't get expected output from echogo plugin"); |
| 61 | + } |
| 62 | +} |
0 commit comments