Update introspection tables acceptance test suite. Closes #2906

This commit is contained in:
Puskar Basu
2023-01-18 17:47:21 +05:30
committed by kai
parent 43502c6447
commit 8b68c0779f
21 changed files with 955 additions and 101 deletions

View File

@@ -329,6 +329,7 @@ jobs:
- "check"
- "performance"
- "workspace"
- "introspection"
- "cloud"
- "dashboard"
- "dashboard_parsing_validation"

View File

@@ -100,6 +100,7 @@ jobs:
- "check"
- "performance"
- "workspace"
- "introspection"
- "cloud"
- "dashboard"
- "dashboard_parsing_validation"

View File

@@ -1,23 +0,0 @@
variable "sample_var_1"{
type = string
default = "steampipe_var"
}
query "sample_query_1"{
title ="Q1"
description = "query 1 - 3 params all with defaults"
sql = "select 'ok' as status, 'steampipe' as resource, concat($1::text, $2::text, $3::text) as reason"
param "p1"{
description = "p1"
default = var.sample_var_1
}
param "p2"{
description = "p2"
default = "because_def "
}
param "p3"{
description = "p3"
default = "string"
}
}

View File

@@ -0,0 +1,129 @@
variable "sample_var_1"{
type = string
default = "steampipe_var"
}
query "sample_query_1"{
title ="Sample query 1"
description = "query 1 - 3 params all with defaults"
sql = "select 'ok' as status, 'steampipe' as resource, concat($1::text, $2::text, $3::text) as reason"
param "p1"{
description = "p1"
default = var.sample_var_1
}
param "p2"{
description = "p2"
default = "because_def "
}
param "p3"{
description = "p3"
default = "string"
}
}
control "sample_control_1" {
title = "Sample control 1"
description = "Sample control to test introspection functionality"
query = query.sample_query_1
severity = "high"
tags = {
"foo": "bar"
}
}
benchmark "sample_benchmark_1" {
title = "Sample benchmark 1"
description = "Sample benchmark to test introspection functionality"
children = [
control.sample_control_1
]
}
dashboard "sample_dashboard_1" {
title = "Sample dashboard 1"
description = "Sample dashboard to test introspection functionality"
container "sample_conatiner_1" {
card "sample_card_1" {
title = "Sample card 1"
}
image "sample_image_1" {
title = "Sample image 1"
width = 3
src = "https://steampipe.io/images/logo.png"
alt = "steampipe"
}
text "sample_text_1" {
title = "Sample text 1"
}
chart "sample_chart_1" {
sql = "select 1 as chart"
width = 5
title = "Sample chart 1"
}
flow "sample_flow_1" {
title = "Sample flow 1"
width = 3
node "sample_node_1" {
sql = <<-EOQ
select 1 as node
EOQ
}
edge "sample_edge_1" {
sql = <<-EOQ
select 1 as edge
EOQ
}
}
graph "sample_graph_1" {
title = "Sample graph 1"
width = 5
node "sample_node_2" {
sql = <<-EOQ
select 1 as node
EOQ
}
edge "sample_edge_2" {
sql = <<-EOQ
select 1 as edge
EOQ
}
}
hierarchy "sample_hierarchy_1" {
title = "Sample hierarchy 1"
width = 5
node "sample_node_3" {
sql = <<-EOQ
select 1 as node
EOQ
}
edge "sample_edge_3" {
sql = <<-EOQ
select 1 as edge
EOQ
}
}
table "sample_table_1" {
sql = "select 1 as table"
width = 4
title = "Sample table 1"
}
input "sample_input_1" {
sql = "select 1 as input"
width = 2
title = "Sample input 1"
}
}
}

View File

