diff options
author | Jae-Heon Ji <atx6419@gmail.com> | 2023-07-31 22:09:05 +0900 |
---|---|---|
committer | Jae-Heon Ji <atx6419@gmail.com> | 2023-07-31 22:09:05 +0900 |
commit | 14f1084c8b14ebf8d30cb4a6041071c4c61a9cdb (patch) | |
tree | e1c64a07a36d70bd39a6d45d3f864e046bd837ce /zellij-server | |
parent | 171a5e816ab9524e06a8be9e46a52314fdcaa260 (diff) |
test: add more new test
Diffstat (limited to 'zellij-server')
3 files changed, 110 insertions, 1 deletions
diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs index 3790e6d88..0f3eef75d 100644 --- a/zellij-server/src/plugins/unit/plugin_tests.rs +++ b/zellij-server/src/plugins/unit/plugin_tests.rs @@ -6,9 +6,10 @@ use std::collections::BTreeMap; use std::path::PathBuf; use tempfile::tempdir; use wasmer::Store; -use zellij_utils::data::{Event, Key, PluginCapabilities}; +use zellij_utils::data::{Event, Key, PermissionStatus, PermissionType, PluginCapabilities}; use zellij_utils::errors::ErrorContext; use zellij_utils::input::layout::{Layout, PluginUserConfiguration, RunPlugin, RunPluginLocation}; +use zellij_utils::input::permission::GrantedPermission; use zellij_utils::input::plugins::PluginsConfig; use zellij_utils::ipc::ClientAttributes; use zellij_utils::lazy_static::lazy_static; @@ -4284,3 +4285,95 @@ pub fn request_plugin_permissions() { .clone(); assert_snapshot!(format!("{:#?}", new_tab_event)); } + +#[test] +#[ignore] +pub fn granted_permission_request_result() { + let temp_folder = tempdir().unwrap(); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let (plugin_thread_sender, _, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin.clone(), + tab_index, + client_id, + size, + )); + std::thread::sleep(std::time::Duration::from_millis(100)); + let _ = plugin_thread_sender.send(PluginInstruction::PermissionRequestResult( + 0, + Some(client_id), + vec![PermissionType::KeyboardInput], + PermissionStatus::Granted, + )); + + teardown(); + + let granted_permission = GrantedPermission::from_cache_or_default(); + let permissions = granted_permission.get(&run_plugin.location.to_string()); + + assert_snapshot!(format!("{:#?}", permissions)); +} + +#[test] +#[ignore] +pub fn denied_permission_request_result() { + let temp_folder = tempdir().unwrap(); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let (plugin_thread_sender, _, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin.clone(), + tab_index, + client_id, + size, + )); + std::thread::sleep(std::time::Duration::from_millis(100)); + let _ = plugin_thread_sender.send(PluginInstruction::PermissionRequestResult( + 0, + Some(client_id), + vec![PermissionType::KeyboardInput], + PermissionStatus::Denied, + )); + + teardown(); + + let granted_permission = GrantedPermission::from_cache_or_default(); + let permissions = granted_permission.get(&run_plugin.location.to_string()); + + assert_snapshot!(format!("{:#?}", permissions)); +}
\ No newline at end of file diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap new file mode 100644 index 000000000..d7dfeb16d --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap @@ -0,0 +1,7 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +expression: "format!(\"{:#?}\", permissions)" +--- +Some( + [], +) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap new file mode 100644 index 000000000..607e8c3b8 --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap @@ -0,0 +1,9 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +expression: "format!(\"{:#?}\", permissions)" +--- +Some( + [ + KeyboardInput, + ], +) |