Fixing old usages of PipelineDataHeader
This commit is contained in:
parent
fe6479983c
commit
dccf597af1
|
@ -145,7 +145,7 @@ fn read_pipeline_data_value() -> Result<(), ShellError> {
|
|||
});
|
||||
let header = PipelineDataHeader::Value {
|
||||
value: value.clone(),
|
||||
metadata,
|
||||
metadata: metadata.clone(),
|
||||
};
|
||||
|
||||
match manager.read_pipeline_data(header, &Signals::empty())? {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
macro_rules! generate_tests {
|
||||
($encoder:expr) => {
|
||||
use nu_plugin_protocol::{
|
||||
CallInfo, CustomValueOp, EvaluatedCall, PipelineDataHeader,
|
||||
PluginCall, PluginCallResponse, PluginCustomValue, PluginInput,
|
||||
PluginOption, PluginOutput, StreamData,
|
||||
CallInfo, CustomValueOp, EvaluatedCall, PipelineDataHeader, PluginCall,
|
||||
PluginCallResponse, PluginCustomValue, PluginInput, PluginOption, PluginOutput,
|
||||
StreamData,
|
||||
};
|
||||
use nu_protocol::{
|
||||
DataSource, PipelineMetadata, LabeledError, PluginSignature, Signature, Span, Spanned, SyntaxShape, Value,
|
||||
DataSource, LabeledError, PipelineMetadata, PluginSignature, Signature, Span, Spanned,
|
||||
SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -133,7 +134,7 @@ macro_rules! generate_tests {
|
|||
call: call.clone(),
|
||||
input: PipelineDataHeader::Value {
|
||||
value: input.clone(),
|
||||
metadata,
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -319,7 +320,10 @@ macro_rules! generate_tests {
|
|||
match returned {
|
||||
PluginOutput::CallResponse(
|
||||
4,
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::Value(returned_value)),
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::Value {
|
||||
value: returned_value,
|
||||
metadata: None,
|
||||
}),
|
||||
) => {
|
||||
assert_eq!(value, returned_value)
|
||||
}
|
||||
|
@ -339,7 +343,10 @@ macro_rules! generate_tests {
|
|||
span,
|
||||
);
|
||||
|
||||
let response = PluginCallResponse::PipelineData(PipelineDataHeader::Value(value));
|
||||
let response = PluginCallResponse::PipelineData(PipelineDataHeader::Value {
|
||||
value,
|
||||
metadata: None,
|
||||
});
|
||||
let output = PluginOutput::CallResponse(5, response);
|
||||
|
||||
let encoder = $encoder;
|
||||
|
@ -355,7 +362,10 @@ macro_rules! generate_tests {
|
|||
match returned {
|
||||
PluginOutput::CallResponse(
|
||||
5,
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::Value(returned_value)),
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::Value {
|
||||
value: returned_value,
|
||||
metadata: None,
|
||||
}),
|
||||
) => {
|
||||
assert_eq!(span, returned_value.span());
|
||||
|
||||
|
|
|
@ -17,8 +17,9 @@ use nu_plugin_protocol::{
|
|||
use nu_protocol::{
|
||||
ast::{Math, Operator},
|
||||
engine::Closure,
|
||||
ByteStreamType, CustomValue, IntoInterruptiblePipelineData, IntoSpanned, PipelineData,
|
||||
PluginMetadata, PluginSignature, ShellError, Signals, Span, Spanned, Value,
|
||||
ByteStreamType, CustomValue, DataSource, IntoInterruptiblePipelineData, IntoSpanned,
|
||||
PipelineData, PipelineMetadata, PluginMetadata, PluginSignature, ShellError, Signals, Span,
|
||||
Spanned, Value,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
|
@ -52,10 +53,13 @@ fn manager_consume_all_exits_after_streams_and_interfaces_are_dropped() -> Resul
|
|||
|
||||
// Create a stream...
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -108,10 +112,13 @@ fn manager_consume_all_propagates_io_error_to_readers() -> Result<(), ShellError
|
|||
test.set_read_error(test_io_error());
|
||||
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -154,11 +161,14 @@ fn manager_consume_all_propagates_message_error_to_readers() -> Result<(), Shell
|
|||
test.add(invalid_output());
|
||||
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ByteStream(ByteStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
}),
|
||||
PipelineDataHeader::ByteStream {
|
||||
info: ByteStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -331,10 +341,13 @@ fn manager_consume_call_response_forwards_to_subscriber_with_pipeline_data(
|
|||
|
||||
manager.consume(PluginOutput::CallResponse(
|
||||
0,
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
})),
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
}),
|
||||
))?;
|
||||
|
||||
for i in 0..2 {
|
||||
|
@ -375,18 +388,24 @@ fn manager_consume_call_response_registers_streams() -> Result<(), ShellError> {
|
|||
// Check list streams, byte streams
|
||||
manager.consume(PluginOutput::CallResponse(
|
||||
0,
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
})),
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
}),
|
||||
))?;
|
||||
manager.consume(PluginOutput::CallResponse(
|
||||
1,
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ByteStream(ByteStreamInfo {
|
||||
id: 1,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
})),
|
||||
PluginCallResponse::PipelineData(PipelineDataHeader::ByteStream {
|
||||
info: ByteStreamInfo {
|
||||
id: 1,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
},
|
||||
metadata: None,
|
||||
}),
|
||||
))?;
|
||||
|
||||
// ListStream should have one
|
||||
|
@ -442,10 +461,13 @@ fn manager_consume_engine_call_forwards_to_subscriber_with_pipeline_data() -> Re
|
|||
span: Span::test_data(),
|
||||
},
|
||||
positional: vec![],
|
||||
input: PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 2,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
input: PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 2,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
redirect_stdout: false,
|
||||
redirect_stderr: false,
|
||||
},
|
||||
|
@ -806,6 +828,11 @@ fn interface_write_plugin_call_writes_run_with_value_input() -> Result<(), Shell
|
|||
let manager = test.plugin("test");
|
||||
let interface = manager.get_interface();
|
||||
|
||||
let metadata0 = PipelineMetadata {
|
||||
data_source: DataSource::None,
|
||||
content_type: Some("baz".into()),
|
||||
};
|
||||
|
||||
let result = interface.write_plugin_call(
|
||||
PluginCall::Run(CallInfo {
|
||||
name: "foo".into(),
|
||||
|
@ -814,7 +841,7 @@ fn interface_write_plugin_call_writes_run_with_value_input() -> Result<(), Shell
|
|||
positional: vec![],
|
||||
named: vec![],
|
||||
},
|
||||
input: PipelineData::Value(Value::test_int(-1), None),
|
||||
input: PipelineData::Value(Value::test_int(-1), Some(metadata0.clone())),
|
||||
}),
|
||||
None,
|
||||
)?;
|
||||
|
@ -826,7 +853,10 @@ fn interface_write_plugin_call_writes_run_with_value_input() -> Result<(), Shell
|
|||
PluginCall::Run(CallInfo { name, input, .. }) => {
|
||||
assert_eq!("foo", name);
|
||||
match input {
|
||||
PipelineDataHeader::Value(value) => assert_eq!(-1, value.as_int()?),
|
||||
PipelineDataHeader::Value { value, metadata } => {
|
||||
assert_eq!(-1, value.as_int()?);
|
||||
assert_eq!(metadata0, metadata.expect("there should be metadata"));
|
||||
}
|
||||
_ => panic!("unexpected input header: {input:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -866,7 +896,10 @@ fn interface_write_plugin_call_writes_run_with_stream_input() -> Result<(), Shel
|
|||
PluginCall::Run(CallInfo { name, input, .. }) => {
|
||||
assert_eq!("foo", name);
|
||||
match input {
|
||||
PipelineDataHeader::ListStream(info) => info,
|
||||
PipelineDataHeader::ListStream {
|
||||
info,
|
||||
metadata: None,
|
||||
} => info,
|
||||
_ => panic!("unexpected input header: {input:?}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,13 @@ fn manager_consume_all_exits_after_streams_and_interfaces_are_dropped() -> Resul
|
|||
|
||||
// Create a stream...
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -111,10 +114,13 @@ fn manager_consume_all_propagates_io_error_to_readers() -> Result<(), ShellError
|
|||
test.set_read_error(test_io_error());
|
||||
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -157,11 +163,14 @@ fn manager_consume_all_propagates_message_error_to_readers() -> Result<(), Shell
|
|||
test.add(invalid_input());
|
||||
|
||||
let stream = manager.read_pipeline_data(
|
||||
PipelineDataHeader::ByteStream(ByteStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
}),
|
||||
PipelineDataHeader::ByteStream {
|
||||
info: ByteStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
type_: ByteStreamType::Unknown,
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
&Signals::empty(),
|
||||
)?;
|
||||
|
||||
|
@ -414,10 +423,13 @@ fn manager_consume_call_run_forwards_to_receiver_with_pipeline_data() -> Result<
|
|||
positional: vec![],
|
||||
named: vec![],
|
||||
},
|
||||
input: PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 6,
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
input: PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 6,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
}),
|
||||
))?;
|
||||
|
||||
|
@ -556,10 +568,13 @@ fn manager_consume_engine_call_response_forwards_to_subscriber_with_pipeline_dat
|
|||
|
||||
manager.consume(PluginInput::EngineCallResponse(
|
||||
0,
|
||||
EngineCallResponse::PipelineData(PipelineDataHeader::ListStream(ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
})),
|
||||
EngineCallResponse::PipelineData(PipelineDataHeader::ListStream {
|
||||
info: ListStreamInfo {
|
||||
id: 0,
|
||||
span: Span::test_data(),
|
||||
},
|
||||
metadata: None,
|
||||
}),
|
||||
))?;
|
||||
|
||||
for i in 0..2 {
|
||||
|
@ -707,7 +722,10 @@ fn interface_write_response_with_value() -> Result<(), ShellError> {
|
|||
assert_eq!(33, id, "id");
|
||||
match response {
|
||||
PluginCallResponse::PipelineData(header) => match header {
|
||||
PipelineDataHeader::Value(value) => assert_eq!(6, value.as_int()?),
|
||||
PipelineDataHeader::Value {
|
||||
value,
|
||||
metadata: None,
|
||||
} => assert_eq!(6, value.as_int()?),
|
||||
_ => panic!("unexpected pipeline data header: {header:?}"),
|
||||
},
|
||||
_ => panic!("unexpected response: {response:?}"),
|
||||
|
@ -739,7 +757,10 @@ fn interface_write_response_with_stream() -> Result<(), ShellError> {
|
|||
let info = match written {
|
||||
PluginOutput::CallResponse(_, response) => match response {
|
||||
PluginCallResponse::PipelineData(header) => match header {
|
||||
PipelineDataHeader::ListStream(info) => info,
|
||||
PipelineDataHeader::ListStream {
|
||||
info,
|
||||
metadata: None,
|
||||
} => info,
|
||||
_ => panic!("expected ListStream header: {header:?}"),
|
||||
},
|
||||
_ => panic!("wrong response: {response:?}"),
|
||||
|
|
Loading…
Reference in New Issue
Block a user