@@ -0,0 +1,44 @@
{
"group_id": "root_result_group",
"title": "Sample control 1",
"description": "",
"tags": {},
"summary": {
"status": {
"alarm": 0,
"ok": 1,
"info": 0,
"skip": 0,
"error": 0
}
},
"groups": [],
"controls": [
{
"summary": {
"alarm": 0,
"ok": 1,
"info": 0,
"skip": 0,
"error": 0
},
"results": [
{
"reason": "steampipe_varbecause_def string",
"resource": "steampipe",
"status": "ok",
"dimensions": null
}
],
"control_id": "control.sample_control_1",
"description": "Sample control to test introspection functionality",
"severity": "high",
"tags": {
"foo": "bar"
},
"title": "Sample control 1",
"run_status": 4,
"run_error": ""
}
]
}

View File

@@ -0,0 +1,26 @@
[
{
"auto_generated": false,
"children": [
"introspection_table_mod.control.sample_control_1"
],
"description": "Sample benchmark to test introspection functionality",
"documentation": null,
"end_line_number": 41,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.benchmark.sample_benchmark_1"
]
],
"resource_name": "sample_benchmark_1",
"source_definition": "benchmark \"sample_benchmark_1\" {\n\ttitle = \"Sample benchmark 1\"\n\tdescription = \"Sample benchmark to test introspection functionality\"\n\tchildren = [\n\t\tcontrol.sample_control_1\n\t]\n}",
"start_line_number": 35,
"tags": null,
"title": "Sample benchmark 1",
"type": null,
"width": null
}
]

View File

@@ -0,0 +1,33 @@
[
{
"args": {
"args_list": null,
"refs": null
},
"auto_generated": false,
"description": "Sample control to test introspection functionality",
"documentation": null,
"end_line_number": 33,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.benchmark.sample_benchmark_1",
"introspection_table_mod.control.sample_control_1"
]
],
"resource_name": "sample_control_1",
"severity": "high",
"source_definition": "control \"sample_control_1\" {\n title = \"Sample control 1\"\n description = \"Sample control to test introspection functionality\"\n query = query.sample_query_1\n severity = \"high\"\n tags = {\n \"foo\": \"bar\"\n }\n}",
"sql": null,
"start_line_number": 25,
"tags": {
"foo": "bar"
},
"title": "Sample control 1",
"type": null,
"width": null
}
]

View File

@@ -0,0 +1,33 @@
[
{
"auto_generated": false,
"children": [
"introspection_table_mod.container.sample_conatiner_1"
],
"description": "Sample dashboard to test introspection functionality",
"display": null,
"documentation": null,
"end_line_number": 129,
"inputs": [
{
"name": "sample_input_1",
"unqualified_name": "input.sample_input_1"
}
],
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1"
]
],
"resource_name": "sample_dashboard_1",
"source_definition": "dashboard \"sample_dashboard_1\" {\n title = \"Sample dashboard 1\"\n description = \"Sample dashboard to test introspection functionality\"\n\n container \"sample_conatiner_1\" {\n\t\tcard \"sample_card_1\" {\n\t\t\ttitle = \"Sample card 1\"\n\t\t}\n\n\t\timage \"sample_image_1\" {\n\t\t\ttitle = \"Sample image 1\"\n\t\t\twidth = 3\n \t\tsrc = \"https://steampipe.io/images/logo.png\"\n \t\talt = \"steampipe\"\n\t\t}\n\n\t\ttext \"sample_text_1\" {\n\t\t\ttitle = \"Sample text 1\"\n\t\t}\n\n chart \"sample_chart_1\" {\n sql = \"select 1 as chart\"\n width = 5\n title = \"Sample chart 1\"\n }\n\n flow \"sample_flow_1\" {\n title = \"Sample flow 1\"\n width = 3\n\n node \"sample_node_1\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_1\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }\n\n graph \"sample_graph_1\" {\n title = \"Sample graph 1\"\n width = 5\n\n node \"sample_node_2\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_2\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }\n\n hierarchy \"sample_hierarchy_1\" {\n title = \"Sample hierarchy 1\"\n width = 5\n\n node \"sample_node_3\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_3\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }\n\n table \"sample_table_1\" {\n sql = \"select 1 as table\"\n width = 4\n title = \"Sample table 1\"\n }\n\n input \"sample_input_1\" {\n sql = \"select 1 as input\"\n width = 2\n title = \"Sample input 1\"\n }\n }\n}",
"start_line_number": 43,
"tags": null,
"title": "Sample dashboard 1",
"url_path": "/introspection_table_mod.dashboard.sample_dashboard_1",
"width": null
}
]

