github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/tests/acceptance/test_files/chaos_and_query.bats (about) 1 load "$LIB_BATS_ASSERT/load.bash" 2 load "$LIB_BATS_SUPPORT/load.bash" 3 4 @test "select from chaos.chaos_high_row_count order by column_0" { 5 run steampipe query --output json "select column_0,column_1,column_2,column_3,column_4,column_5,column_6,column_7,column_8,column_9,id from chaos.chaos_high_row_count order by column_0 limit 10" 6 echo $output > $TEST_DATA_DIR/actual_1.json 7 8 # verify that the json contents of actual_1 and expected_1 files are the same 9 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_1.json 10 echo $output 11 12 diff=$($FILE_PATH/json_patch.sh $output) 13 echo $diff 14 # check if there is no diff returned by the script 15 assert_equal "$diff" "" 16 17 rm -f $TEST_DATA_DIR/actual_1.json 18 } 19 20 @test "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'" { 21 run steampipe query --output json "select id, string_column, json_column, boolean_column from chaos.chaos_all_column_types where id='0'" 22 echo $output > $TEST_DATA_DIR/actual_1.json 23 24 # verify that the json contents of actual_1 and expected_2 files are the same 25 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_2.json 26 echo $output 27 28 diff=$($FILE_PATH/json_patch.sh $output) 29 echo $diff 30 # check if there is no diff returned by the script 31 assert_equal "$diff" "" 32 33 rm -f $TEST_DATA_DIR/actual_1.json 34 } 35 36 @test "select from chaos.chaos_high_column_count order by column_0" { 37 run steampipe query --output json "select * from chaos.chaos_high_column_count order by column_0 limit 10" 38 echo $output > $TEST_DATA_DIR/actual_1.json 39 40 # verify that the json contents of actual_1 and expected_3 files are the same 41 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_3.json 42 echo $output 43 44 diff=$($FILE_PATH/json_patch.sh $output) 45 echo $diff 46 # check if there is no diff returned by the script 47 assert_equal "$diff" "" 48 49 rm -f $TEST_DATA_DIR/actual_1.json 50 } 51 52 @test "select from chaos.chaos_hydrate_columns_dependency where id='0'" { 53 run steampipe query --output json "select hydrate_column_1,hydrate_column_2,hydrate_column_3,hydrate_column_4,hydrate_column_5,id from chaos.chaos_hydrate_columns_dependency where id='0'" 54 echo $output > $TEST_DATA_DIR/actual_1.json 55 56 # verify that the json contents of actual_1 and expected_5 files are the same 57 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_5.json 58 echo $output 59 60 diff=$($FILE_PATH/json_patch.sh $output) 61 echo $diff 62 # check if there is no diff returned by the script 63 assert_equal "$diff" "" 64 65 rm -f $TEST_DATA_DIR/actual_1.json 66 } 67 68 @test "select from chaos.chaos_list_error" { 69 run steampipe query "select fatal_error from chaos.chaos_list_errors" 70 assert_output --partial 'fatalError' 71 } 72 73 @test "select panic from chaos.chaos_get_errors where id=0" { 74 run steampipe query --output json "select panic from chaos.chaos_get_errors where id=0" 75 assert_output --partial 'Panic' 76 } 77 78 @test "select error from chaos_transform_errors" { 79 skip "skipped till chaos_transform_errors table is modified" 80 run steampipe query "select error from chaos_transform_errors" 81 assert_output --partial 'TRANSFORM ERROR' 82 } 83 84 @test "select from chaos.chaos_hydrate_delay" { 85 run steampipe query --output json "select delay from chaos.chaos_hydrate_errors order by id" 86 assert_success 87 } 88 89 @test "select from chaos.chaos_parallel_hydrate_columns where id='0'" { 90 run steampipe query --output json "select column_1,column_10,column_11,column_12,column_13,column_14,column_15,column_16,column_17,column_18,column_19,column_2,column_20,column_3,column_4,column_5,column_6,column_7,column_8,column_9,id from chaos.chaos_parallel_hydrate_columns where id='0'" 91 echo $output > $TEST_DATA_DIR/actual_1.json 92 93 # verify that the json contents of actual_1 and expected_11 files are the same 94 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_11.json 95 echo $output 96 97 diff=$($FILE_PATH/json_patch.sh $output) 98 echo $diff 99 # check if there is no diff returned by the script 100 assert_equal "$diff" "" 101 102 rm -f $TEST_DATA_DIR/actual_1.json 103 } 104 105 @test "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'" { 106 run steampipe query --output json "select float32_data, id, int64_data, uint16_data from chaos.chaos_all_numeric_column where id='31'" 107 echo $output > $TEST_DATA_DIR/actual_1.json 108 109 # verify that the json contents of actual_1 and expected_12 files are the same 110 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_12.json 111 echo $output 112 113 diff=$($FILE_PATH/json_patch.sh $output) 114 echo $diff 115 # check if there is no diff returned by the script 116 assert_equal "$diff" "" 117 118 rm -f $TEST_DATA_DIR/actual_1.json 119 } 120 121 @test "select transform_method_column from chaos_transforms order by id" { 122 run steampipe query --output json "select transform_method_column from chaos_transforms order by id" 123 echo $output > $TEST_DATA_DIR/actual_1.json 124 125 # verify that the json contents of actual_1 and expected_14 files are the same 126 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_14.json 127 echo $output 128 129 diff=$($FILE_PATH/json_patch.sh $output) 130 echo $diff 131 # check if there is no diff returned by the script 132 assert_equal "$diff" "" 133 134 rm -f $TEST_DATA_DIR/actual_1.json 135 } 136 137 @test "select parent_should_ignore_error from chaos.chaos_list_parent_child" { 138 run steampipe query "select parent_should_ignore_error from chaos.chaos_list_parent_child" 139 assert_success 140 } 141 142 @test "select from_qual_column from chaos_transforms where id=2" { 143 run steampipe query --output json "select from_qual_column from chaos_transforms where id=2" 144 echo $output > $TEST_DATA_DIR/actual_1.json 145 146 # verify that the json contents of actual_1 and expected_13 files are the same 147 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_13.json 148 echo $output 149 150 diff=$($FILE_PATH/json_patch.sh $output) 151 echo $diff 152 # check if there is no diff returned by the script 153 assert_equal "$diff" "" 154 155 rm -f $TEST_DATA_DIR/actual_1.json 156 } 157 158 @test "public schema insert select all types" { 159 skip 160 steampipe query "drop table if exists all_columns" 161 steampipe query "create table all_columns (nullcolumn CHAR(2), booleancolumn boolean, textcolumn1 CHAR(20), textcolumn2 VARCHAR(20), textcolumn3 text, integercolumn1 smallint, integercolumn2 int, integercolumn3 SERIAL, integercolumn4 bigint, integercolumn5 bigserial, numericColumn numeric(6,4), realColumn real, floatcolumn float, date1 DATE, time1 TIME, timestamp1 TIMESTAMP, timestamp2 TIMESTAMPTZ, interval1 INTERVAL, array1 text[], jsondata jsonb, jsondata2 json, uuidcolumn UUID, ipAddress inet, macAddress macaddr, cidrRange cidr, xmlData xml, currency money)" 162 steampipe query "INSERT INTO all_columns (nullcolumn, booleancolumn, textcolumn1, textcolumn2, textcolumn3, integercolumn1, integercolumn2, integercolumn3, integercolumn4, integercolumn5, numericColumn, realColumn, floatcolumn, date1, time1, timestamp1, timestamp2, interval1, array1, jsondata, jsondata2, uuidcolumn, ipAddress, macAddress, cidrRange, xmlData, currency) VALUES (NULL, TRUE, 'Yes', 'test for varchar', 'This is a very long text for the PostgreSQL text column', 3278, 21445454, 2147483645, 92233720368547758, 922337203685477580, 23.5141543, 4660.33777, 4.6816421254887534, '1978-02-05', '08:00:00', '2016-06-22 19:10:25-07', '2016-06-22 19:10:25-07', '1 year 2 months 3 days', '{\"(408)-589-5841\"}','{ \"customer\": \"John Doe\", \"items\": {\"product\": \"Beer\",\"qty\": 6}}', '{ \"customer\": \"John Doe\", \"items\": {\"product\": \"Beer\",\"qty\": 6}}', '6948DF80-14BD-4E04-8842-7668D9C001F5', '192.168.0.0', '08:00:2b:01:02:03', '10.1.2.3/32', '<book><title>Manual</title><chapter>...</chapter></book>', 922337203685477.57)" 163 run steampipe query "select * from all_columns" --output json 164 echo $output > $TEST_DATA_DIR/actual_1.json 165 166 # verify that the json contents of actual_1 and expected_6 files are the same 167 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_6.json 168 echo $output 169 170 diff=$($FILE_PATH/json_patch.sh $output) 171 echo $diff 172 # check if there is no diff returned by the script 173 assert_equal "$diff" "" 174 175 rm -f $TEST_DATA_DIR/actual_1.json 176 run steampipe query "drop table all_columns" 177 } 178 179 @test "query json" { 180 run steampipe query "select 1 as val, 2 as col" --output json 181 echo $output > $TEST_DATA_DIR/actual_1.json 182 183 # verify that the json contents of actual_1 and expected_query_json files are the same 184 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_query_json.json 185 echo $output 186 187 diff=$($FILE_PATH/json_patch.sh $output) 188 echo $diff 189 # check if there is no diff returned by the script 190 assert_equal "$diff" "" 191 192 rm -f $TEST_DATA_DIR/actual_1.json 193 } 194 195 @test "query csv" { 196 run steampipe query "select 1 as val, 2 as col" --output csv 197 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_query_csv.csv)" 198 } 199 200 @test "query line" { 201 run steampipe query "select 1 as val, 2 as col" --output line 202 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_query_line.txt)" 203 } 204 205 @test "query line long" { 206 run steampipe query "drop table if exists long_columns" 207 run steampipe query "create table long_columns (shortstring char(20), longstring char(3900))" 208 run steampipe query "INSERT INTO long_columns (shortstring,longstring) VALUES ('a short text','tincidunt dui ut ornare lectus sit amet est placerat in egestas erat imperdiet sed euismod nisi porta lorem mollis aliquam ut porttitor leo a diam sollicitudin tempor id eu nisl nunc mi ipsum faucibus vitae aliquet nec ullamcorper sit amet risus nullam eget felis eget nunc lobortis mattis aliquam faucibus purus in massa tempor nec feugiat nisl pretium fusce id velit ut tortor pretium viverra suspendisse potenti nullam ac tortor vitae purus faucibus ornare suspendisse sed nisi lacus sed viverra tellus in hac habitasse platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget arcu dictum varius duis at consectetur lorem donec massa sapien faucibus et molestie ac feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu augue ut lectus arcu bibendum at varius vel pharetra vel turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet bibendum enim facilisis gravida neque convallis a cras semper auctor neque vitae tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut faucibus pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt eget nullam non nisi est sit amet facilisis magna etiam tempor orci eu lobortis elementum nibh tellus molestie nunc non blandit massa enim nec dui nunc mattis enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque penatibus et magnis dis parturient montes nascetur ridiculus mus mauris vitae ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan lacus vel facilisis volutpat est velit egestas dui id ornare arcu odio ut sem nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit amet mattis vulputate enim nulla aliquet porttitor lacus luctus accumsan tortor posuere ac ut consequat semper viverra nam libero justo laoreet sit amet cursus sit amet dictum sit amet justo donec enim diam vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean euismod elementum nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque viverra justo nec ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis in eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod quis viverra nibh cras pulvinar mattis nunc sed blandit libero volutpat sed cras ornare arcu dui vivamus arcu felis bibendum ut tristique et egestas quis ipsum suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim sit amet venenatis urna cursus eget nunc scelerisque viverra mauris in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet risus feugiat in ante metus dictum at tempor commodo ullamcorper a lacus vestibulum sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in dictum non consectetur a erat nam at lectus urna duis')" 209 run steampipe query "select * from long_columns" --output line 210 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_line_long.txt)" 211 run steampipe query "drop table long_columns" 212 } 213 214 @test "query csv header off" { 215 run steampipe query "select 1 as val, 2 as col" --output csv --header=false 216 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_query_csv_header_off.csv)" 217 } 218 219 @test "query table header off" { 220 run steampipe query "select 1 as val, 2 as col" --header=false 221 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_query_table_header_off.txt)" 222 } 223 224 @test "table with header" { 225 run steampipe query "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 226 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_table_header.txt)" 227 } 228 229 @test "table no header" { 230 run steampipe query "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" --header=false 231 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_table_no_header.txt)" 232 } 233 234 @test "table with null values" { 235 run steampipe query "select 1 as id, 2 as val1, null as val2" 236 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_table_with_null_values.txt)" 237 } 238 239 @test "csv with null values" { 240 run steampipe query --output csv "select 1 as id, 2 as val1, null as val2" 241 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_csv_with_null_values.csv)" 242 } 243 244 @test "csv header" { 245 run steampipe query --output csv "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 246 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_csv_header.csv)" 247 } 248 249 @test "csv no header" { 250 run steampipe query --output csv "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" --header=false 251 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_csv_no_header.csv)" 252 } 253 254 @test "csv | separator" { 255 run steampipe query --output csv --separator "|" "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 256 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_csv_separator_header.csv)" 257 } 258 259 @test "csv | separator no header" { 260 run steampipe query --output csv --separator "|" "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" --header=false 261 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_csv_separator_no_header.csv)" 262 } 263 264 @test "json" { 265 run steampipe query --output json "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 266 echo $output > $TEST_DATA_DIR/actual_1.json 267 268 # verify that the json contents of actual_1 and expected_json files are the same 269 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_json.json 270 echo $output 271 272 diff=$($FILE_PATH/json_patch.sh $output) 273 echo $diff 274 # check if there is no diff returned by the script 275 assert_equal "$diff" "" 276 277 rm -f $TEST_DATA_DIR/actual_1.json 278 } 279 280 @test "line" { 281 run steampipe query --output line "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 282 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_line.txt)" 283 } 284 285 @test "timer on" { 286 run steampipe query "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" --timing 287 assert_output --partial 'Time:' 288 } 289 290 @test "select query install directory" { 291 run steampipe query --output csv "select 1" --install-dir '~/.steampipe_test' 292 assert_success 293 } 294 295 @test "named query current folder" { 296 cd $FILE_PATH/test_data/mods/sample_workspace/query 297 run steampipe query query.named_query_1 298 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_named_query_current_folder.txt)" 299 } 300 301 @test "named query workspace folder" { 302 run steampipe query query.named_query_4 --mod-location "$FILE_PATH/test_data/mods/sample_workspace/" 303 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_workspace_folder.txt)" 304 } 305 306 @test "sql file" { 307 run steampipe query $FILE_PATH/test_data/mods/sample_workspace/query/named_query_7.sql 308 assert_equal "$output" "$(cat $TEST_DATA_DIR/expected_sql_file.txt)" 309 } 310 311 @test "sql file(not found)" { 312 run steampipe query $FILE_PATH/test_files/workspace_folder/query_folder/named_query_70.sql 313 assert_equal "$output" "Error: file '$FILE_PATH/test_files/workspace_folder/query_folder/named_query_70.sql' does not exist" 314 } 315 316 @test "verify fetch and hydrate data are populated with timing enabled" { 317 run steampipe query --timing "select id, string_column, json_column from chaos.chaos_all_column_types where id='0'" 318 assert_output --partial "Time" 319 assert_output --partial "Rows fetched" 320 assert_output --partial "Hydrate calls" 321 } 322 323 @test "verify empty json result is empty list and not null" { 324 run steampipe query "select * from steampipe_connection where plugin = 'random'" --output json 325 echo $output > $TEST_DATA_DIR/actual_1.json 326 327 # verify that the json contents of actual_1 and expected_query_empty_json files are the same 328 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_query_empty_json.json 329 echo $output 330 331 diff=$($FILE_PATH/json_patch.sh $output) 332 echo $diff 333 # check if there is no diff returned by the script 334 assert_equal "$diff" "" 335 336 rm -f $TEST_DATA_DIR/actual_1.json 337 } 338 339 @test "migrate legacy lock file" { 340 cd $FILE_PATH/test_data/mods/dependent_mod_with_legacy_lock 341 steampipe mod install 342 # run steampipe query twice - the bug we are testing for caused the workspace lock to be deleted after the first query 343 steampipe query "select 1 as a" --output json 344 run steampipe query "select 1 as a" --output json 345 echo $output > $TEST_DATA_DIR/actual_1.json 346 347 # verify that the json contents of actual_1 and expected_15 files are the same 348 run jd -f patch $TEST_DATA_DIR/actual_1.json $TEST_DATA_DIR/expected_15.json 349 echo $output 350 351 diff=$($FILE_PATH/json_patch.sh $output) 352 echo $diff 353 # check if there is no diff returned by the script 354 assert_equal "$diff" "" 355 356 rm -f $TEST_DATA_DIR/actual_1.json 357 } 358 359 function teardown_file() { 360 # list running processes 361 ps -ef | grep steampipe 362 363 # check if any processes are running 364 num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ') 365 assert_equal $num 0 366 }