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

     1  load "$LIB_BATS_ASSERT/load.bash"
     2  load "$LIB_BATS_SUPPORT/load.bash"
     3  
     4  # This test looks for a bug in the schema cloning code meaning when adding multiple connections 
     5  # for the same plugin, only 1 of the connections will work when querying - the others will give an 
     6  # FDW no schema loaded for connection error.
     7  @test "schema cloning" {
     8    # remove existing connections
     9    rm -f $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    10  
    11    # remove db, to trigger a clean installation with no connections
    12    rm -rf $STEAMPIPE_INSTALL_DIR/db
    13  
    14    # run steampipe(installs db)
    15    steampipe query "select 1"
    16  
    17    # add connections(more than 1) to trigger schema cloning
    18    cp $SRC_DATA_DIR/two_chaos.spc $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    19  
    20    # query both connections(both should work)
    21    run steampipe query "select * from chaos.chaos_all_column_types"
    22    assert_success
    23    run steampipe query "select * from chaos2.chaos_all_column_types"
    24    assert_success
    25  }
    26  
    27  # This test looks for a bug in the schema cloning code where the schema clone function 
    28  # used to fail if table had an LTREE column
    29  @test "schema cloning - function fails if table has an LTREE column" {
    30    # remove existing connections
    31    rm -f $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    32  
    33    # remove db, to trigger a clean installation with no connections
    34    rm -rf $STEAMPIPE_INSTALL_DIR/db
    35  
    36    # run steampipe(installs db)
    37    steampipe query "select 1"
    38  
    39    # add connections(more than 1) to trigger schema cloning
    40    cp $SRC_DATA_DIR/two_chaos.spc $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    41  
    42    run steampipe query "select ltree_column from chaos2.chaos_all_column_types"
    43    assert_success
    44  }
    45  
    46  @test "schema cloning - quoting issue" {
    47    # remove existing connections
    48    rm -f $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    49  
    50    # remove db, to trigger a clean installation with no connections
    51    rm -rf $STEAMPIPE_INSTALL_DIR/db
    52  
    53    # run steampipe(installs db)
    54    steampipe query "select 1"
    55  
    56    # add connections(more than 1 - with names containing both uppercase and lowercase chars) 
    57    # to trigger schema cloning
    58    cp $SRC_DATA_DIR/chaos_case_sensitivity.spc $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    59  
    60    steampipe query "select 1"
    61  
    62    # query all connections(all connections should be ready and should work)
    63    run steampipe query 'select * from "M_t0".chaos_all_column_types'
    64    assert_success
    65    run steampipe query 'select * from "M_t1".chaos_all_column_types'
    66    assert_success
    67    run steampipe query 'select * from "M_t2".chaos_all_column_types'
    68    assert_success
    69    run steampipe query 'select * from "M_t3".chaos_all_column_types'
    70    assert_success
    71    run steampipe query 'select * from "M_t4".chaos_all_column_types'
    72    assert_success
    73    run steampipe query 'select * from "M_t5".chaos_all_column_types'
    74    assert_success
    75  }
    76  
    77  function teardown_file() {
    78    # list running processes
    79    ps -ef | grep steampipe
    80  
    81    # check if any processes are running
    82    num=$(ps aux | grep steampipe | grep -v bats | grep -v grep | grep -v tests/acceptance | wc -l | tr -d ' ')
    83    assert_equal $num 0
    84  }
    85  
    86  function teardown() {
    87    # remove the files created as part of these tests 
    88    rm -f $STEAMPIPE_INSTALL_DIR/config/chaos.spc
    89  }