View File

@@ -0,0 +1,31 @@
[
{
"args": null,
"auto_generated": false,
"description": null,
"documentation": null,
"end_line_number": 50,
"icon": null,
"is_anonymous": false,
"label": null,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"resource_name": "sample_card_1",
"source_definition": "\t\tcard \"sample_card_1\" {\n\t\t\ttitle = \"Sample card 1\"\n\t\t}",
"sql": null,
"start_line_number": 48,
"tags": null,
"title": "Sample card 1",
"type": null,
"value": null,
"width": null
}
]

View File

@@ -0,0 +1,31 @@
[
{
"args": null,
"auto_generated": false,
"axes": null,
"description": null,
"documentation": null,
"end_line_number": 67,
"is_anonymous": false,
"legend": null,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"resource_name": "sample_chart_1",
"series": null,
"source_definition": " chart \"sample_chart_1\" {\n sql = \"select 1 as chart\"\n width = 5\n title = \"Sample chart 1\"\n }",
"sql": "select 1 as chart",
"start_line_number": 63,
"tags": null,
"title": "Sample chart 1",
"type": null,
"width": "5"
}
]

View File

@@ -0,0 +1,31 @@
[
{
"args": null,
"auto_generated": false,
"description": null,
"documentation": null,
"edges": [
{
"name": "sample_edge_1"
}
],
"end_line_number": 83,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"nodes": [
{
"name": "sample_node_1"
}
],
"params": null,
"path": null,
"resource_name": "sample_flow_1",
"source_definition": " flow \"sample_flow_1\" {\n title = \"Sample flow 1\"\n width = 3\n\n node \"sample_node_1\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_1\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }",
"sql": null,
"start_line_number": 69,
"tags": null,
"title": "Sample flow 1",
"type": null,
"width": "3"
}
]

View File

@@ -0,0 +1,32 @@
[
{
"args": null,
"auto_generated": false,
"description": null,
"direction": null,
"documentation": null,
"edges": [
{
"name": "sample_edge_2"
}
],
"end_line_number": 99,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"nodes": [
{
"name": "sample_node_2"
}
],
"params": null,
"path": null,
"resource_name": "sample_graph_1",
"source_definition": " graph \"sample_graph_1\" {\n title = \"Sample graph 1\"\n width = 5\n\n node \"sample_node_2\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_2\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }",
"sql": null,
"start_line_number": 85,
"tags": null,
"title": "Sample graph 1",
"type": null,
"width": "5"
}
]

View File

@@ -0,0 +1,31 @@
[
{
"args": null,
"auto_generated": false,
"description": null,
"documentation": null,
"edges": [
{
"name": "sample_edge_3"
}
],
"end_line_number": 115,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"nodes": [
{
"name": "sample_node_3"
}
],
"params": null,
"path": null,
"resource_name": "sample_hierarchy_1",
"source_definition": " hierarchy \"sample_hierarchy_1\" {\n title = \"Sample hierarchy 1\"\n width = 5\n\n node \"sample_node_3\" {\n sql = <<-EOQ\n select 1 as node\n EOQ\n }\n edge \"sample_edge_3\" {\n sql = <<-EOQ\n select 1 as edge\n EOQ\n }\n }",
"sql": null,
"start_line_number": 101,
"tags": null,
"title": "Sample hierarchy 1",
"type": null,
"width": "5"
}
]

View File

