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

     1  load "$LIB_BATS_ASSERT/load.bash"
     2  load "$LIB_BATS_SUPPORT/load.bash"
     3  
     4  ### workspace mod tests ###
     5  # The following set of tests use a workspace mod(the mod is committed) with no dependencies and the
     6  # variable has a default. The variable is then set from the command line, an auto spvars file, an explicit spvars 
     7  # file, or an ENV var. The tests below check that the variable is resolved correctly in each of these cases.
     8  
     9  @test "test variable resolution in workspace mod set from command line(--var)" {
    10    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_command_line
    11  
    12    run steampipe query query.version --output csv --var version="v5.0.0"
    13    # check the output - query should use the value of variable set from the command line
    14    # --var flag ("v5.0.0") which will give the output:
    15  # +--------+----------+--------+
    16  # | reason | resource | status |
    17  # +--------+----------+--------+
    18  # | v5.0.0 | v5.0.0   | ok     |
    19  # +--------+----------+--------+
    20    assert_output 'reason,resource,status
    21  v5.0.0,v5.0.0,ok'
    22  }
    23  
    24  @test "test variable resolution in workspace mod set from steampipe.spvars file" {
    25    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_steampipe.spvars
    26  
    27    run steampipe query query.version --output csv
    28    # check the output - query should use the value of variable set from the steampipe spvars
    29    # file ("v7.0.0") which will give the output:
    30  # +--------+----------+--------+
    31  # | reason | resource | status |
    32  # +--------+----------+--------+
    33  # | v7.0.0 | v7.0.0   | ok     |
    34  # +--------+----------+--------+
    35    assert_output 'reason,resource,status
    36  v7.0.0,v7.0.0,ok'
    37  }
    38  
    39  @test "test variable resolution in workspace mod set from *.auto.spvars file" {
    40    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_auto.spvars
    41  
    42    run steampipe query query.version --output csv
    43    # check the output - query should use the value of variable set from the auto spvars
    44    # file ("v7.0.0") which will give the output:
    45  # +--------+----------+--------+
    46  # | reason | resource | status |
    47  # +--------+----------+--------+
    48  # | v7.0.0 | v7.0.0   | ok     |
    49  # +--------+----------+--------+
    50    assert_output 'reason,resource,status
    51  v7.0.0,v7.0.0,ok'
    52  }
    53  
    54  @test "test variable resolution in workspace mod set from explicit spvars file" {
    55    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_explicit_spvars
    56  
    57    run steampipe query query.version --output csv --var-file='deps.spvars'
    58    # check the output - query should use the value of variable set from the explicit spvars
    59    # file ("v8.0.0") which will give the output:
    60  # +--------+----------+--------+
    61  # | reason | resource | status |
    62  # +--------+----------+--------+
    63  # | v8.0.0 | v8.0.0   | ok     |
    64  # +--------+----------+--------+
    65    assert_output 'reason,resource,status
    66  v8.0.0,v8.0.0,ok'
    67  }
    68  
    69  @test "test variable resolution in workspace mod set from ENV" {
    70    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_command_line
    71    export SP_VAR_version=v9.0.0
    72    run steampipe query query.version --output csv
    73    # check the output - query should use the value of variable set from the ENV var
    74    # SP_VAR_version ("v9.0.0") which will give the output:
    75  # +--------+----------+--------+
    76  # | reason | resource | status |
    77  # +--------+----------+--------+
    78  # | v9.0.0 | v9.0.0   | ok     |
    79  # +--------+----------+--------+
    80    assert_output 'reason,resource,status
    81  v9.0.0,v9.0.0,ok'
    82  }
    83  
    84  ### dependency mod tests ###
    85  # The following set of tests use a dependency mod(the mod is committed) that has a variable dependency but the
    86  # variable does not have a default. This means that the variable must be set from the command
    87  # line, an auto spvars file, an explicit spvars file, or an ENV var. The tests below check that
    88  # the variable is resolved correctly in each of these cases.
    89  
    90  @test "test variable resolution in dependency mod set from command line(--var)" {
    91    cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_command_line
    92  
    93    run steampipe query dependency_vars_1.query.version --output csv --var dependency_vars_1.version="v5.0.0"
    94    # check the output - query should use the value of variable set from the command line
    95    # --var flag ("v5.0.0") which will give the output:
    96  # +--------+----------+--------+
    97  # | reason | resource | status |
    98  # +--------+----------+--------+
    99  # | v5.0.0 | v5.0.0   | ok     |
   100  # +--------+----------+--------+
   101    assert_output 'reason,resource,status
   102  v5.0.0,v5.0.0,ok'
   103  }
   104  
   105  @test "test variable resolution in dependency mod set from steampipe.spvars file" {
   106    cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_steampipe.spvars
   107  
   108    run steampipe query dependency_vars_1.query.version --output csv
   109    # check the output - query should use the value of variable set from the steampipe.spvars
   110    # file ("v7.0.0") which will give the output:
   111  # +--------+----------+--------+
   112  # | reason | resource | status |
   113  # +--------+----------+--------+
   114  # | v7.0.0 | v7.0.0   | ok     |
   115  # +--------+----------+--------+
   116    assert_output 'reason,resource,status
   117  v7.0.0,v7.0.0,ok'
   118  }
   119  
   120  @test "test variable resolution in dependency mod set from *.auto.spvars spvars file" {
   121    cd $FILE_PATH/test_data/mods/test_dependency_mod_var_set_from_auto.spvars
   122  
   123    run steampipe query dependency_vars_1.query.version --output csv
   124    # check the output - query should use the value of variable set from the *.auto.spvars 
   125    # file ("v8.0.0") which will give the output:
   126  # +--------+----------+--------+
   127  # | reason | resource | status |
   128  # +--------+----------+--------+
   129  # | v8.0.0 | v8.0.0   | ok     |
   130  # +--------+----------+--------+
   131    assert_output 'reason,resource,status
   132  v8.0.0,v8.0.0,ok'
   133  }
   134  
   135  ### precedence tests ###
   136  
   137  @test "test variable resolution precedence in workspace mod set from steampipe.spvars and *.auto.spvars file" {
   138    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_precedence_set_from_both_spvars
   139  
   140    run steampipe query query.version --output csv
   141    # check the output - query should use the value of variable set from the  *.auto.spvars("v8.0.0") file over 
   142    # steampipe.spvars("v7.0.0") which will give the output:
   143  # +--------+----------+--------+
   144  # | reason | resource | status |
   145  # +--------+----------+--------+
   146  # | v8.0.0 | v8.0.0   | ok     |
   147  # +--------+----------+--------+
   148    assert_output 'reason,resource,status
   149  v8.0.0,v8.0.0,ok'
   150  }
   151  
   152  @test "test variable resolution precedence in workspace mod set from steampipe.spvars and ENV" {
   153    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_steampipe.spvars
   154    export SP_VAR_version=v9.0.0
   155    run steampipe query query.version --output csv
   156    # check the output - query should use the value of variable set from the steampipe.spvars("v7.0.0") file over 
   157    # ENV("v9.0.0") which will give the output:
   158  # +--------+----------+--------+
   159  # | reason | resource | status |
   160  # +--------+----------+--------+
   161  # | v7.0.0 | v7.0.0   | ok     |
   162  # +--------+----------+--------+
   163    assert_output 'reason,resource,status
   164  v7.0.0,v7.0.0,ok'
   165  }
   166  
   167  @test "test variable resolution precedence in workspace mod set from command line(--var) and steampipe.spvars file and *.auto.spvars file" {
   168    cd $FILE_PATH/test_data/mods/test_workspace_mod_var_precedence_set_from_both_spvars
   169  
   170    run steampipe query query.version --output csv --var version="v5.0.0"
   171    # check the output - query should use the value of variable set from the command line --var flag("v5.0.0") over 
   172    # steampipe.spvars("v7.0.0") and *.auto.spvars file("v8.0.0") which will give the output:
   173  # +--------+----------+--------+
   174  # | reason | resource | status |
   175  # +--------+----------+--------+
   176  # | v5.0.0 | v5.0.0   | ok     |
   177  # +--------+----------+--------+
   178    assert_output 'reason,resource,status
   179  v5.0.0,v5.0.0,ok'
   180  }
   181