fix: More acceptance tests

This commit is contained in:
Ilya Kuznetsov 2025-01-17 18:32:38 +01:00
parent d0db1d73f9
commit 2c9adcb1ed
No known key found for this signature in database
GPG Key ID: 91F3DDCF5D21CDDF
19 changed files with 217 additions and 20 deletions

View File

@ -1,4 +1,4 @@
Error: no value assigned to required variable a. Assignment can be done through the "--var" flag or by setting the BUNDLE_VAR_a environment variable
Error: no value assigned to required variable a. Assignment can be done through the "--var" or "--var-file" flag or by setting the BUNDLE_VAR_a environment variable
Name: empty${var.a}
Target: default

View File

@ -9,7 +9,7 @@
"prod-a env-var-b"
>>> errcode $CLI bundle validate -t env-missing-a-required-variable-assignment
Error: no value assigned to required variable b. Assignment can be done through the "--var" flag or by setting the BUNDLE_VAR_b environment variable
Error: no value assigned to required variable b. Assignment can be done through the "--var" or "--var-file" flag or by setting the BUNDLE_VAR_b environment variable
Name: test bundle
Target: env-missing-a-required-variable-assignment

View File

@ -1,8 +0,0 @@
{
"job_cluster_key": "mlops_stacks-cluster",
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 2
}
}
"mlops_stacks-cluster"

View File

@ -1,5 +0,0 @@
# variable file
$CLI bundle validate -o json --var-file=vars.json | jq .resources.jobs.job1.job_clusters[0]
# variable flag
$CLI bundle validate -o json --var="cluster_key=mlops_stacks-cluster" | jq .resources.jobs.job1.job_clusters[0].job_cluster_key

View File

@ -3,7 +3,7 @@
"abc def"
>>> errcode $CLI bundle validate
Error: no value assigned to required variable b. Assignment can be done through the "--var" flag or by setting the BUNDLE_VAR_b environment variable
Error: no value assigned to required variable b. Assignment can be done through the "--var" or "--var-file" flag or by setting the BUNDLE_VAR_b environment variable
Name: ${var.a} ${var.b}
Target: default

View File

@ -0,0 +1,32 @@
bundle:
name: TestResolveVariablesFromFile
variables:
cluster:
type: "complex"
cluster_key:
cluster_workers:
resources:
jobs:
job1:
job_clusters:
- job_cluster_key: ${var.cluster_key}
new_cluster:
node_type_id: "${var.cluster.node_type_id}"
num_workers: ${var.cluster_workers}
targets:
with-defaults:
default: true
variables:
cluster_workers:
default: 1
cluster:
type: "complex"
default:
node_type_id: "default"
cluster_key:
default: "default"
without-defaults:

View File