@@ -0,0 +1,29 @@
[
{
"alt": "steampipe",
"args": null,
"auto_generated": false,
"description": null,
"documentation": null,
"end_line_number": 57,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"resource_name": "sample_image_1",
"source_definition": "\t\timage \"sample_image_1\" {\n\t\t\ttitle = \"Sample image 1\"\n\t\t\twidth = 3\n \t\tsrc = \"https://steampipe.io/images/logo.png\"\n \t\talt = \"steampipe\"\n\t\t}",
"sql": null,
"src": "https://steampipe.io/images/logo.png",
"start_line_number": 52,
"tags": null,
"title": "Sample image 1",
"width": "3"
}
]

View File

@@ -0,0 +1,31 @@
[
{
"args": null,
"auto_generated": false,
"dashboard": "introspection_table_mod.dashboard.sample_dashboard_1",
"description": null,
"documentation": null,
"end_line_number": 127,
"is_anonymous": false,
"label": null,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"placeholder": null,
"resource_name": "sample_input_1",
"source_definition": " input \"sample_input_1\" {\n sql = \"select 1 as input\"\n width = 2\n title = \"Sample input 1\"\n }",
"sql": "select 1 as input",
"start_line_number": 123,
"tags": null,
"title": "Sample input 1",
"type": null,
"width": "2"
}
]

View File

@@ -0,0 +1,29 @@
[
{
"args": null,
"auto_generated": false,
"columns": null,
"description": null,
"documentation": null,
"end_line_number": 121,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"params": null,
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"resource_name": "sample_table_1",
"source_definition": " table \"sample_table_1\" {\n sql = \"select 1 as table\"\n width = 4\n title = \"Sample table 1\"\n }",
"sql": "select 1 as table",
"start_line_number": 117,
"tags": null,
"title": "Sample table 1",
"type": null,
"width": "4"
}
]

View File

@@ -0,0 +1,26 @@
[
{
"auto_generated": false,
"description": null,
"documentation": null,
"end_line_number": 61,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.dashboard.sample_dashboard_1",
"introspection_table_mod.container.sample_conatiner_1",
"introspection_table_mod.text.sample_text_1"
]
],
"resource_name": "sample_text_1",
"source_definition": "\t\ttext \"sample_text_1\" {\n\t\t\ttitle = \"Sample text 1\"\n\t\t}",
"start_line_number": 59,
"tags": null,
"title": "Sample text 1",
"type": null,
"value": null,
"width": null
}
]

View File

@@ -0,0 +1,40 @@
[
{
"args": null,
"auto_generated": false,
"description": "query 1 - 3 params all with defaults",
"documentation": null,
"end_line_number": 23,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"params": [
{
"default": "steampipe_var",
"description": "p1",
"name": "p1"
},
{
"default": "because_def ",
"description": "p2",
"name": "p2"
},
{
"default": "string",
"description": "p3",
"name": "p3"
}
],
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.query.sample_query_1"
]
],
"resource_name": "sample_query_1",
"source_definition": "query \"sample_query_1\"{\n\ttitle =\"Sample query 1\"\n\tdescription = \"query 1 - 3 params all with defaults\"\n\tsql = \"select 'ok' as status, 'steampipe' as resource, concat($1::text, $2::text, $3::text) as reason\"\n\tparam \"p1\"{\n\t\t\tdescription = \"p1\"\n\t\t\tdefault = var.sample_var_1\n\t}\n\tparam \"p2\"{\n\t\t\tdescription = \"p2\"\n\t\t\tdefault = \"because_def \"\n\t}\n\tparam \"p3\"{\n\t\t\tdescription = \"p3\"\n\t\t\tdefault = \"string\"\n\t}\n}",
"sql": "select 'ok' as status, 'steampipe' as resource, concat($1::text, $2::text, $3::text) as reason",
"start_line_number": 7,
"tags": null,
"title": "Sample query 1"
}
]

View File

