Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 64ad96b

Browse files
committed
Add more integration tests for multiple composefile
Signed-off-by: Vincent Demeester <[email protected]>
1 parent 5a8ed55 commit 64ad96b

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

docker/convert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestParseCommand(t *testing.T) {
1919

2020
func TestParseBindsAndVolumes(t *testing.T) {
2121
ctx := &Context{}
22-
ctx.ComposeFile = "foo/docker-compose.yml"
22+
ctx.ComposeFiles = []string{"foo/docker-compose.yml"}
2323
ctx.ResourceLookup = &lookup.FileConfigLookup{}
2424

2525
abs, err := filepath.Abs(".")
@@ -34,7 +34,7 @@ func TestParseBindsAndVolumes(t *testing.T) {
3434

3535
func TestParseLabels(t *testing.T) {
3636
ctx := &Context{}
37-
ctx.ComposeFile = "foo/docker-compose.yml"
37+
ctx.ComposeFiles = []string{"foo/docker-compose.yml"}
3838
ctx.ResourceLookup = &lookup.FileConfigLookup{}
3939
bashCmd := "bash"
4040
fooLabel := "foo.label"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
yetanother:
2+
image: busybox:latest
3+
command: top
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
simple:
2+
image: busybox:latest
3+
command: top
4+
another:
5+
image: busybox:latest
6+
command: top

integration/create_test.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77

88
. "gopkg.in/check.v1"
9+
"path/filepath"
910
)
1011

1112
func (s *RunSuite) TestFields(c *C) {
@@ -172,9 +173,9 @@ func (s *RunSuite) TestFieldTypeConversions(c *C) {
172173
os.Unsetenv("LIMIT")
173174
}
174175

175-
func (s *RunSuite) TestMultipleComposeFiles(c *C) {
176-
p := s.RandomProject()
177-
cmd := exec.Command(s.command, "-f", "./assets/multiple/one.yml", "-f", "./assets/multiple/two.yml", "-p", p, "create")
176+
func (s *RunSuite) TestMultipleComposeFilesOneTwo(c *C) {
177+
p := "multiple"
178+
cmd := exec.Command(s.command, "-f", "./assets/multiple/one.yml", "-f", "./assets/multiple/two.yml", "create")
178179
cmd.Stdout = os.Stdout
179180
cmd.Stderr = os.Stderr
180181
cmd.Stdin = os.Stdin
@@ -197,27 +198,53 @@ func (s *RunSuite) TestMultipleComposeFiles(c *C) {
197198
c.Assert(container.Config.Image, Equals, "busybox")
198199
c.Assert(container.Config.Cmd, DeepEquals, []string{"echo", "two"})
199200
c.Assert(container.Config.Env, DeepEquals, []string{"KEY1=VAL1", "KEY2=VAL2"})
201+
}
200202

201-
p = s.RandomProject()
202-
cmd = exec.Command(s.command, "-f", "./assets/multiple/two.yml", "-f", "./assets/multiple/one.yml", "-p", p, "create")
203+
func (s *RunSuite) TestMultipleComposeFilesTwoOne(c *C) {
204+
p := "multiple"
205+
cmd := exec.Command(s.command, "-f", "./assets/multiple/two.yml", "-f", "./assets/multiple/one.yml", "create")
203206
cmd.Stdout = os.Stdout
204207
cmd.Stderr = os.Stderr
205208
cmd.Stdin = os.Stdin
206-
err = cmd.Run()
209+
err := cmd.Run()
207210

208211
c.Assert(err, IsNil)
209212

213+
containerNames := []string{"multiple", "simple", "another", "yetanother"}
214+
210215
for _, containerName := range containerNames {
211216
name := fmt.Sprintf("%s_%s_1", p, containerName)
212217
container := s.GetContainerByName(c, name)
213218

214219
c.Assert(container, NotNil)
215220
}
216221

217-
name = fmt.Sprintf("%s_%s_1", p, "multiple")
218-
container = s.GetContainerByName(c, name)
222+
name := fmt.Sprintf("%s_%s_1", p, "multiple")
223+
container := s.GetContainerByName(c, name)
219224

220225
c.Assert(container.Config.Image, Equals, "tianon/true")
221226
c.Assert(container.Config.Cmd, DeepEquals, []string{"echo", "two"})
222227
c.Assert(container.Config.Env, DeepEquals, []string{"KEY2=VAL2", "KEY1=VAL1"})
223228
}
229+
230+
func (s *RunSuite) TestDefaultMultipleComposeFiles(c *C) {
231+
p := s.RandomProject()
232+
cmd := exec.Command(filepath.Join("../../", s.command), "-p", p, "create")
233+
cmd.Stdout = os.Stdout
234+
cmd.Stderr = os.Stderr
235+
cmd.Stdin = os.Stdin
236+
cmd.Dir = "./assets/multiple-composefiles-default/"
237+
err := cmd.Run()
238+
239+
c.Assert(err, IsNil)
240+
241+
containerNames := []string{"simple", "another", "yetanother"}
242+
243+
for _, containerName := range containerNames {
244+
name := fmt.Sprintf("%s_%s_1", p, containerName)
245+
container := s.GetContainerByName(c, name)
246+
247+
c.Assert(container, NotNil)
248+
}
249+
250+
}

project/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ func (c *Context) readComposeFiles() error {
5757

5858
for _, composeFile := range c.ComposeFiles {
5959
composeBytes, err := ioutil.ReadFile(composeFile)
60-
if !os.IsNotExist(err) {
60+
if err != nil && !os.IsNotExist(err) {
6161
logrus.Errorf("Failed to open the compose file: %s", composeFile)
6262
return err
6363
}
64-
if !c.IgnoreMissingConfig {
64+
if err != nil && !c.IgnoreMissingConfig {
6565
logrus.Errorf("Failed to find the compose file: %s", composeFile)
6666
return err
6767
}

0 commit comments

Comments
 (0)