From 56d55a4137e93ad225a0a0a1f156674b2051ec84 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 23 Aug 2023 11:15:39 +0200 Subject: [PATCH] test: fix non-deterministic compose context path Signed-off-by: CrazyMax --- bake/bake_test.go | 15 ++++++++++++--- bake/compose_test.go | 13 ++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bake/bake_test.go b/bake/bake_test.go index 0a116c4763f..32a21bc2732 100644 --- a/bake/bake_test.go +++ b/bake/bake_test.go @@ -295,6 +295,9 @@ services: ctx := context.TODO() + cwd, err := os.Getwd() + require.NoError(t, err) + m, g, err := ReadTargets(ctx, []File{fp, fp2, fp3}, []string{"default"}, nil, nil) require.NoError(t, err) @@ -303,7 +306,7 @@ services: require.True(t, ok) require.Equal(t, "Dockerfile.webapp", *m["webapp"].Dockerfile) - require.Equal(t, "/src/bake", *m["webapp"].Context) + require.Equal(t, cwd, *m["webapp"].Context) require.Equal(t, ptrstr("1"), m["webapp"].Args["buildno"]) require.Equal(t, ptrstr("12"), m["webapp"].Args["buildno2"]) @@ -342,6 +345,9 @@ services: ctx := context.TODO() + cwd, err := os.Getwd() + require.NoError(t, err) + m, _, err := ReadTargets(ctx, []File{fp}, []string{"web.app"}, nil, nil) require.NoError(t, err) require.Equal(t, 1, len(m)) @@ -364,7 +370,7 @@ services: _, ok = m["web_app"] require.True(t, ok) require.Equal(t, "Dockerfile.webapp", *m["web_app"].Dockerfile) - require.Equal(t, "/src/bake", *m["web_app"].Context) + require.Equal(t, cwd, *m["web_app"].Context) require.Equal(t, ptrstr("1"), m["web_app"].Args["buildno"]) require.Equal(t, ptrstr("12"), m["web_app"].Args["buildno2"]) @@ -543,6 +549,9 @@ services: ctx := context.TODO() + cwd, err := os.Getwd() + require.NoError(t, err) + m, _, err := ReadTargets(ctx, []File{fp, fp2}, []string{"app1", "app2"}, nil, nil) require.NoError(t, err) @@ -555,7 +564,7 @@ services: require.Equal(t, "Dockerfile", *m["app1"].Dockerfile) require.Equal(t, ".", *m["app1"].Context) require.Equal(t, "Dockerfile", *m["app2"].Dockerfile) - require.Equal(t, "/src/bake", *m["app2"].Context) + require.Equal(t, cwd, *m["app2"].Context) } func TestReadContextFromTargetChain(t *testing.T) { diff --git a/bake/compose_test.go b/bake/compose_test.go index 918f884f928..b18db6bb455 100644 --- a/bake/compose_test.go +++ b/bake/compose_test.go @@ -22,7 +22,7 @@ services: build: context: ./dir additional_contexts: - foo: /bar + foo: ./bar dockerfile: Dockerfile-alternate network: none @@ -49,6 +49,9 @@ secrets: file: /root/.aws/credentials `) + cwd, err := os.Getwd() + require.NoError(t, err) + c, err := ParseCompose([]compose.ConfigFile{{Content: dt}}, nil) require.NoError(t, err) @@ -62,12 +65,12 @@ secrets: return c.Targets[i].Name < c.Targets[j].Name }) require.Equal(t, "db", c.Targets[0].Name) - require.Equal(t, "/src/bake/db", *c.Targets[0].Context) + require.Equal(t, filepath.Join(cwd, "db"), *c.Targets[0].Context) require.Equal(t, []string{"docker.io/tonistiigi/db"}, c.Targets[0].Tags) require.Equal(t, "webapp", c.Targets[1].Name) - require.Equal(t, "/src/bake/dir", *c.Targets[1].Context) - require.Equal(t, map[string]string{"foo": "/bar"}, c.Targets[1].Contexts) + require.Equal(t, filepath.Join(cwd, "dir"), *c.Targets[1].Context) + require.Equal(t, map[string]string{"foo": filepath.Join(cwd, "bar")}, c.Targets[1].Contexts) require.Equal(t, "Dockerfile-alternate", *c.Targets[1].Dockerfile) require.Equal(t, 1, len(c.Targets[1].Args)) require.Equal(t, ptrstr("123"), c.Targets[1].Args["buildno"]) @@ -80,7 +83,7 @@ secrets: }, c.Targets[1].Secrets) require.Equal(t, "webapp2", c.Targets[2].Name) - require.Equal(t, "/src/bake/dir", *c.Targets[2].Context) + require.Equal(t, filepath.Join(cwd, "dir"), *c.Targets[2].Context) require.Equal(t, "FROM alpine\n", *c.Targets[2].DockerfileInline) }