Skip to content

Commit

Permalink
Merge pull request #2871 from jsternberg/bake-empty-variable-tests
Browse files Browse the repository at this point in the history
bake: test empty override
  • Loading branch information
tonistiigi authored Dec 18, 2024
2 parents 3771fe2 + 1e992b2 commit 0dfc4a1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions bake/bake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,24 +2019,43 @@ target "app" {
})
}

// https://github.com/docker/buildx/pull/428
// https://github.com/docker/buildx/issues/2822
func TestEmptyAttribute(t *testing.T) {
func TestVariableEmpty(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
variable "FOO" {
default = ""
}
target "app" {
output = [""]
output = [FOO]
}
`),
}

ctx := context.TODO()

m, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil, &EntitlementConf{})
require.Equal(t, 1, len(m))
require.NoError(t, err)
require.Contains(t, m, "app")
require.Len(t, m["app"].Outputs, 0)
}

// https://github.com/docker/buildx/issues/2858
func TestOverrideEmpty(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
target "app" {
output = ["./bin"]
}
`),
}

ctx := context.TODO()
m, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, []string{"app.output="}, nil, &EntitlementConf{})
require.NoError(t, err)
require.Contains(t, m, "app")
require.Len(t, m["app"].Outputs, 0)
}

func stringify[V fmt.Stringer](values []V) []string {
Expand Down

0 comments on commit 0dfc4a1

Please sign in to comment.