Merge pull request #1722 from jedevc/bake-matrix-check-map-type

bake: fix map type checking to detect matrix property set to list
pull/1723/head
Justin Chadwell 2 years ago committed by GitHub
commit 1e149bb84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -820,7 +820,7 @@ func (t *Target) GetEvalContexts(ectx *hcl.EvalContext, block *hcl.Block, loadDe
return nil, err
}
if !value.CanIterateElements() {
if !value.Type().IsMapType() && !value.Type().IsObjectType() {
return nil, errors.Errorf("matrix must be a map")
}
matrix := value.AsValueMap()

@ -1051,6 +1051,14 @@ func TestHCLMatrixBadTypes(t *testing.T) {
_, err := ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(`
target "default" {
matrix = ["test"]
}
`)
_, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(`
target "default" {
matrix = {
@ -1061,6 +1069,16 @@ func TestHCLMatrixBadTypes(t *testing.T) {
_, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(`
target "default" {
matrix = {
1 = 2
}
}
`)
_, err = ParseFile(dt, "docker-bake.hcl")
require.Error(t, err)
dt = []byte(`
target "default" {
matrix = {

Loading…
Cancel
Save