update and enable config precedence tests

This commit is contained in:
Puskar Basu
2024-10-15 15:18:09 +05:30
parent abf5796ab0
commit ad1259f888
11 changed files with 40 additions and 116 deletions

4
go.mod
View File

@@ -44,8 +44,8 @@ require (
github.com/spf13/viper v1.19.0
github.com/thediveo/enumflag/v2 v2.0.5
github.com/turbot/go-kit v0.10.0-rc.0
// v1.6.x ec08115 (Update SteampipeWorkspaceProfile to warn for removed args in workspace instead or erroring...)
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241008150745-ec081153b1b3
// v1.6.x 11f7dce (Update SteampipeWorkspaceProfile to warn for removed args in workspace instead or erroring...)
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241011155452-11f7dcedff30
github.com/turbot/steampipe-cloud-sdk-go v0.6.0
// branch: workspace_profiles
github.com/turbot/steampipe-plugin-sdk/v5 v5.11.0-rc.1

4
go.sum
View File

@@ -774,8 +774,8 @@ github.com/turbot/go-kit v0.10.0-rc.0 h1:kd+jp2ibbIV33Hc8SsMAN410Dl9Pz6SJ40axbKU
github.com/turbot/go-kit v0.10.0-rc.0/go.mod h1:fFQqR59I5z5JeeBLfK1PjSifn4Oprs3NiQx0CxeSJxs=
github.com/turbot/go-prompt v0.2.6-steampipe.0.0.20221028122246-eb118ec58d50 h1:zs87uA6QZsYLk4RRxDOIxt8ro/B2V6HzoMWm05Lo7ao=
github.com/turbot/go-prompt v0.2.6-steampipe.0.0.20221028122246-eb118ec58d50/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241008150745-ec081153b1b3 h1:Ws96Wk9uDEqqVSWe+lw8IfSCvbZJ/wTuvxMHlFC8FB8=
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241008150745-ec081153b1b3/go.mod h1:bBriS3DBSCvv6aJsHu5UZviRDHEMrNrfMvMsK8K5hc8=
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241011155452-11f7dcedff30 h1:OnGIXpnB08vYcjVNNsGgiLy54fKgDp1DFNLheTGdIXg=
github.com/turbot/pipe-fittings v1.6.0-beta.1.0.20241011155452-11f7dcedff30/go.mod h1:bBriS3DBSCvv6aJsHu5UZviRDHEMrNrfMvMsK8K5hc8=
github.com/turbot/pipes-sdk-go v0.9.1 h1:2yRojY2wymvJn6NQyE6A0EDFV267MNe+yDLxPVvsBwM=
github.com/turbot/pipes-sdk-go v0.9.1/go.mod h1:Mb+KhvqqEdRbz/6TSZc2QWDrMa5BN3E4Xw+gPt2TRkc=
github.com/turbot/steampipe-cloud-sdk-go v0.6.0 h1:ufAxOpKS1uq7eejuE5sfEu1+d7QAd0RBjl8Bn6+mIs8=

View File

@@ -1,10 +0,0 @@
package constants
//
// metaquery mode arguments
var ArgOutput = ArgFromMetaquery(CmdOutput)
var ArgSeparator = ArgFromMetaquery(CmdSeparator)
var ArgHeader = ArgFromMetaquery(CmdHeaders)
var ArgMultiLine = ArgFromMetaquery(CmdMulti)
var ArgAutoComplete = ArgFromMetaquery(CmdAutoComplete)

View File

@@ -1,7 +1,5 @@
package constants
import "fmt"
// Metaquery commands
const (
@@ -23,11 +21,3 @@ const (
CmdCacheTtl = ".cache_ttl" // set cache ttl
CmdAutoComplete = ".autocomplete" // enable or disable auto complete
)
// ArgFromMetaquery converts a metaquery of form '.header' into the config argument used to set the mode, i.e. 'header'
func ArgFromMetaquery(cmd string) string {
if cmd[:1] != "." {
panic(fmt.Sprintf("ArgFromMetaquery called for non-metyaquery: %s", cmd))
}
return cmd[1:]
}

View File

@@ -56,7 +56,7 @@ func init() {
constants.CmdHeaders: {
title: "headers",
handler: setHeader,
validator: booleanValidator(constants.CmdHeaders, validatorFromArgsOf(constants.CmdHeaders)),
validator: booleanValidator(constants.CmdHeaders, pconstants.ArgHeader, validatorFromArgsOf(constants.CmdHeaders)),
description: "Enable or disable column headers",
args: []metaQueryArg{
{value: pconstants.ArgOn, description: "Turn on headers in output"},
@@ -67,7 +67,7 @@ func init() {
constants.CmdMulti: {
title: "multi-line",
handler: setMultiLine,
validator: booleanValidator(constants.CmdMulti, validatorFromArgsOf(constants.CmdMulti)),
validator: booleanValidator(constants.CmdMulti, pconstants.ArgMultiLine, validatorFromArgsOf(constants.CmdMulti)),
description: "Enable or disable multiline mode",
args: []metaQueryArg{
{value: pconstants.ArgOn, description: "Turn on multiline mode"},
@@ -155,7 +155,7 @@ func init() {
constants.CmdAutoComplete: {
title: "auto-complete",
handler: setAutoComplete,
validator: booleanValidator(constants.CmdAutoComplete, validatorFromArgsOf(constants.CmdAutoComplete)),
validator: booleanValidator(constants.CmdAutoComplete, pconstants.ArgAutoComplete, validatorFromArgsOf(constants.CmdAutoComplete)),
description: "Enable or disable auto-completion",
args: []metaQueryArg{
{value: pconstants.ArgOn, description: "Turn on auto-completion"},

View File

@@ -8,7 +8,6 @@ import (
pconstants "github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/steampipe/pkg/cmdconfig"
"github.com/turbot/steampipe/pkg/constants"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
@@ -46,7 +45,7 @@ func titleSentenceCase(title string) string {
return strings.Join(titleSegments, "-")
}
func booleanValidator(metaquery string, validators ...validator) validator {
func booleanValidator(metaquery, arg string, validators ...validator) validator {
return func(args []string) ValidationResult {
// Error: argument required multi-line mode is off. You can enable it with: .multi on
// headers mode is off. You can enable it with: .headers on
@@ -57,7 +56,7 @@ func booleanValidator(metaquery string, validators ...validator) validator {
if numArgs == 0 {
// get the current status of this mode (convert metaquery name into arg name)
// NOTE - request second arg from cast even though we donl;t use it - to avoid panic
currentStatus := cmdconfig.Viper().GetBool(constants.ArgFromMetaquery(metaquery))
currentStatus := cmdconfig.Viper().GetBool(arg)
// what is the new status (the opposite)
newStatus := !currentStatus

View File

@@ -257,7 +257,7 @@ func loadConfig(ctx context.Context, configFolder string, steampipeConfig *Steam
}
// do a partial decode
content, moreDiags := body.Content(pparse.ConfigBlockSchema)
content, moreDiags := body.Content(pparse.SteampipeConfigBlockSchema)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
return perror_helpers.DiagsToErrorsAndWarnings("Failed to load config", diags)

View File

@@ -1,20 +1,16 @@
workspace "default" {
introspection = "info"
pipes_host = "latestpipe.turbot.io/"
pipes_token = "spt_012faketoken34567890_012faketoken3456789099999"
install_dir = "sp_install_dir_default"
mod_location = "sp_install_dir_default"
snapshot_location = "snaps"
workspace_database = "fk43e7"
}
workspace "sample" {
introspection = "control"
pipes_host = "testpipe.turbot.io"
pipes_token = "spt_012faketoken34567890_012faketoken3456789099999"
install_dir = "sp_install_dir_sample"
mod_location = "sp_install_dir_sample"
snapshot_location = "snap"
workspace_database = "fk43e8"
}

View File

@@ -1,12 +1,10 @@
workspace "default" {
pipes_host = "latestpipe.turbot.io/"
pipes_token = "spt_012faketoken34567890_012faketoken3456789099999"
mod_location = "sp_install_dir_default"
snapshot_location = "snaps"
workspace_database = "fk43e7"
search_path = ""
search_path_prefix = "abc"
watch = false
options "query" {
autocomplete = false
header = false
@@ -15,23 +13,15 @@ workspace "default" {
separator = "|"
timing = true
}
options "check" {
header = false
output = "json"
separator = "|"
timing = true
}
}
workspace "sample" {
pipes_host = "latestpipe.turbot.io/"
pipes_token = "spt_012faketoken34567890_012faketoken3456789099999"
mod_location = "sp_install_dir_sample"
snapshot_location = "snaps"
workspace_database = "fk43e7"
search_path = "abc"
search_path_prefix = "abc, def"
watch = false
options "query" {
autocomplete = true
header = false
@@ -40,10 +30,4 @@ workspace "sample" {
separator = ";"
timing = true
}
options "check" {
header = false
output = "csv"
separator = ";"
timing = true
}
}

View File

@@ -10,11 +10,9 @@
"args": []
},
"expected": {
"introspection": "info",
"pipes-host": "latestpipe.turbot.io/",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099999",
"install-dir": "sp_install_dir_default",
"mod-location": "sp_install_dir_default",
"snapshot-location": "snaps",
"workspace": "default",
"workspace-database": "fk43e7"
@@ -28,16 +26,13 @@
"env": [
"STEAMPIPE_WORKSPACE_PROFILES_LOCATION=workspace_profiles",
"PIPES_HOST=testpipe.turbot.io",
"STEAMPIPE_MOD_LOCATION=sp_install_dir_env",
"STEAMPIPE_INSTALL_DIR=sp_install_dir_env",
"PIPES_TOKEN=spt_012faketoken34567890_012faketoken3456789099996",
"STEAMPIPE_SNAPSHOT_LOCATION=snapshot",
"STEAMPIPE_WORKSPACE_DATABASE=fk/43e7",
"STEAMPIPE_INTROSPECTION=none"
"STEAMPIPE_WORKSPACE_DATABASE=fk/43e7"
],
"args": [
"--install-dir=sp_install_dir_default",
"--mod-location=sp_install_dir_default",
"--pipes-host=fastestpipe.turbot.io",
"--pipes-token=spt_012faketoken34567890_012faketoken3456789099990",
"--snapshot-location=snaps",
@@ -45,11 +40,9 @@
]
},
"expected": {
"introspection": "none",
"pipes-host": "fastestpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099990",
"install-dir": "sp_install_dir_default",
"mod-location": "sp_install_dir_default",
"snapshot-location": "snaps",
"workspace": "default",
"workspace-database": "fk43e9"
@@ -63,7 +56,6 @@
"env": [
"PIPES_HOST=latestpipe.turbot.io/",
"STEAMPIPE_INSTALL_DIR=sp_install_dir_env",
"STEAMPIPE_MOD_LOCATION=sp_install_dir_env",
"PIPES_TOKEN=spt_012faketoken34567890_012faketoken3456789099999",
"STEAMPIPE_SNAPSHOT_LOCATION=snaps",
"STEAMPIPE_WORKSPACE_DATABASE=fk43e7"
@@ -74,7 +66,6 @@
"pipes-host": "latestpipe.turbot.io/",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099999",
"install-dir": "sp_install_dir_env",
"mod-location": "sp_install_dir_env",
"snapshot-location": "snaps",
"workspace": "default",
"workspace-database": "fk43e7"
@@ -93,11 +84,9 @@
]
},
"expected": {
"introspection": "control",
"pipes-host": "testpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099999",
"install-dir": "sp_install_dir_sample",
"mod-location": "sp_install_dir_sample",
"snapshot-location": "snap",
"workspace": "sample",
"workspace-database": "fk43e8"
@@ -111,7 +100,6 @@
"env": [],
"args": [
"--install-dir=sp_install_dir_sample",
"--mod-location=sp_install_dir_sample",
"--pipes-host=fastestpipe.turbot.io",
"--pipes-token=spt_012faketoken34567890_012faketoken3456789099990",
"--snapshot-location=snaps",
@@ -122,7 +110,6 @@
"pipes-host": "fastestpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099990",
"install-dir": "sp_install_dir_sample",
"mod-location": "sp_install_dir_sample",
"snapshot-location": "snaps",
"workspace": "default",
"workspace-database": "fk43e9"
@@ -137,7 +124,6 @@
"STEAMPIPE_WORKSPACE_PROFILES_LOCATION=workspace_profiles",
"PIPES_HOST=fastestpipe.turbot.io/",
"STEAMPIPE_INSTALL_DIR=sp_install_dir_env",
"STEAMPIPE_MOD_LOCATION=sp_install_dir_env",
"PIPES_TOKEN=spt_012faketoken34567890_012faketoken3456789099996",
"STEAMPIPE_SNAPSHOT_LOCATION=snapshot",
"STEAMPIPE_WORKSPACE_DATABASE=ab43e6"
@@ -148,7 +134,6 @@
"pipes-host": "fastestpipe.turbot.io/",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099996",
"install-dir": "sp_install_dir_env",
"mod-location": "sp_install_dir_env",
"snapshot-location": "snapshot",
"workspace": "default",
"workspace-database": "ab43e6"
@@ -163,7 +148,6 @@
"STEAMPIPE_WORKSPACE_PROFILES_LOCATION=workspace_profiles",
"PIPES_HOST=fastestpipe.turbot.io/",
"STEAMPIPE_INSTALL_DIR=sp_install_dir_env",
"STEAMPIPE_MOD_LOCATION=sp_install_dir_env",
"PIPES_TOKEN=spt_012faketoken34567890_012faketoken3456789099996",
"STEAMPIPE_SNAPSHOT_LOCATION=snapshot",
"STEAMPIPE_WORKSPACE_DATABASE=ab43e6"
@@ -176,7 +160,6 @@
"pipes-host": "testpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099999",
"install-dir": "sp_install_dir_sample",
"mod-location": "sp_install_dir_sample",
"snapshot-location": "snap",
"workspace": "sample",
"workspace-database": "fk43e8"
@@ -191,7 +174,6 @@
"STEAMPIPE_WORKSPACE_PROFILES_LOCATION=workspace_profiles",
"PIPES_HOST=fastestpipe.turbot.io/",
"STEAMPIPE_INSTALL_DIR=sp_install_dir_env",
"STEAMPIPE_MOD_LOCATION=sp_install_dir_env",
"PIPES_TOKEN=spt_012faketoken34567890_012faketoken3456789099996",
"STEAMPIPE_SNAPSHOT_LOCATION=snapshot",
"STEAMPIPE_WORKSPACE_DATABASE=ab43e6"
@@ -204,7 +186,6 @@
"pipes-host": "testpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099999",
"install-dir": "sp_install_dir_sample",
"mod-location": "sp_install_dir_sample",
"snapshot-location": "snap",
"workspace": "sample",
"workspace-database": "fk43e8"
@@ -220,7 +201,6 @@
],
"args": [
"--install-dir=sp_install_dir_default",
"--mod-location=sp_install_dir_default",
"--pipes-host=fastestpipe.turbot.io",
"--pipes-token=spt_012faketoken34567890_012faketoken3456789099990",
"--snapshot-location=snaps",
@@ -231,7 +211,6 @@
"pipes-host": "fastestpipe.turbot.io",
"pipes-token": "spt_012faketoken34567890_012faketoken3456789099990",
"install-dir": "sp_install_dir_default",
"mod-location": "sp_install_dir_default",
"snapshot-location": "snaps",
"workspace": "default",
"workspace-database": "fk43e9"
@@ -248,18 +227,16 @@
"args": []
},
"expected": {
"query.autocomplete": false,
"query.auto-complete": false,
"query.header": false,
"query.multi": true,
"query.multi-line": true,
"query.output": "json",
"query-timeout": 0,
"search-path": "[ ]",
"search-path-prefix": "[ abc ]",
"query.separator": "|",
"query.timing": true,
"telemetry": "info",
"update-check": "false",
"watch": false
"telemetry": "info"
}
},
{
@@ -296,17 +273,16 @@
]
},
"expected": {
"query.autocomplete": true,
"query.auto-complete": true,
"query.header": false,
"query.multi": true,
"query.multi-line": true,
"query.output": "csv",
"search-path": "[ abc ]",
"search-path-prefix": "[ abc, def ]",
"query.separator": ";",
"query.timing": true,
"telemetry": "none",
"update-check": "true",
"watch": false
"update-check": "true"
}
},
{
@@ -322,12 +298,11 @@
"--search-path=abc",
"--search-path-prefix=def",
"--separator=+",
"--timing=true",
"--watch=true"
"--timing=true"
]
},
"expected": {
"query.autocomplete": false,
"query.auto-complete": false,
"header": true,
"output": "table",
"query-timeout": 190,
@@ -335,8 +310,7 @@
"search-path-prefix": "[ def ]",
"separator": "+",
"telemetry": "none",
"update-check": "true",
"watch": true
"update-check": "true"
}
},
{
@@ -354,18 +328,17 @@
"args": []
},
"expected": {
"query.autocomplete": false,
"query.auto-complete": false,
"query.header": false,
"max-parallel": 10,
"query.multi": true,
"query.multi-line": true,
"query.output": "json",
"query-timeout": 100,
"search-path": "[ ]",
"search-path-prefix": "[ abc ]",
"query.separator": "|",
"telemetry": "none",
"update-check": true,
"watch": false
"update-check": true
}
},
{
@@ -385,18 +358,17 @@
]
},
"expected": {
"autocomplete": true,
"auto-complete": true,
"header": false,
"max-parallel": 10,
"multi": true,
"multi-line": true,
"output": "csv",
"query-timeout": 100,
"search-path": "[ abc ]",
"search-path-prefix": "[ abc, def ]",
"separator": ";",
"telemetry": "none",
"update-check": true,
"watch": false
"update-check": true
}
},
{
@@ -415,18 +387,17 @@
"args": []
},
"expected": {
"autocomplete": true,
"auto-complete": true,
"header": false,
"max-parallel": 10,
"multi": true,
"multi-line": true,
"output": "csv",
"query-timeout": 100,
"search-path": "[ abc ]",
"search-path-prefix": "[ abc, def ]",
"separator": ";",
"telemetry": "none",
"update-check": true,
"watch": false
"update-check": true
}
},
{
@@ -449,23 +420,21 @@
"--search-path=xyz",
"--search-path-prefix=pqr",
"--separator=+",
"--timing=true",
"--watch=true"
"--timing=true"
]
},
"expected": {
"autocomplete": true,
"auto-complete": true,
"header": true,
"max-parallel": 10,
"multi": true,
"multi-line": true,
"output": "table",
"query-timeout": 190,
"search-path": "[ xyz ]",
"search-path-prefix": "[ pqr ]",
"separator": "+",
"telemetry": "none",
"update-check": true,
"watch": true
"update-check": true
}
},
{
@@ -487,23 +456,21 @@
"--search-path=xyz",
"--search-path-prefix=pqr",
"--separator=+",
"--timing=true",
"--watch=true"
"--timing=true"
]
},
"expected": {
"autocomplete": true,
"auto-complete": true,
"header": true,
"max-parallel": 10,
"multi": true,
"multi-line": true,
"output": "table",
"query-timeout": 190,
"search-path": "[ xyz ]",
"search-path-prefix": "[ pqr ]",
"separator": "+",
"telemetry": "none",
"update-check": true,
"watch": true
"update-check": true
}
},
{
@@ -520,18 +487,17 @@
"args": []
},
"expected": {
"autocomplete": true,
"auto-complete": true,
"header": false,
"max-parallel": 10,
"multi": true,
"multi-line": true,
"output": "csv",
"query-timeout": 100,
"search-path": "[ abc ]",
"search-path-prefix": "[ abc, def ]",
"separator": ";",
"telemetry": "none",
"update-check": true,
"watch": false
"update-check": true
}
}
]

View File

@@ -4,7 +4,6 @@ load "$LIB_BATS_SUPPORT/load.bash"
## workspace tests
@test "generic config precedence test" {
skip 'TODO - update and enable this test'
cp $FILE_PATH/test_data/source_files/config_tests/default.spc $STEAMPIPE_INSTALL_DIR/config/default.spc
# setup test folder and read the test-cases file