Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable resolution acceptance tests #4093

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release_cli_and_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ jobs:
- "dynamic_aggregators"
- "cache"
- "mod_install"
- "mod_vars"
- "mod"
- "mod_require"
- "check"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
- "dynamic_aggregators"
- "cache"
- "mod_install"
- "mod_vars"
- "mod"
- "mod_require"
- "check"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependency_vars_1.version = "v8.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod "test_vars_dependency_mod" {
title = "test_vars_dependency_mod"
require {
mod "github.com/pskrbasu/steampipe-mod-dependency-vars-1" {
version = "*"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependency_vars_1.version = "v7.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "v8.0.0"
16 changes: 16 additions & 0 deletions tests/acceptance/test_data/mods/test_vars_workspace_mod/mod.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mod "test_vars_workspace_mod" {
title = "test_vars_workspace_mod"
}

query "version" {
sql = "select $1::text as reason, $1::text as resource, 'ok' as status"
param "p1"{
description = "p1"
default = var.version
}
}

variable "version"{
type = string
default = "v2.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "v7.0.0"
142 changes: 142 additions & 0 deletions tests/acceptance/test_files/mod_vars.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
load "$LIB_BATS_ASSERT/load.bash"
load "$LIB_BATS_SUPPORT/load.bash"

### workspace mod tests ###

@test "test variable resolution in workspace mod set from command line(--var)" {
cd $FILE_PATH/test_data/mods/test_vars_workspace_mod

run steampipe query query.version --output csv --var version="v5.0.0"
# check the output - query should use the value of variable set from the command line
# --var flag ("v5.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v5.0.0 | v5.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v5.0.0,v5.0.0,ok'
}

@test "test variable resolution in workspace mod set from auto spvars file" {
cd $FILE_PATH/test_data/mods/test_vars_workspace_mod

run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the auto spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}

@test "test variable resolution in workspace mod set from explicit spvars file" {
cd $FILE_PATH/test_data/mods/test_vars_workspace_mod

run steampipe query query.version --output csv --var-file='deps.spvars'
# check the output - query should use the value of variable set from the explicit spvars
# file ("v8.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v8.0.0 | v8.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v8.0.0,v8.0.0,ok'
}

@test "test variable resolution in workspace mod set from ENV" {
cd $FILE_PATH/test_data/mods/test_vars_workspace_mod
export SP_VAR_version=v9.0.0
run steampipe query query.version --output csv
# check the output - query should use the value of variable set from the ENV var
# SP_VAR_top ("v9.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v9.0.0 | v9.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v9.0.0,v9.0.0,ok'
}

### dependency mod tests ###

@test "test variable resolution in dependency mod set from command line(--var)" {
cd $FILE_PATH/test_data/mods/test_vars_dependency_mod
steampipe mod install

run steampipe query dependency_vars_1.query.version --output csv --var dependency_vars_1.version="v5.0.0"
# check the output - query should use the value of variable set from the command line
# --var flag ("v5.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v5.0.0 | v5.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v5.0.0,v5.0.0,ok'

rm -rf .steampipe/
rm -rf .mod.cache.json
}

@test "test variable resolution in dependency mod set from auto spvars file" {
cd $FILE_PATH/test_data/mods/test_vars_dependency_mod
steampipe mod install

run steampipe query dependency_vars_1.query.version --output csv
# check the output - query should use the value of variable set from the auto spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'

rm -rf .steampipe/
rm -rf .mod.cache.json
}

@test "test variable resolution in dependency mod set from explicit spvars file" {
cd $FILE_PATH/test_data/mods/test_vars_dependency_mod
steampipe mod install

run steampipe query dependency_vars_1.query.version --output csv --var-file='deps.spvars'
# check the output - query should use the value of variable set from the explicit spvars
# file ("v8.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v8.0.0 | v8.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v8.0.0,v8.0.0,ok'

rm -rf .steampipe/
rm -rf .mod.cache.json
}

@test "test variable resolution in dependency mod set from ENV" {
cd $FILE_PATH/test_data/mods/test_vars_dependency_mod
steampipe mod install
export SP_VAR_version=v9.0.0
run steampipe query dependency_vars_1.query.version --output csv
# check the output - query should use the value of variable set from the ENV var
# SP_VAR_top ("v9.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v9.0.0 | v9.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v9.0.0,v9.0.0,ok'

rm -rf .steampipe/
rm -rf .mod.cache.json
}
Loading