github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/tests/acceptance/test_files/check.bats (about)

     1  load "$LIB_BATS_ASSERT/load.bash"
     2  load "$LIB_BATS_SUPPORT/load.bash"
     3  
     4  @test "steampipe check exitCode - no control alarms or errors" {
     5    cd $FUNCTIONALITY_TEST_MOD
     6    run steampipe check benchmark.all_controls_ok
     7    assert_equal $status 0
     8    cd -
     9  }
    10  
    11  @test "steampipe check exitCode - with controls in error" {
    12    cd $CONTROL_RENDERING_TEST_MOD
    13    run steampipe check benchmark.control_check_rendering_benchmark
    14    assert_equal $status 2
    15    cd -
    16  }
    17  
    18  #@test "steampipe check exitCode - with controls in alarm" {
    19  #  cd $FUNCTIONALITY_TEST_MOD
    20  #  run steampipe check benchmark.check_search_path_benchmark
    21  #  assert_equal $status 1
    22  #  cd -
    23  #}
    24  
    25  @test "steampipe check exitCode - with controls in error(running multiple benchmarks together)" {
    26    cd $FUNCTIONALITY_TEST_MOD
    27    run steampipe check benchmark.control_summary_benchmark benchmark.check_cache_benchmark
    28    assert_equal $status 2
    29    cd -
    30  }
    31  
    32  @test "steampipe check exitCode - runtime error(insufficient args)" {
    33    cd $FUNCTIONALITY_TEST_MOD
    34    run steampipe check
    35    assert_equal $status 254
    36    cd -
    37  }
    38  
    39  @test "steampipe check long control title" {
    40    cd $CONTROL_RENDERING_TEST_MOD
    41    export STEAMPIPE_DISPLAY_WIDTH=100
    42    run steampipe check control.control_long_title --progress=false --theme=plain
    43    assert_output --partial "$(cat $TEST_DATA_DIR/expected_long_title.txt)"
    44    cd -
    45  }
    46  
    47  @test "steampipe check short control title" {
    48    cd $CONTROL_RENDERING_TEST_MOD
    49    export STEAMPIPE_DISPLAY_WIDTH=100
    50    run steampipe check control.control_short_title --progress=false --theme=plain
    51    assert_output --partial "$(cat $TEST_DATA_DIR/expected_short_title.txt)"
    52    cd -
    53  }
    54  
    55  @test "steampipe check unicode control title" {
    56    cd $CONTROL_RENDERING_TEST_MOD
    57    export STEAMPIPE_DISPLAY_WIDTH=100
    58    run steampipe check control.control_unicode_title --progress=false --theme=plain
    59    assert_output --partial "$(cat $TEST_DATA_DIR/expected_unicode_title.txt)"
    60    cd -
    61  }
    62  
    63  @test "steampipe check reasons(very long, very short, unicode)" {
    64    cd $CONTROL_RENDERING_TEST_MOD
    65    export STEAMPIPE_DISPLAY_WIDTH=100
    66    run steampipe check control.control_long_short_unicode_reasons --progress=false --theme=plain
    67    assert_output --partial "$(cat $TEST_DATA_DIR/expected_reasons.txt)"
    68    cd -
    69  }
    70  
    71  @test "steampipe check control with all possible statuses(10 OK, 5 ALARM, 2 ERROR, 1 SKIP and 3 INFO)" {
    72    cd $CONTROL_RENDERING_TEST_MOD
    73    export STEAMPIPE_DISPLAY_WIDTH=100
    74    run steampipe check control.sample_control_mixed_results_1 --progress=false --theme=plain
    75    assert_output --partial "$(cat $TEST_DATA_DIR/expected_mixed_results.txt)"
    76    cd -
    77  }
    78  
    79  @test "steampipe check control with all resources in ALARM" {
    80    cd $CONTROL_RENDERING_TEST_MOD
    81    export STEAMPIPE_DISPLAY_WIDTH=100
    82    run steampipe check control.sample_control_all_alarms --progress=false --theme=plain
    83    assert_output --partial "$(cat $TEST_DATA_DIR/expected_all_alarm.txt)"
    84    cd -
    85  }
    86  
    87  @test "steampipe check control with blank dimension" {
    88    cd $BLANK_DIMENSION_VALUE_TEST_MOD
    89    export STEAMPIPE_DISPLAY_WIDTH=100
    90    run steampipe check all --progress=false --theme=plain
    91    assert_output --partial "$(cat $TEST_DATA_DIR/expected_blank_dimension.txt)"
    92    cd -
    93  }
    94  
    95  @test "steampipe check - output csv - no header" {
    96    cd $CONTROL_RENDERING_TEST_MOD
    97    run steampipe check control.sample_control_mixed_results_1 --output=csv --progress=false --header=false
    98    assert_output --partial "$(cat $TEST_DATA_DIR/expected_check_csv_noheader.csv)"
    99    cd -
   100  }
   101  
   102  @test "steampipe check - output csv(check tags and dimensions sorting)" {
   103    cd $CONTROL_RENDERING_TEST_MOD
   104    run steampipe check control.sample_control_sorted_tags_and_dimensions --output=csv --progress=false
   105    assert_output --partial "$(cat $TEST_DATA_DIR/expected_check_csv_sorted_tags.csv)"
   106    cd -
   107  }
   108  
   109  @test "steampipe check - output json" {
   110    cd $CONTROL_RENDERING_TEST_MOD
   111    run steampipe check control.sample_control_mixed_results_1 --output json --progress=false --export output.json
   112    output=""
   113    run jd "$TEST_DATA_DIR/expected_check_json.json" output.json
   114    echo $output
   115    assert_success
   116    rm -f output.json
   117    cd -
   118  }
   119  
   120  @test "steampipe check - export csv" {
   121    cd $CONTROL_RENDERING_TEST_MOD
   122    run steampipe check control.sample_control_mixed_results_1 --export test.csv --progress=false
   123    assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv.csv)"
   124    rm -f test.csv
   125    cd -
   126  }
   127  
   128  @test "steampipe check - export csv - pipe separator" {
   129    cd $CONTROL_RENDERING_TEST_MOD
   130    run steampipe check control.sample_control_mixed_results_1 --export test.csv --separator="|" --progress=false
   131    assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv_pipe_separator.csv)"
   132    rm -f test.csv
   133    cd -
   134  }
   135  
   136  @test "steampipe check - export csv(check tags and dimensions sorting)" {
   137    cd $CONTROL_RENDERING_TEST_MOD
   138    run steampipe check control.sample_control_sorted_tags_and_dimensions --export test.csv --progress=false
   139    assert_equal "$(cat test.csv)" "$(cat $TEST_DATA_DIR/expected_check_csv_sorted_tags.csv)"
   140    rm -f test.csv
   141    cd -
   142  }
   143  
   144  @test "steampipe check - export json" {
   145    cd $CONTROL_RENDERING_TEST_MOD
   146    run steampipe check control.sample_control_mixed_results_1 --export test.json --progress=false
   147    output=""
   148    run jd "$TEST_DATA_DIR/expected_check_json.json" test.json
   149    echo $output
   150    assert_success
   151    rm -f output.json
   152    cd -
   153  }
   154  
   155  @test "steampipe check - export html" {
   156    cd $CONTROL_RENDERING_TEST_MOD
   157    run steampipe check control.sample_control_mixed_results_1 --export test.html --progress=false
   158    
   159    # checking for OS type, since sed command is different for linux and OSX
   160    # removing the 642nd line, since it contains file locations and timestamps
   161    if [[ "$OSTYPE" == "darwin"* ]]; then
   162      run sed -i ".html" "642d" test.html
   163      run sed -i ".html" "642d" test.html
   164      run sed -i ".html" "642d" test.html
   165    else
   166      run sed -i "642d" test.html
   167      run sed -i "642d" test.html
   168      run sed -i "642d" test.html
   169    fi
   170  
   171    assert_equal "$(cat test.html)" "$(cat $TEST_DATA_DIR/expected_check_html.html)"
   172    rm -rf test.html*
   173    cd -
   174  }
   175  
   176  @test "steampipe check - export md" {
   177    cd $CONTROL_RENDERING_TEST_MOD
   178    run steampipe check control.sample_control_mixed_results_1 --export test.md --progress=false
   179    
   180    # checking for OS type, since sed command is different for linux and OSX
   181    # removing the 42nd line, since it contains file locations and timestamps
   182    if [[ "$OSTYPE" == "darwin"* ]]; then
   183      run sed -i ".md" "42d" test.md
   184    else
   185      run sed -i "42d" test.md
   186    fi
   187  
   188    assert_equal "$(cat test.md)" "$(cat $TEST_DATA_DIR/expected_check_markdown.md)"
   189    rm -rf test.md*
   190    cd -
   191  }
   192  
   193  @test "steampipe check - export nunit3" {
   194    cd $CONTROL_RENDERING_TEST_MOD
   195    run steampipe check control.sample_control_mixed_results_1 --export test.xml --progress=false
   196  
   197    # checking for OS type, since sed command is different for linux and OSX
   198    # removing the 6th line, since it contains duration, and duration will be different in each run
   199    if [[ "$OSTYPE" == "darwin"* ]]; then
   200      run sed -i ".xml" "6d" test.xml
   201    else
   202      run sed -i "6d" test.xml
   203    fi
   204  
   205    assert_equal "$(cat test.xml)" "$(cat $TEST_DATA_DIR/expected_check_nunit3.xml)"
   206    rm -f test.xml*
   207    cd -
   208  }
   209  
   210  @test "steampipe check - export snapshot" {
   211    cd $CONTROL_RENDERING_TEST_MOD
   212    run steampipe check control.sample_control_mixed_results_1 --export test.sps --progress=false
   213  
   214    # get the patch diff between the two snapshots
   215    run jd -f patch $TEST_DATA_DIR/expected_check_snapshot.sps test.sps
   216  
   217    # run the script to evaluate the patch
   218    # returns nothing if there is no diff(except start_time, end_time & search_path)
   219    diff=$($FILE_PATH/json_patch.sh $output)
   220    echo $diff
   221    rm -f test.sps
   222  
   223    # check if there is no diff returned by the script
   224    assert_equal "$diff" ""
   225    cd -
   226  }
   227  
   228  @test "steampipe check all" {
   229    cd $CHECK_ALL_MOD
   230    run steampipe check all --export test.json --progress=false
   231    output=""
   232    run jd "$TEST_DATA_DIR/expected_check_all.json" test.json
   233    echo $output
   234    assert_success
   235    rm -f output.json
   236    cd -
   237  }
   238  
   239  @test "check all - export sps" {
   240    skip "not implemented yet"
   241  }
   242  @test "check all - export file.sps" {
   243    skip "not implemented yet"
   244  }
   245  @test "check single benchmark - export sps" {
   246    skip "not implemented yet"
   247  }
   248  @test "check single benchmark - export file.sps" {
   249    skip "not implemented yet"
   250  }
   251  @test "check multiple benchmark - export sps" {
   252    skip "not implemented yet"
   253  }
   254  @test "check multiple benchmark - export file.sps" {
   255    skip "not implemented yet"
   256  }
   257  
   258  @test "check all - export json" {
   259    skip "not implemented yet"
   260  }
   261  @test "check all - export file.json" {
   262    skip "not implemented yet"
   263  }
   264  @test "check single benchmark - export json" {
   265    skip "not implemented yet"
   266  }
   267  @test "check single benchmark - export file.json" {
   268    skip "not implemented yet"
   269  }
   270  @test "check multiple benchmark - export json" {
   271    skip "not implemented yet"
   272  }
   273  @test "check multiple benchmark - export file.json" {
   274    skip "not implemented yet"
   275  }
   276  
   277  @test "check all - export csv" {
   278    skip "not implemented yet"
   279  }
   280  @test "check all - export file.csv" {
   281    skip "not implemented yet"
   282  }
   283  @test "check single benchmark - export csv" {
   284    skip "not implemented yet"
   285  }
   286  @test "check single benchmark - export file.csv" {
   287    skip "not implemented yet"
   288  }
   289  @test "check multiple benchmark - export csv" {
   290    skip "not implemented yet"
   291  }
   292  @test "check multiple benchmark - export file.csv" {
   293    skip "not implemented yet"
   294  }
   295  
   296  ## check search_path tests
   297  
   298  #@test "steampipe check search_path_prefix when passed through command line" {
   299  #  cd $FUNCTIONALITY_TEST_MOD
   300  #  run steampipe check control.search_path_test_1 --output json --search-path-prefix aws --export test.json
   301  #  assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
   302  #  rm -f test.json
   303  #}
   304  
   305  #@test "steampipe check search_path when passed through command line" {
   306  #  cd $FUNCTIONALITY_TEST_MOD
   307  #  run steampipe check control.search_path_test_2 --output json --search-path chaos,b,c --export test.json
   308  #  assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
   309  #  rm -f test.json
   310  #}
   311  
   312  #@test "steampipe check search_path and search_path_prefix when passed through command line" {
   313  #  cd $FUNCTIONALITY_TEST_MOD
   314  #  run steampipe check control.search_path_test_3 --output json --search-path chaos,b,c --search-path-prefix aws --export test.json
   315  #  assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
   316  #  rm -f test.json
   317  #}
   318  
   319  
   320  
   321  ## plugin crash
   322  
   323  @test "check whether the plugin is crashing or not" {
   324    skip
   325    cd $FUNCTIONALITY_TEST_MOD
   326    run steampipe check benchmark.check_plugin_crash_benchmark
   327    echo $output
   328    [ $(echo $output | grep "ERROR: context canceled" | wc -l | tr -d ' ') -eq 0 ]
   329  }
   330  
   331  # testing the check summary output feature in steampipe
   332  @test "check summary output" {
   333    cd $FUNCTIONALITY_TEST_MOD
   334    run steampipe check benchmark.control_summary_benchmark --theme plain
   335  
   336    echo $output
   337  
   338    # TODO: Find a way to store the output in a file and match it with the 
   339    # expected file. For now the work-around is to check whether the output
   340    # contains `summary`
   341    assert_output --partial 'Summary'
   342  }
   343  
   344  function teardown_file() {
   345    # list running processes
   346    ps -ef | grep steampipe
   347  
   348    # check if any processes are running
   349    num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
   350    assert_equal $num 0
   351  }