@@ -0,0 +1,35 @@
[
{
"auto_generated": false,
"default_value": "steampipe_var",
"description": "",
"documentation": null,
"end_line_number": 4,
"is_anonymous": false,
"mod_name": "introspection_table_mod",
"path": [
[
"mod.introspection_table_mod",
"introspection_table_mod.var.sample_var_1"
],
[
"mod.introspection_table_mod",
"introspection_table_mod.var.sample_var_1"
],
[
"mod.introspection_table_mod",
"introspection_table_mod.var.sample_var_1"
]
],
"resource_name": "sample_var_1",
"source_definition": "variable \"sample_var_1\"{\n\ttype = string\n\tdefault = \"steampipe_var\"\n}",
"start_line_number": 1,
"tags": null,
"title": null,
"value": "steampipe_var",
"value_source": "config",
"value_source_end_line_number": 1,
"value_source_start_line_number": 1,
"var_type": "string"
}
]

View File

@@ -0,0 +1,342 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"
@test "steampipe_introspection=none" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=none
run steampipe query "select * from steampipe_query" --output json
assert_output --partial 'relation "steampipe_query" does not exist'
}
@test "resource=query | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_query" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 8th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "8d" output.json
else
run sed -i "8d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_query.json)"
rm -f output.json*
}
@test "resource=control | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_control" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 11th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "11d" output.json
else
run sed -i "11d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_control.json)"
rm -f output.json*
}
@test "resource=variable | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_variable" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 8th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "8d" output.json
run sed -i ".json" "32d" output.json
else
run sed -i "8d" output.json
run sed -i "32d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_variable.json)"
rm -f output.json*
}
@test "resource=benchmark | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_benchmark" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 10th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "10d" output.json
else
run sed -i "10d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_benchmark.json)"
rm -f output.json*
}
@test "resource=dashboard | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 11th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "11d" output.json
else
run sed -i "11d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard.json)"
rm -f output.json*
}
@test "resource=dashboard_card | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_card" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 8th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "8d" output.json
else
run sed -i "8d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_card.json)"
rm -f output.json*
}
@test "resource=dashboard_image | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_image" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 9th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "9d" output.json
else
run sed -i "9d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_image.json)"
rm -f output.json*
}
@test "resource=dashboard_text | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_text" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 7th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "7d" output.json
else
run sed -i "7d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_text.json)"
rm -f output.json*
}
@test "resource=dashboard_chart | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_chart" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 9th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "9d" output.json
else
run sed -i "9d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_chart.json)"
rm -f output.json*
}
@test "resource=dashboard_flow | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_flow" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 13th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "13d" output.json
else
run sed -i "13d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_flow.json)"
rm -f output.json*
}
@test "resource=dashboard_graph | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_graph" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 14th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "14d" output.json
else
run sed -i "14d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_graph.json)"
rm -f output.json*
}
@test "resource=dashboard_hierarchy | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_hierarchy" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 13th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "13d" output.json
else
run sed -i "13d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_hierarchy.json)"
rm -f output.json*
}
@test "resource=dashboard_input | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_input" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 9th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "9d" output.json
else
run sed -i "9d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_input.json)"
rm -f output.json*
}
@test "resource=dashboard_table | steampipe_introspection=info" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=info
steampipe query "select * from steampipe_dashboard_table" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 9th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "9d" output.json
else
run sed -i "9d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_dashboard_table.json)"
rm -f output.json*
}
@test "ensure mod name in introspection table is <mod_name> not mod.<mod_name>" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_query" --output json
# extract the first mod_name from the list
mod_name=$(echo $output | jq '.[0].mod_name')
# check if mod_name starts with "mod."
if [[ "$mod_name" == *"mod."* ]];
then
flag=1
else
flag=0
fi
assert_equal "$flag" "0"
}
@test "ensure query pseudo resources, i.e. sql files, have resource name <query_name> not <query.query_name>" {
cd $WORKSPACE_DIR
run steampipe query "select * from steampipe_query" --output json
# extract the first encountered sql file's file_name from the list
sql_file_name=$(echo $output | jq '.[].file_name' | grep ".sql" | head -1)
#extract the resource_name of the above extracted file_name
resource_name=$(echo $output | jq --arg FILENAME "$sql_file_name" '.[] | select(.file_name=="$FILENAME") | .resource_name')
# check if resource_name starts with "query."
if [[ "$resource_name" == *"query."* ]];
then
flag=1
else
flag=0
fi
assert_equal "$flag" "0"
}
@test "ensure the reference_from column is populated correctly" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_reference" --output json
# extract the refs and the referenced_by of the variable `sample_var_1`
refs=$(echo $output | jq '.[] | select(.reference_to=="var.sample_var_1") | .reference_from')
echo $refs
assert_equal "$refs" '"query.sample_query_1"'
}
@test "introspection tables should get populated in query batch mode" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_query" --output json
# extracting only description from the list, which is enough to prove that there is an output
description=$(echo $output | jq '.[].description')
assert_equal "$description" '"query 1 - 3 params all with defaults"'
}
@test "steampipe_introspection=control" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=control
steampipe query "select * from steampipe_control" --output json > output.json
# checking for OS type, since sed command is different for linux and OSX
# removing the 11th line, since it contains file location which would differ in github runners
if [[ "$OSTYPE" == "darwin"* ]]; then
run sed -i ".json" "11d" output.json
else
run sed -i "11d" output.json
fi
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_info_control.json)"
rm -f output.json*
}
@test "steampipe check --where | steampipe_introspection=control" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=control
steampipe check control.sample_control_1 --where "severity in ('high')" --export output.json
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_check_where.json)"
rm -f output.json*
}
@test "steampipe check --tag | steampipe_introspection=control" {
cd $SIMPLE_MOD_DIR
export STEAMPIPE_INTROSPECTION=control
steampipe check control.sample_control_1 --tag foo=bar --export output.json
assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_introspection_check_where.json)"
rm -f output.json*
}

