Adds unimplemented module, tests.

This commit is contained in:
Thomas Hartmann 2019-10-13 21:15:30 +02:00
parent 5ec6bac7d9
commit 648d4865b1
3 changed files with 101 additions and 0 deletions

View File

@ -22,6 +22,7 @@ pub(crate) mod from_csv;
pub(crate) mod from_ini;
pub(crate) mod from_json;
pub(crate) mod from_sqlite;
pub(crate) mod from_ssv;
pub(crate) mod from_toml;
pub(crate) mod from_tsv;
pub(crate) mod from_url;
@ -91,6 +92,7 @@ pub(crate) use from_ini::FromINI;
pub(crate) use from_json::FromJSON;
pub(crate) use from_sqlite::FromDB;
pub(crate) use from_sqlite::FromSQLite;
pub(crate) use from_ssv::FromSSV;
pub(crate) use from_toml::FromTOML;
pub(crate) use from_tsv::FromTSV;
pub(crate) use from_url::FromURL;

43
src/commands/from_ssv.rs Normal file
View File

@ -0,0 +1,43 @@
use crate::commands::WholeStreamCommand;
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromSSV;
#[derive(Deserialize)]
pub struct FromSSVArgs {
headerless: bool,
}
const STRING_REPRESENTATION: &str = "from-ssv";
impl WholeStreamCommand for FromSSV {
fn name(&self) -> &str {
STRING_REPRESENTATION
}
fn signature(&self) -> Signature {
Signature::build(STRING_REPRESENTATION).switch("headerless")
}
fn usage(&self) -> &str {
"Parse text as .ssv and create a table."
}
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, from_ssv)?.run()
}
}
fn from_ssv(
FromSSVArgs {
headerless: headerless,
}: FromSSVArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
unimplemented!()
}

View File

@ -355,6 +355,62 @@ fn converts_from_tsv_text_skipping_headers_to_structured_table() {
})
}
#[test]
fn converts_from_ssv_text_to_structured_table() {
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"oc_get_svc.ssv",
r#"
NAME LABELS SELECTOR IP PORT(S)
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
"#,
)]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
open oc_get_svc.ssv
| from-ssv
| nth 0
| get NAME
| echo $it
"#
));
assert_eq!(actual, "docker-registry");
})
}
#[test]
fn converts_from_ssv_text_skipping_headers_to_structured_table() {
Playground::setup("filter_from_ssv_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"oc_get_svc.ssv",
r#"
NAME LABELS SELECTOR IP PORT(S)
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
"#,
)]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
open oc_get_svc.ssv
| from-ssv --headerless
| nth 2
| get Column2
| echo $it
"#
));
assert_eq!(actual, "component=apiserver,provider=kubernetes");
})
}
#[test]
fn can_convert_table_to_bson_and_back_into_table() {
let actual = nu!(