From b01693f63ee420586b004683f9ae770dfaee5c8d Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 4 Aug 2023 17:24:30 +0200 Subject: [PATCH] bake: test compose include Signed-off-by: CrazyMax --- bake/compose_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bake/compose_test.go b/bake/compose_test.go index f20a9f217cc..918f884f928 100644 --- a/bake/compose_test.go +++ b/bake/compose_test.go @@ -674,6 +674,48 @@ services: require.NoError(t, err) } +func TestInclude(t *testing.T) { + tmpdir := t.TempDir() + + err := os.WriteFile(filepath.Join(tmpdir, "compose-foo.yml"), []byte(` +services: + foo: + build: + context: . + target: buildfoo + ports: + - 3306:3306 +`), 0644) + require.NoError(t, err) + + var dt = []byte(` +include: + - compose-foo.yml + +services: + bar: + build: + context: . + target: buildbar +`) + + chdir(t, tmpdir) + c, err := ParseComposeFiles([]File{{ + Name: "compose.yml", + Data: dt, + }}) + require.NoError(t, err) + + require.Equal(t, 2, len(c.Targets)) + sort.Slice(c.Targets, func(i, j int) bool { + return c.Targets[i].Name < c.Targets[j].Name + }) + require.Equal(t, "bar", c.Targets[0].Name) + require.Equal(t, "buildbar", *c.Targets[0].Target) + require.Equal(t, "foo", c.Targets[1].Name) + require.Equal(t, "buildfoo", *c.Targets[1].Target) +} + // chdir changes the current working directory to the named directory, // and then restore the original working directory at the end of the test. func chdir(t *testing.T, dir string) {