bake: check condition and error_message are set during validation#3101
bake: check condition and error_message are set during validation#3101tonistiigi merged 1 commit intodocker:masterfrom
Conversation
Signed-off-by: CrazyMax <[email protected]>
rcjsuen
left a comment
There was a problem hiding this comment.
@crazy-max Could you try to add this test? What should be the expected case if condition = false? It seems like if the user puts that in they will get This check failed, but has an invalid error message?
func TestHello(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
variable "PORT" {
default = 3000
validation {
condition = false
}
}
`),
}
_, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, nil, nil, &EntitlementConf{})
require.Error(t, err)
fmt.Println(">>>>>>")
fmt.Println(err)
fmt.Println(">>>>>>")
require.Contains(t, err.Error(), "Condition expression must return either true or false, not null")
}
Yes because the error message is required similar to how terraform does when evaluating conditions: https://github.com/hashicorp/terraform/blob/ea767aa7add3e14b7d292efead3ef23d25cd49e1/internal/terraform/eval_conditions.go#L190-L193 |
Gotcha, another Terraform thing, eh? Thanks for clarifying. 👍 |
fixes #3100
We forgot to check if
conditionanderror_messageare set and also check if result value has the expected type.cc @rcjsuen