Skip to content

Commit

Permalink
test: add 'show system' subcommand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
waynr committed Jan 29, 2025
1 parent 493bdbd commit c24ebee
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
80 changes: 80 additions & 0 deletions influxdb3/tests/server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,86 @@ fn test_create_token() {
);
}

#[test_log::test(tokio::test)]
async fn test_show_system() {
let server = TestServer::configure().spawn().await;
let server_addr = server.client_addr();
let db_name = "foo";

server
.write_lp_to_db(
db_name,
"cpu,t1=a,t2=b,t3=c f1=true,f2=\"hello\",f3=4i,f4=4u,f5=5 1000",
influxdb3_client::Precision::Second,
)
.await
.expect("write to db");

struct SuccessTestCase<'a> {
name: &'static str,
args: Vec<&'a str>,
}

let cases = vec![
SuccessTestCase {
name: "summary should show up to ten entries from each table",
args: vec![
"show",
"system",
"--host",
server_addr.as_str(),
"--database",
db_name,
"summary",
],
},
SuccessTestCase {
name: "summary should show default registered system tables",
args: vec![
"show",
"system",
"--host",
server_addr.as_str(),
"--database",
db_name,
"table-list",
],
},
];

for case in cases {
let output = run(&case.args);
let snap_name = case.name.replace(' ', "_");
insta::assert_snapshot!(snap_name, output);
}

struct FailTestCase<'a> {
name: &'static str,
args: Vec<&'a str>,
}

let cases = vec![
FailTestCase {
name: "fail without database name",
args: vec!["show", "system", "table-list"],
},
FailTestCase {
name: "random table name doesn't exist, should error",
args: vec!["show", "system", "--host", server_addr.as_str(), "--database", db_name, "table", "meow"],
},
FailTestCase {
name: "iox schema table name exists, but should error because we're concerned here with system tables",
args: vec!["show", "system", "--host", server_addr.as_str(), "--database", db_name, "table", "cpu"],
},
];

for case in cases {
let output = run_and_err(&case.args);
let snap_name = case.name.replace(' ', "_");
insta::assert_snapshot!(snap_name, output);
}
}

#[tokio::test]
async fn distinct_cache_create_and_delete() {
let server = TestServer::spawn().await;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: influxdb3/tests/server/cli.rs
expression: output
snapshot_kind: text
---
error: the following required arguments were not provided:
--database <DATABASE_NAME>

Usage: influxdb3 show system --database <DATABASE_NAME> <COMMAND>

For more information, try '--help'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: influxdb3/tests/server/cli.rs
expression: output
snapshot_kind: text
---
Show command failed: system table 'cpu' not found: please use a valid system table name: ["distinct_caches", "last_caches", "parquet_files", "processing_engine_plugins", "processing_engine_triggers", "queries"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: influxdb3/tests/server/cli.rs
expression: output
snapshot_kind: text
---
Show command failed: system table 'meow' not found: please use a valid system table name: ["distinct_caches", "last_caches", "parquet_files", "processing_engine_plugins", "processing_engine_triggers", "queries"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: influxdb3/tests/server/cli.rs
expression: output
snapshot_kind: text
---
+----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| table_name | column_names |
+----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| distinct_caches | [table, name, column_ids, column_names, max_cardinality, max_age_seconds] |
| last_caches | [table, name, key_column_ids, key_column_names, value_column_ids, value_column_names, count, ttl] |
| parquet_files | [table_name, path, size_bytes, row_count, min_time, max_time] |
| processing_engine_plugins | [plugin_name, file_name, plugin_type] |
| processing_engine_triggers | [trigger_name, plugin_name, trigger_specification, disabled] |
| queries | [id, phase, issue_time, query_type, query_text, partitions, parquet_files, plan_duration, permit_duration, execute_duration, end2end_duration, compute_duration, max_memory, success, running, cancelled, trace_id] |
+----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: influxdb3/tests/server/cli.rs
expression: output
snapshot_kind: text
---
distinct_caches summary:
+-------+------+------------+--------------+-----------------+-----------------+
| table | name | column_ids | column_names | max_cardinality | max_age_seconds |
+-------+------+------------+--------------+-----------------+-----------------+
+-------+------+------------+--------------+-----------------+-----------------+
last_caches summary:
+-------+------+----------------+------------------+------------------+--------------------+-------+-----+
| table | name | key_column_ids | key_column_names | value_column_ids | value_column_names | count | ttl |
+-------+------+----------------+------------------+------------------+--------------------+-------+-----+
+-------+------+----------------+------------------+------------------+--------------------+-------+-----+
parquet_files summary:
+------------+------+------------+-----------+----------+----------+
| table_name | path | size_bytes | row_count | min_time | max_time |
+------------+------+------------+-----------+----------+----------+
+------------+------+------------+-----------+----------+----------+
processing_engine_plugins summary:
++
++
processing_engine_triggers summary:
++
++

0 comments on commit c24ebee

Please sign in to comment.