2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-12-15 16:15:06 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_to_table() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"oc_get_svc.txt",
|
|
|
|
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(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2020-05-04 08:44:33 +00:00
|
|
|
| from ssv
|
2022-02-09 10:58:54 +00:00
|
|
|
| get 0
|
2019-12-15 16:15:06 +00:00
|
|
|
| get IP
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "172.30.78.158");
|
2019-12-15 16:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_to_table_with_separator_specified() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"oc_get_svc.txt",
|
|
|
|
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(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2020-05-04 08:44:33 +00:00
|
|
|
| from ssv --minimum-spaces 3
|
2022-02-09 10:58:54 +00:00
|
|
|
| get 0
|
2019-12-15 16:15:06 +00:00
|
|
|
| get IP
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "172.30.78.158");
|
2019-12-15 16:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_treating_first_line_as_data_with_flag() {
|
|
|
|
Playground::setup("filter_from_ssv_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"oc_get_svc.txt",
|
|
|
|
r#"
|
|
|
|
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 aligned_columns = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2021-02-22 07:25:17 +00:00
|
|
|
| from ssv --noheaders -a
|
2019-12-15 16:15:06 +00:00
|
|
|
| first
|
2022-02-20 00:26:47 +00:00
|
|
|
| get column1
|
2019-12-15 16:15:06 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
let separator_based = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2021-02-22 07:25:17 +00:00
|
|
|
| from ssv --noheaders
|
2019-12-15 16:15:06 +00:00
|
|
|
| first
|
2022-02-20 00:26:47 +00:00
|
|
|
| get column1
|
|
|
|
|
2019-12-15 16:15:06 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(aligned_columns.out, separator_based.out);
|
|
|
|
assert_eq!(separator_based.out, "docker-registry");
|
2019-12-15 16:15:06 +00:00
|
|
|
})
|
|
|
|
}
|