-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathintegration_plugins.rs
More file actions
186 lines (161 loc) Β· 6.66 KB
/
integration_plugins.rs
File metadata and controls
186 lines (161 loc) Β· 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! Integration tests for wash plugin system
//!
//! This test validates the plugin test command functionality using the oauth plugin.
//! It runs the plugin test command with various combinations of command and hook flags.
use anyhow::{Context, Result};
use std::path::PathBuf;
use wash::{
cli::{
CliCommand, CliContext,
plugin::{PluginCommand, TestCommand},
},
runtime::bindings::plugin::exports::wasmcloud::wash::plugin::HookType,
};
/// Test the plugin test command with the inspect plugin
#[tokio::test]
async fn test_plugin_test_inspect_comprehensive() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let ctx = CliContext::new()
.await
.context("Failed to create CLI context")?;
let inspect_plugin_path = PathBuf::from("plugins/inspect");
// Verify the inspect plugin directory exists
if !inspect_plugin_path.exists() {
anyhow::bail!(
"inspect plugin directory not found at {}",
inspect_plugin_path.display()
);
}
eprintln!(
"π§ͺ Testing inspect plugin at: {}",
inspect_plugin_path.display()
);
// TODO(#12): Weirdly, clap's help text will actually _exit_ the test if this
// runs. So it either needs to be tested separately or hooked into somehow
// Test 1: Basic plugin test without any command or hook flags
// eprintln!("π Test 1: Basic plugin test (help)");
// let test_cmd_basic = TestCommand {
// plugin: oauth_plugin_path.clone(),
// args: vec!["--help".to_string()],
// hooks: vec![],
// };
// let plugin_cmd_basic = PluginCommand::Test(test_cmd_basic);
// let result_basic = plugin_cmd_basic
// .handle(&ctx)
// .await
// .context("Failed to execute basic plugin test")?;
// NOTE: This may feel weird, but the default --help exit code is actually 1
// assert!(
// !result_basic.is_success(),
// "Basic plugin test should succeed"
// );
// // The description
// assert!(result_basic.text().contains(
// "OAuth2 server for authentication"
// ));
// eprintln!("β
Basic plugin test passed");
// Test 2: Plugin test with inspect command using a test component
eprintln!("π Test 2: Plugin test command with component inspection");
// Copy test component to plugin accessible location
let test_component_host_path = "./tests/fixtures/http_hello_world_rust.wasm";
let component_arg = if std::path::Path::new(test_component_host_path).exists() {
// Copy to temp dir so the plugin can access it
let tmp_path = std::env::temp_dir().join("http_hello_world_rust.wasm");
std::fs::copy(test_component_host_path, &tmp_path)
.context("Failed to copy test component to temp dir")?;
"http_hello_world_rust.wasm".to_string() // Plugin will see this relative to temp dir
} else {
// Skip this test if no test component is available
eprintln!(
"β οΈ Skipping component inspection test - no test component found at {}",
test_component_host_path
);
"nonexistent.wasm".to_string() // This will test error handling
};
let test_cmd_with_command = TestCommand {
plugin: inspect_plugin_path.to_string_lossy().to_string(),
args: vec![component_arg.clone()],
hooks: vec![],
};
let plugin_cmd_with_command = PluginCommand::Test(test_cmd_with_command);
let result_with_command = plugin_cmd_with_command
.handle(&ctx)
.await
.context("Failed to execute plugin test with command")?;
// The result depends on whether the test component exists
if std::path::Path::new(test_component_host_path).exists() {
assert!(
result_with_command.is_success(),
"Plugin test with valid component should succeed"
);
eprintln!("β
Plugin test with component inspection passed");
} else {
// Should fail gracefully with nonexistent component
assert!(
!result_with_command.is_success(),
"Plugin test with nonexistent component should fail gracefully"
);
eprintln!("β
Plugin test with invalid component failed gracefully");
}
// Test 3: Plugin test with --hook afterdev
eprintln!("π Test 3: Plugin test with AfterDev hook");
let test_cmd_with_hook = TestCommand {
plugin: inspect_plugin_path.to_string_lossy().to_string(),
args: vec![],
hooks: vec![HookType::AfterDev],
};
let plugin_cmd_with_hook = PluginCommand::Test(test_cmd_with_hook);
let result_with_hook = plugin_cmd_with_hook
.handle(&ctx)
.await
.context("Failed to execute plugin test with hook")?;
assert!(
result_with_hook.is_success(),
"Plugin test with AfterDev hook should succeed (even without artifact)"
);
eprintln!("β
Plugin test with AfterDev hook passed");
// Test 4: Plugin test with both command and AfterDev hook
eprintln!("π Test 4: Plugin test with both component inspection and AfterDev hook");
let test_cmd_with_both = TestCommand {
plugin: inspect_plugin_path.to_string_lossy().to_string(),
args: vec![component_arg.clone()],
hooks: vec![HookType::AfterDev],
};
let plugin_cmd_with_both = PluginCommand::Test(test_cmd_with_both);
let result_with_both = plugin_cmd_with_both
.handle(&ctx)
.await
.context("Failed to execute plugin test with both command and hook")?;
// Should succeed regardless of component existence due to graceful error handling
eprintln!("β
Plugin test with both command and AfterDev hook completed");
// Verify that all tests produced meaningful output
let outputs = [
// &result_basic,
&result_with_command,
&result_with_hook,
&result_with_both,
];
for (i, output) in outputs.iter().enumerate() {
eprintln!("π Test {} output: {}", i + 1, output.text());
// Verify that the output contains expected content
if let Some(json_value) = output.json() {
assert!(
json_value.get("success").is_some(),
"Output should contain success field"
);
assert!(
json_value.get("metadata").is_some(),
"Output should contain metadata field"
);
eprintln!(
"π Test {} metadata: {}",
i + 1,
json_value.get("metadata").unwrap()
);
}
}
eprintln!("π All inspect plugin tests passed successfully!");
Ok(())
}