View File

@@ -320,84 +320,6 @@ load "$LIB_BATS_SUPPORT/load.bash"
assert_equal "$content" ""
}
## introspection
@test "ensure mod name in introspection table is <mod_name> not mod.<mod_name>" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_query" --output json
# extract the first mod_name from the list
mod_name=$(echo $output | jq '.[0].mod_name')
# check if mod_name starts with "mod."
if [[ "$mod_name" == *"mod."* ]];
then
flag=1
else
flag=0
fi
assert_equal "$flag" "0"
}
@test "ensure query pseudo resources, i.e. sql files, have resource name <query_name> not <query.query_name>" {
cd $WORKSPACE_DIR
run steampipe query "select * from steampipe_query" --output json
# extract the first encountered sql file's file_name from the list
sql_file_name=$(echo $output | jq '.[].file_name' | grep ".sql" | head -1)
#extract the resource_name of the above extracted file_name
resource_name=$(echo $output | jq --arg FILENAME "$sql_file_name" '.[] | select(.file_name=="$FILENAME") | .resource_name')
# check if resource_name starts with "query."
if [[ "$resource_name" == *"query."* ]];
then
flag=1
else
flag=0
fi
assert_equal "$flag" "0"
}
@test "ensure the reference_to and reference_from columns are populated correctly" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_reference" --output json
# extract the refs and the referenced_by
refs=$(echo $output | jq '.[0].reference_to')
referenced_by=$(echo $output | jq '.[0].reference_from')
assert_equal "$refs" '"var.sample_var_1"'
assert_equal "$referenced_by" '"query.sample_query_1"'
}
@test "ensure the reference_to column includes variable references" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_reference" --output json
# extract the refs
refs=$(echo $output | jq '.[0].reference_to')
echo $refs
# check if refs contains variables(start with "var.")
if [[ "$refs" == *"var."* ]];
then
flag=1
else
flag=0
fi
assert_equal "$flag" "1"
}
@test "introspection tables should get populated in query batch mode" {
cd $SIMPLE_MOD_DIR
run steampipe query "select * from steampipe_query" --output json
# extracting only description from the list, which is enough to prove that there is an output
description=$(echo $output | jq '.[].description')
assert_equal "$description" '"query 1 - 3 params all with defaults"'
}
## traversal
# This test consists of a mod with nested folders, with mod.sp file within one of them(folder11).