@ -0,0 +1,126 @@
>>> $CLI bundle validate -o json --var-file=var_files/normal.json
{
"job_cluster_key": "mlops_stacks-cluster",
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 2
}
}
>>> $CLI bundle validate -o json --var=cluster_key=mlops_stacks-cluster
{
"job_cluster_key": "mlops_stacks-cluster",
"new_cluster": {
"node_type_id": "default",
"num_workers": 1
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/normal.json --var=cluster_key=mlops_stacks-cluster
Error: cannot specify both --var and --var-file flags
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/not_found.json
Error: failed to read variables file: open var_files/not_found.json: no such file or directory
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/invalid_json.json
Error: failed to parse variables file: error decoding JSON at :0:0: invalid character 'o' in literal false (expecting 'a')
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/wrong_file_structure.json
Error: failed to parse variables file: var_files/wrong_file_structure.json:1:1: expected a map, found a sequence
in var_files/wrong_file_structure.json:1:1
Variables file must be a JSON object with the following format:
{"var1": "value1", "var2": "value2"}
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/undeclared.json
Error: variable undeclared_var has not been defined
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/complex_to_string.json
Error: expected a map to index "variables.cluster.value.node_type_id", found string
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --var-file=var_files/string_to_complex.json
Error: failed to assign map[node_type_id:Standard_DS3_v2] to cluster_key: variable type is not complex
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}
>>> errcode $CLI bundle validate -o json --target without-defaults --var-file=var_files/empty.json
Error: no value assigned to required variable cluster_workers. Assignment can be done through the "--var" or "--var-file" flag or by setting the BUNDLE_VAR_cluster_workers environment variable
Exit code: 1
{
"job_cluster_key": "${var.cluster_key}",
"new_cluster": {
"node_type_id": "${var.cluster.node_type_id}",
"num_workers": "${var.cluster_workers}"
}
}

View File

@ -0,0 +1,31 @@
cluster_expr=".resources.jobs.job1.job_clusters[0]"
# variable file
trace $CLI bundle validate -o json --var-file=var_files/normal.json | jq $cluster_expr
# variable flag
trace $CLI bundle validate -o json --var="cluster_key=mlops_stacks-cluster" | jq $cluster_expr
# both variable file and flag
trace errcode $CLI bundle validate -o json --var-file=var_files/normal.json --var="cluster_key=mlops_stacks-cluster" | jq $cluster_expr
# file not found
trace errcode $CLI bundle validate -o json --var-file=var_files/not_found.json | jq $cluster_expr
# file cannot be parsed
trace errcode $CLI bundle validate -o json --var-file=var_files/invalid_json.json | jq $cluster_expr
# file has wrong structure
trace errcode $CLI bundle validate -o json --var-file=var_files/wrong_file_structure.json | jq $cluster_expr
# file has variable name that is not defined
trace errcode $CLI bundle validate -o json --var-file=var_files/undeclared.json | jq $cluster_expr
# file has variable name that is complex but default is string
trace errcode $CLI bundle validate -o json --var-file=var_files/complex_to_string.json | jq $cluster_expr
# file has variable name that is string but default is complex
trace errcode $CLI bundle validate -o json --var-file=var_files/string_to_complex.json | jq $cluster_expr
# variable is required but it's not provided in the file
trace errcode $CLI bundle validate -o json --target without-defaults --var-file=var_files/empty.json | jq $cluster_expr

View File

@ -0,0 +1,3 @@
{
"cluster": "mlops_stacks-cluster"
}

View File

@ -0,0 +1,5 @@
{
"cluster_key": {
"node_type_id": "Standard_DS3_v2"
}
}

View File

@ -0,0 +1,3 @@
{
"undeclared_var": 1
}

View File

@ -1,13 +1,13 @@
bundle:
name: TestResolveVariablesFromFile
name: TestResolveVariablesFromFlag
variables:
cluster:
type: "complex"
default:
node_type_id: "unused"
node_type_id: "undefined"
cluster_key:
default: "unused"
default: "undefined"
cluster_workers:
default: 1

View File

@ -0,0 +1,3 @@
>>> $CLI bundle validate -o json --var=cluster_key=mlops_stacks-cluster
"mlops_stacks-cluster"

View File

@ -0,0 +1,2 @@
# single flag
trace $CLI bundle validate -o json --var="cluster_key=mlops_stacks-cluster" | jq .resources.jobs.job1.job_clusters[0].job_cluster_key

View File

@ -64,7 +64,7 @@ func setVariable(ctx context.Context, v dyn.Value, variable *variable.Variable,
}
// We should have had a value to set for the variable at this point.
return dyn.InvalidValue, fmt.Errorf(`no value assigned to required variable %s. Assignment can be done through the "--var" flag or by setting the %s environment variable`, name, bundleVarPrefix+name)
return dyn.InvalidValue, fmt.Errorf(`no value assigned to required variable %s. Assignment can be done through the "--var" or "--var-file" flag or by setting the %s environment variable`, name, bundleVarPrefix+name)
}
func (m *setVariables) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {