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

     1  load "$LIB_BATS_ASSERT/load.bash"
     2  load "$LIB_BATS_SUPPORT/load.bash"
     3  
     4  ## connection config tests
     5  
     6  @test "steampipe aggregator connection wildcard check" {
     7      skip
     8      run steampipe plugin install chaos
     9      run steampipe plugin install steampipe
    10      cp $SRC_DATA_DIR/aggregator.spc $STEAMPIPE_INSTALL_DIR/config/chaos_agg.spc
    11      run steampipe query "select * from chaos_group.chaos_all_column_types"
    12      assert_success
    13  }
    14  
    15  @test "steampipe aggregator connection check total results" {
    16      skip
    17      run steampipe query "select * from chaos.chaos_all_numeric_column" --output json
    18  
    19      # store the length of the result when queried using `chaos` connection
    20      length_chaos=$(echo $output | jq length)
    21  
    22      run steampipe query "select * from chaos2.chaos_all_numeric_column" --output json
    23  
    24      # store the length of the result when queried using `chaos2` connection
    25      length_chaos_2=$(echo $output | jq length)
    26  
    27      run steampipe query "select * from chaos_group.chaos_all_numeric_column" --output json
    28  
    29      # store the length of the result when queried using `chaos_group` aggregated connection
    30      length_chaos_agg=$(echo $output | jq length)
    31  
    32      # since the aggregator connection `chaos_group` contains two chaos connections, we expect
    33      # the number of results returned will be the summation of the two
    34      assert_equal "$length_chaos_agg" "$((length_chaos+length_chaos_2))"
    35  }
    36  
    37  @test "steampipe aggregator connections should fail when querying a different plugin" {
    38      skip
    39      run steampipe query "select * from chaos_group.chaos_all_numeric_column order by id"
    40  
    41      # this should pass since the aggregator contains only chaos connections
    42      assert_success
    43      
    44      run steampipe query "select * from chaos_group.steampipe_registry_plugin order by id"
    45  
    46      # this should fail since the aggregator contains only chaos connections, and we are
    47      # querying a steampipe table
    48      assert_failure
    49  }
    50  
    51  @test "steampipe json connection config" {
    52      cp $SRC_DATA_DIR/chaos2.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
    53  
    54      run steampipe query "select time_col from chaos4.chaos_cache_check"
    55  
    56      # remove the config file
    57      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
    58  
    59      assert_success
    60  }
    61  
    62  @test "steampipe should return an error for duplicate connection name" {
    63      cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos2.json
    64      cp $SRC_DATA_DIR/chaos.json $STEAMPIPE_INSTALL_DIR/config/chaos3.json
    65      
    66      # this should fail because of duplicate connection name
    67      run steampipe query "select time_col from chaos.chaos_cache_check"
    68  
    69      # remove the config file
    70      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos2.json
    71      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos3.json
    72  
    73      assert_output --partial 'duplicate connection name'
    74  }
    75  
    76  @test "steampipe yaml connection config" {
    77      cp $SRC_DATA_DIR/chaos2.yml $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
    78  
    79      steampipe query "select 1"
    80  
    81      run steampipe query "select time_col from chaos5.chaos_cache_check"
    82  
    83      # remove the config file
    84      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos3.yml
    85  
    86      assert_success
    87  }
    88  
    89  @test "steampipe test connection config with options(hcl)" {
    90      cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
    91  
    92      steampipe query "select 1"
    93  
    94      run steampipe query "select time_col from chaos6.chaos_cache_check"
    95  
    96      # remove the config file
    97      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
    98  
    99      assert_success
   100  }
   101  
   102  @test "steampipe test connection config with options(yml)" {
   103      cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
   104  
   105      steampipe query "select 1"
   106  
   107      run steampipe query "select time_col from chaos6.chaos_cache_check"
   108      # remove the config file
   109      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
   110  
   111      assert_success
   112  }
   113  
   114  @test "steampipe test connection config with options(json)" {
   115      cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
   116  
   117      steampipe query "select 1"
   118  
   119      run steampipe query "select time_col from chaos6.chaos_cache_check"
   120      # remove the config file
   121      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
   122  
   123      assert_success
   124  }
   125  
   126  @test "steampipe check regions in connection config is being parsed and used(hcl)" {
   127      cp $SRC_DATA_DIR/chaos_options.spc $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
   128  
   129      steampipe query "select 1"
   130  
   131      # check regions in connection config is being parsed and used
   132      run steampipe query "select id,region_name from chaos6.chaos_regions order by id" --output json
   133      result=$(echo $output | tr -d '[:space:]')
   134      # set the trimmed result as output
   135      run echo $result
   136      echo $output
   137  
   138      # remove the config file
   139      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.spc
   140      # check output
   141      assert_output --partial '[{"id":0,"region_name":"us-east-1"},{"id":3,"region_name":"us-west-2"}]'
   142  
   143  }
   144  
   145  @test "steampipe check regions in connection config is being parsed and used(yml)" {
   146      cp $SRC_DATA_DIR/chaos_options.yml $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
   147  
   148      steampipe query "select 1"
   149  
   150      # check regions in connection config is being parsed and used
   151      run steampipe query "select id,region_name from chaos6.chaos_regions order by id" --output json
   152      result=$(echo $output | tr -d '[:space:]')
   153      # set the trimmed result as output
   154      run echo $result
   155      echo $output
   156  
   157      # remove the config file
   158      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.yml
   159      # check output
   160      assert_output --partial '[{"id":0,"region_name":"us-east-1"},{"id":3,"region_name":"us-west-2"}]'
   161  
   162  }
   163  
   164  @test "steampipe check regions in connection config is being parsed and used(json)" {
   165      cp $SRC_DATA_DIR/chaos_options.json $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
   166  
   167      steampipe query "select 1"
   168  
   169      # check regions in connection config is being parsed and used
   170      run steampipe query "select id,region_name from chaos6.chaos_regions order by id" --output json
   171      result=$(echo $output | tr -d '[:space:]')
   172      # set the trimmed result as output
   173      run echo $result
   174      echo $output
   175  
   176      # remove the config file
   177      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_options.json
   178      # check output
   179      assert_output --partial '[{"id":0,"region_name":"us-east-1"},{"id":3,"region_name":"us-west-2"}]'
   180  
   181  }
   182  
   183  @test "connection name escaping" {
   184      cp $SRC_DATA_DIR/chaos_conn_name_escaping.spc $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
   185  
   186      steampipe query "select 1"
   187  
   188      # keywords should be escaped properly
   189      run steampipe query "select * from \"escape\".chaos_limit limit 1"
   190  
   191      # remove the config file
   192      rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_conn_name_escaping.spc
   193  
   194      assert_success
   195  }
   196  
   197  @test "cleanup" {
   198    rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_agg.spc
   199    run steampipe plugin uninstall steampipe
   200    rm -f $STEAMPIPE_INSTALL_DIR/config/steampipe.spc
   201  }
   202  
   203  function teardown_file() {
   204    # list running processes
   205    ps -ef | grep steampipe
   206  
   207    # check if any processes are running
   208    num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
   209    assert_equal $num 0
   210  }