From 44c840b31d1712d0f1031e9a532dfc47fae4148b Mon Sep 17 00:00:00 2001 From: Patrick Van Stee Date: Thu, 7 May 2020 23:51:06 -0400 Subject: [PATCH] Add test of parsing a json bake config Signed-off-by: Patrick Van Stee --- bake/hcl_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/bake/hcl_test.go b/bake/hcl_test.go index 7ea047a0..6cb53ea3 100644 --- a/bake/hcl_test.go +++ b/bake/hcl_test.go @@ -68,6 +68,66 @@ func TestParseHCL(t *testing.T) { require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args) }) + t.Run("BasicInJSON", func(t *testing.T) { + dt := []byte(` + { + "group": { + "default": { + "targets": ["db", "webapp"] + } + }, + "target": { + "db": { + "context": "./db", + "tags": ["docker.io/tonistiigi/db"] + }, + "webapp": { + "context": "./dir", + "dockerfile": "Dockerfile-alternate", + "args": { + "buildno": "123" + } + }, + "cross": { + "platforms": [ + "linux/amd64", + "linux/arm64" + ] + }, + "webapp-plus": { + "inherits": ["webapp", "cross"], + "args": { + "IAMCROSS": "true" + } + } + } + } + `) + + c, err := ParseHCL(dt, "docker-bake.json") + require.NoError(t, err) + + require.Equal(t, 1, len(c.Groups)) + require.Equal(t, "default", c.Groups[0].Name) + require.Equal(t, []string{"db", "webapp"}, c.Groups[0].Targets) + + require.Equal(t, 4, len(c.Targets)) + require.Equal(t, c.Targets[0].Name, "db") + require.Equal(t, "./db", *c.Targets[0].Context) + + require.Equal(t, c.Targets[1].Name, "webapp") + require.Equal(t, 1, len(c.Targets[1].Args)) + require.Equal(t, "123", c.Targets[1].Args["buildno"]) + + require.Equal(t, c.Targets[2].Name, "cross") + require.Equal(t, 2, len(c.Targets[2].Platforms)) + require.Equal(t, []string{"linux/amd64", "linux/arm64"}, c.Targets[2].Platforms) + + require.Equal(t, c.Targets[3].Name, "webapp-plus") + require.Equal(t, 1, len(c.Targets[3].Args)) + require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args) + }) + t.Run("WithFunctions", func(t *testing.T) { dt := []byte(` group "default" {