github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/tests/acceptance/test_files/introspection.bats (about) 1 load "$LIB_BATS_ASSERT/load.bash" 2 load "$LIB_BATS_SUPPORT/load.bash" 3 4 @test "steampipe_introspection=none" { 5 cd $SIMPLE_MOD_DIR 6 export STEAMPIPE_INTROSPECTION=none 7 run steampipe query "select * from steampipe_query" --output json 8 9 assert_output --partial 'relation "steampipe_query" does not exist' 10 } 11 12 @test "resource=query | steampipe_introspection=info" { 13 cd $SIMPLE_MOD_DIR 14 export STEAMPIPE_INTROSPECTION=info 15 steampipe query "select * from steampipe_query" --output json > output.json 16 17 # checking for OS type, since sed command is different for linux and OSX 18 # removing the 9th line, since it contains file location which would differ in github runners 19 if [[ "$OSTYPE" == "darwin"* ]]; then 20 run sed -i ".json" "9d" output.json 21 else 22 run sed -i "9d" output.json 23 fi 24 25 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_query.json" output.json 26 echo $output 27 28 diff=$($FILE_PATH/json_patch.sh $output) 29 echo $diff 30 31 # check if there is no diff returned by the script 32 assert_equal "$diff" "" 33 rm -f output.json 34 } 35 36 @test "resource=control | steampipe_introspection=info" { 37 cd $SIMPLE_MOD_DIR 38 export STEAMPIPE_INTROSPECTION=info 39 steampipe query "select * from steampipe_control" --output json > output.json 40 41 # checking for OS type, since sed command is different for linux and OSX 42 # removing the 12th line, since it contains file location which would differ in github runners 43 if [[ "$OSTYPE" == "darwin"* ]]; then 44 run sed -i ".json" "12d" output.json 45 else 46 run sed -i "12d" output.json 47 fi 48 49 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_control.json" output.json 50 echo $output 51 52 diff=$($FILE_PATH/json_patch.sh $output) 53 echo $diff 54 55 # check if there is no diff returned by the script 56 assert_equal "$diff" "" 57 rm -f output.json 58 } 59 60 @test "resource=variable | steampipe_introspection=info" { 61 cd $SIMPLE_MOD_DIR 62 export STEAMPIPE_INTROSPECTION=info 63 steampipe query "select * from steampipe_variable" --output json > output.json 64 65 # checking for OS type, since sed command is different for linux and OSX 66 # removing the 8th line, since it contains file location which would differ in github runners 67 if [[ "$OSTYPE" == "darwin"* ]]; then 68 run sed -i ".json" "9d" output.json 69 run sed -i ".json" "34d" output.json 70 else 71 run sed -i "9d" output.json 72 run sed -i "34d" output.json 73 fi 74 75 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_variable.json" output.json 76 echo $output 77 78 diff=$($FILE_PATH/json_patch.sh $output) 79 echo $diff 80 81 # check if there is no diff returned by the script 82 assert_equal "$diff" "" 83 rm -f output.json 84 } 85 86 @test "resource=benchmark | steampipe_introspection=info" { 87 cd $SIMPLE_MOD_DIR 88 export STEAMPIPE_INTROSPECTION=info 89 steampipe query "select * from steampipe_benchmark" --output json > output.json 90 91 # checking for OS type, since sed command is different for linux and OSX 92 # removing the 11th line, since it contains file location which would differ in github runners 93 if [[ "$OSTYPE" == "darwin"* ]]; then 94 run sed -i ".json" "11d" output.json 95 else 96 run sed -i "11d" output.json 97 fi 98 99 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_benchmark.json" output.json 100 echo $output 101 102 diff=$($FILE_PATH/json_patch.sh $output) 103 echo $diff 104 105 # check if there is no diff returned by the script 106 assert_equal "$diff" "" 107 rm -f output.json 108 } 109 110 @test "resource=dashboard | steampipe_introspection=info" { 111 cd $SIMPLE_MOD_DIR 112 export STEAMPIPE_INTROSPECTION=info 113 steampipe query "select * from steampipe_dashboard" --output json > output.json 114 115 # checking for OS type, since sed command is different for linux and OSX 116 # removing the 12th line, since it contains file location which would differ in github runners 117 if [[ "$OSTYPE" == "darwin"* ]]; then 118 run sed -i ".json" "12d" output.json 119 else 120 run sed -i "12d" output.json 121 fi 122 123 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard.json" output.json 124 echo $output 125 126 diff=$($FILE_PATH/json_patch.sh $output) 127 echo $diff 128 129 # check if there is no diff returned by the script 130 assert_equal "$diff" "" 131 rm -f output.json 132 } 133 134 @test "resource=dashboard_card | steampipe_introspection=info" { 135 cd $SIMPLE_MOD_DIR 136 export STEAMPIPE_INTROSPECTION=info 137 steampipe query "select * from steampipe_dashboard_card" --output json > output.json 138 139 # checking for OS type, since sed command is different for linux and OSX 140 # removing the 8th line, since it contains file location which would differ in github runners 141 if [[ "$OSTYPE" == "darwin"* ]]; then 142 run sed -i ".json" "9d" output.json 143 else 144 run sed -i "9d" output.json 145 fi 146 147 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_card.json" output.json 148 echo $output 149 150 diff=$($FILE_PATH/json_patch.sh $output) 151 echo $diff 152 153 # check if there is no diff returned by the script 154 assert_equal "$diff" "" 155 rm -f output.json 156 } 157 158 @test "resource=dashboard_image | steampipe_introspection=info" { 159 cd $SIMPLE_MOD_DIR 160 export STEAMPIPE_INTROSPECTION=info 161 steampipe query "select * from steampipe_dashboard_image" --output json > output.json 162 163 # checking for OS type, since sed command is different for linux and OSX 164 # removing the 10th line, since it contains file location which would differ in github runners 165 if [[ "$OSTYPE" == "darwin"* ]]; then 166 run sed -i ".json" "10d" output.json 167 else 168 run sed -i "10d" output.json 169 fi 170 171 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_image.json" output.json 172 echo $output 173 174 diff=$($FILE_PATH/json_patch.sh $output) 175 echo $diff 176 177 # check if there is no diff returned by the script 178 assert_equal "$diff" "" 179 rm -f output.json 180 } 181 182 @test "resource=dashboard_text | steampipe_introspection=info" { 183 cd $SIMPLE_MOD_DIR 184 export STEAMPIPE_INTROSPECTION=info 185 steampipe query "select * from steampipe_dashboard_text" --output json > output.json 186 187 # checking for OS type, since sed command is different for linux and OSX 188 # removing the 8th line, since it contains file location which would differ in github runners 189 if [[ "$OSTYPE" == "darwin"* ]]; then 190 run sed -i ".json" "8d" output.json 191 else 192 run sed -i "8d" output.json 193 fi 194 195 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_text.json" output.json 196 echo $output 197 198 diff=$($FILE_PATH/json_patch.sh $output) 199 echo $diff 200 201 # check if there is no diff returned by the script 202 assert_equal "$diff" "" 203 rm -f output.json 204 } 205 206 @test "resource=dashboard_chart | steampipe_introspection=info" { 207 cd $SIMPLE_MOD_DIR 208 export STEAMPIPE_INTROSPECTION=info 209 steampipe query "select * from steampipe_dashboard_chart" --output json > output.json 210 211 # checking for OS type, since sed command is different for linux and OSX 212 # removing the 10th line, since it contains file location which would differ in github runners 213 if [[ "$OSTYPE" == "darwin"* ]]; then 214 run sed -i ".json" "10d" output.json 215 else 216 run sed -i "10d" output.json 217 fi 218 219 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_chart.json" output.json 220 echo $output 221 222 diff=$($FILE_PATH/json_patch.sh $output) 223 echo $diff 224 225 # check if there is no diff returned by the script 226 assert_equal "$diff" "" 227 rm -f output.json 228 } 229 230 @test "resource=dashboard_flow | steampipe_introspection=info" { 231 cd $SIMPLE_MOD_DIR 232 export STEAMPIPE_INTROSPECTION=info 233 steampipe query "select * from steampipe_dashboard_flow" --output json > output.json 234 235 # checking for OS type, since sed command is different for linux and OSX 236 # removing the 14th line, since it contains file location which would differ in github runners 237 if [[ "$OSTYPE" == "darwin"* ]]; then 238 run sed -i ".json" "14d" output.json 239 else 240 run sed -i "14d" output.json 241 fi 242 243 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_flow.json" output.json 244 echo $output 245 246 diff=$($FILE_PATH/json_patch.sh $output) 247 echo $diff 248 249 # check if there is no diff returned by the script 250 assert_equal "$diff" "" 251 rm -f output.json 252 } 253 254 @test "resource=dashboard_graph | steampipe_introspection=info" { 255 cd $SIMPLE_MOD_DIR 256 export STEAMPIPE_INTROSPECTION=info 257 steampipe query "select * from steampipe_dashboard_graph" --output json > output.json 258 259 # checking for OS type, since sed command is different for linux and OSX 260 # removing the 15th line, since it contains file location which would differ in github runners 261 if [[ "$OSTYPE" == "darwin"* ]]; then 262 run sed -i ".json" "15d" output.json 263 else 264 run sed -i "15d" output.json 265 fi 266 267 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_graph.json" output.json 268 echo $output 269 270 diff=$($FILE_PATH/json_patch.sh $output) 271 echo $diff 272 273 # check if there is no diff returned by the script 274 assert_equal "$diff" "" 275 rm -f output.json 276 } 277 278 @test "resource=dashboard_hierarchy | steampipe_introspection=info" { 279 cd $SIMPLE_MOD_DIR 280 export STEAMPIPE_INTROSPECTION=info 281 steampipe query "select * from steampipe_dashboard_hierarchy" --output json > output.json 282 283 # checking for OS type, since sed command is different for linux and OSX 284 # removing the 14th line, since it contains file location which would differ in github runners 285 if [[ "$OSTYPE" == "darwin"* ]]; then 286 run sed -i ".json" "14d" output.json 287 else 288 run sed -i "14d" output.json 289 fi 290 291 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_hierarchy.json" output.json 292 echo $output 293 294 diff=$($FILE_PATH/json_patch.sh $output) 295 echo $diff 296 297 # check if there is no diff returned by the script 298 assert_equal "$diff" "" 299 rm -f output.json 300 } 301 302 @test "resource=dashboard_input | steampipe_introspection=info" { 303 cd $SIMPLE_MOD_DIR 304 export STEAMPIPE_INTROSPECTION=info 305 steampipe query "select * from steampipe_dashboard_input" --output json > output.json 306 307 # checking for OS type, since sed command is different for linux and OSX 308 # removing the 10th line, since it contains file location which would differ in github runners 309 if [[ "$OSTYPE" == "darwin"* ]]; then 310 run sed -i ".json" "10d" output.json 311 else 312 run sed -i "10d" output.json 313 fi 314 315 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_input.json" output.json 316 echo $output 317 318 diff=$($FILE_PATH/json_patch.sh $output) 319 echo $diff 320 321 # check if there is no diff returned by the script 322 assert_equal "$diff" "" 323 rm -f output.json 324 } 325 326 @test "resource=dashboard_table | steampipe_introspection=info" { 327 cd $SIMPLE_MOD_DIR 328 export STEAMPIPE_INTROSPECTION=info 329 steampipe query "select * from steampipe_dashboard_table" --output json > output.json 330 331 # checking for OS type, since sed command is different for linux and OSX 332 # removing the 10th line, since it contains file location which would differ in github runners 333 if [[ "$OSTYPE" == "darwin"* ]]; then 334 run sed -i ".json" "10d" output.json 335 else 336 run sed -i "10d" output.json 337 fi 338 339 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_dashboard_table.json" output.json 340 echo $output 341 342 diff=$($FILE_PATH/json_patch.sh $output) 343 echo $diff 344 345 # check if there is no diff returned by the script 346 assert_equal "$diff" "" 347 rm -f output.json 348 } 349 350 @test "ensure mod name in introspection table is <mod_name> not mod.<mod_name>" { 351 cd $SIMPLE_MOD_DIR 352 run steampipe query "select * from steampipe_query" --output json 353 354 # extract the first mod_name from the list 355 mod_name=$(echo $output | jq '.rows[0].mod_name') 356 357 # check if mod_name starts with "mod." 358 if [[ "$mod_name" == *"mod."* ]]; 359 then 360 flag=1 361 else 362 flag=0 363 fi 364 assert_equal "$flag" "0" 365 } 366 367 @test "ensure query pseudo resources, i.e. sql files, have resource name <query_name> not <query.query_name>" { 368 cd $WORKSPACE_DIR 369 run steampipe query "select * from steampipe_query" --output json 370 371 # extract the first encountered sql file's file_name from the list 372 sql_file_name=$(echo $output | jq '.rows[0].file_name' | grep ".sql" | head -1) 373 374 #extract the resource_name of the above extracted file_name 375 resource_name=$(echo $output | jq --arg FILENAME "$sql_file_name" '.rows[0] | select(.file_name=="$FILENAME") | .resource_name') 376 377 # check if resource_name starts with "query." 378 if [[ "$resource_name" == *"query."* ]]; 379 then 380 flag=1 381 else 382 flag=0 383 fi 384 assert_equal "$flag" "0" 385 } 386 387 @test "ensure the reference_from column is populated correctly" { 388 skip 389 cd $SIMPLE_MOD_DIR 390 run steampipe query "select * from steampipe_reference" --output json 391 392 # extract the refs and the referenced_by of the variable `sample_var_1` 393 refs=$(echo $output | jq '.rows[0] | select(.reference_to=="var.sample_var_1") | .reference_from') 394 echo $refs 395 396 assert_equal "$refs" '"query.sample_query_1"' 397 } 398 399 @test "introspection tables should get populated in query batch mode" { 400 cd $SIMPLE_MOD_DIR 401 run steampipe query "select * from steampipe_query" --output json 402 403 # extracting only description from the list, which is enough to prove that there is an output 404 description=$(echo $output | jq '.rows[0].description') 405 assert_equal "$description" '"query 1 - 3 params all with defaults"' 406 } 407 408 @test "steampipe_introspection=control" { 409 cd $SIMPLE_MOD_DIR 410 export STEAMPIPE_INTROSPECTION=control 411 steampipe query "select * from steampipe_control" --output json > output.json 412 413 # checking for OS type, since sed command is different for linux and OSX 414 # removing the 12th line, since it contains file location which would differ in github runners 415 if [[ "$OSTYPE" == "darwin"* ]]; then 416 run sed -i ".json" "12d" output.json 417 else 418 run sed -i "12d" output.json 419 fi 420 421 run jd -f patch "$TEST_DATA_DIR/expected_introspection_info_control.json" output.json 422 echo $output 423 424 diff=$($FILE_PATH/json_patch.sh $output) 425 echo $diff 426 427 # check if there is no diff returned by the script 428 assert_equal "$diff" "" 429 rm -f output.json 430 } 431 432 @test "steampipe check --where | steampipe_introspection=control" { 433 cd $SIMPLE_MOD_DIR 434 export STEAMPIPE_INTROSPECTION=control 435 steampipe check control.sample_control_1 --where "severity in ('high')" --export output.json 436 437 run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json 438 echo $output 439 assert_success 440 rm -f output.json 441 } 442 443 @test "steampipe check --tag | steampipe_introspection=control" { 444 cd $SIMPLE_MOD_DIR 445 export STEAMPIPE_INTROSPECTION=control 446 steampipe check control.sample_control_1 --tag foo=bar --export output.json 447 448 run jd "$TEST_DATA_DIR/expected_introspection_check_where.json" output.json 449 echo $output 450 assert_success 451 rm -f output.json 452 } 453 454 function teardown_file() { 455 # list running processes 456 ps -ef | grep steampipe 457 458 # check if any processes are running 459 num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ') 460 assert_equal $num 0 461 }