summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--test_plugin/Cargo.toml1
-rw-r--r--test_plugin/src/lib.rs14
-rw-r--r--test_plugin/tests/integration_tests.rs19
-rw-r--r--test_plugin/tests/test.js6
5 files changed, 35 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c62cbbfd8..afedc80aa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3407,6 +3407,7 @@ version = "0.0.1"
dependencies = [
"deno_core",
"futures",
+ "serde",
"test_util",
]
diff --git a/test_plugin/Cargo.toml b/test_plugin/Cargo.toml
index 6830f33fe..439559dca 100644
--- a/test_plugin/Cargo.toml
+++ b/test_plugin/Cargo.toml
@@ -13,6 +13,7 @@ crate-type = ["cdylib"]
[dependencies]
deno_core = { path = "../core" }
futures = "0.3.9"
+serde = "1"
[dev-dependencies]
test_util = { path = "../test_util" }
diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs
index 56eb8d489..0626ef3c3 100644
--- a/test_plugin/src/lib.rs
+++ b/test_plugin/src/lib.rs
@@ -13,6 +13,7 @@ use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
+use serde::Deserialize;
#[no_mangle]
pub fn init() -> Extension {
@@ -32,13 +33,20 @@ pub fn init() -> Extension {
.build()
}
+#[derive(Debug, Deserialize)]
+struct TestArgs {
+ val: String,
+}
+
fn op_test_sync(
_state: &mut OpState,
- _args: (),
+ args: TestArgs,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<String, AnyError> {
println!("Hello from sync plugin op.");
+ println!("args: {:?}", args);
+
if let Some(buf) = zero_copy {
let buf_str = std::str::from_utf8(&buf[..])?;
println!("zero_copy: {}", buf_str);
@@ -49,11 +57,13 @@ fn op_test_sync(
async fn op_test_async(
_state: Rc<RefCell<OpState>>,
- _args: (),
+ args: TestArgs,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<String, AnyError> {
println!("Hello from async plugin op.");
+ println!("args: {:?}", args);
+
if let Some(buf) = zero_copy {
let buf_str = std::str::from_utf8(&buf[..])?;
println!("zero_copy: {}", buf_str);
diff --git a/test_plugin/tests/integration_tests.rs b/test_plugin/tests/integration_tests.rs
index 203a8bade..e408f59db 100644
--- a/test_plugin/tests/integration_tests.rs
+++ b/test_plugin/tests/integration_tests.rs
@@ -35,7 +35,24 @@ fn basic() {
}
println!("{:?}", output.status);
assert!(output.status.success());
- let expected = "Plugin rid: 3\nHello from sync plugin op.\nzero_copy: test\nop_test_sync returned: test\nHello from async plugin op.\nzero_copy: 123\nop_test_async returned: test\nHello from resource_table.add plugin op.\nTestResource rid: 4\nHello from resource_table.get plugin op.\nTestResource get value: hello plugin!\nHello from sync plugin op.\nOps completed count is correct!\nOps dispatched count is correct!\n";
+ let expected = "\
+ Plugin rid: 3\n\
+ Hello from sync plugin op.\n\
+ args: TestArgs { val: \"1\" }\n\
+ zero_copy: test\n\
+ op_test_sync returned: test\n\
+ Hello from async plugin op.\n\
+ args: TestArgs { val: \"1\" }\n\
+ zero_copy: 123\n\
+ op_test_async returned: test\n\
+ Hello from resource_table.add plugin op.\n\
+ TestResource rid: 4\n\
+ Hello from resource_table.get plugin op.\n\
+ TestResource get value: hello plugin!\n\
+ Hello from sync plugin op.\n\
+ args: TestArgs { val: \"1\" }\n\
+ Ops completed count is correct!\n\
+ Ops dispatched count is correct!\n";
assert_eq!(stdout, expected);
assert_eq!(stderr, "");
}
diff --git a/test_plugin/tests/test.js b/test_plugin/tests/test.js
index 716b2ff9a..5e0e6d5a4 100644
--- a/test_plugin/tests/test.js
+++ b/test_plugin/tests/test.js
@@ -42,7 +42,7 @@ if (
function runTestSync() {
const result = Deno.core.opSync(
"op_test_sync",
- null,
+ { val: "1" },
new Uint8Array([116, 101, 115, 116]),
);
@@ -56,7 +56,7 @@ function runTestSync() {
async function runTestAsync() {
const promise = Deno.core.opAsync(
"op_test_async",
- null,
+ { val: "1" },
new Uint8Array([49, 50, 51]),
);
@@ -95,7 +95,7 @@ function runTestResourceTable() {
function runTestOpCount() {
const start = Deno.metrics();
- Deno.core.opSync("op_test_sync");
+ Deno.core.opSync("op_test_sync", { val: "1" });
const end = Deno.metrics();