github.com/connyay/libcompose@v0.4.0/integration/build_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os/exec"
     6  	"strings"
     7  
     8  	"golang.org/x/net/context"
     9  
    10  	. "gopkg.in/check.v1"
    11  )
    12  
    13  func (s *CliSuite) TestBuild(c *C) {
    14  	p := s.RandomProject()
    15  	cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
    16  	err := cmd.Run()
    17  
    18  	oneImageName := fmt.Sprintf("%s_one", p)
    19  	twoImageName := fmt.Sprintf("%s_two", p)
    20  
    21  	c.Assert(err, IsNil)
    22  
    23  	client := GetClient(c)
    24  	one, _, err := client.ImageInspectWithRaw(context.Background(), oneImageName)
    25  	c.Assert(err, IsNil)
    26  	c.Assert([]string(one.Config.Cmd), DeepEquals, []string{"echo", "one"})
    27  
    28  	two, _, err := client.ImageInspectWithRaw(context.Background(), twoImageName)
    29  	c.Assert(err, IsNil)
    30  	c.Assert([]string(two.Config.Cmd), DeepEquals, []string{"echo", "two"})
    31  }
    32  
    33  func (s *CliSuite) TestBuildWithNoCache1(c *C) {
    34  	p := s.RandomProject()
    35  	cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
    36  
    37  	output, err := cmd.Output()
    38  	c.Assert(err, IsNil)
    39  
    40  	cmd = exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
    41  	output, err = cmd.Output()
    42  	c.Assert(err, IsNil)
    43  	out := string(output[:])
    44  	c.Assert(strings.Contains(out,
    45  		"Using cache"),
    46  		Equals, true, Commentf("%s", out))
    47  }
    48  
    49  func (s *CliSuite) TestBuildWithNoCache2(c *C) {
    50  	p := s.RandomProject()
    51  	cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
    52  
    53  	output, err := cmd.Output()
    54  	c.Assert(err, IsNil)
    55  
    56  	cmd = exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build", "--no-cache")
    57  	output, err = cmd.Output()
    58  	c.Assert(err, IsNil)
    59  	out := string(output[:])
    60  	c.Assert(strings.Contains(out,
    61  		"Using cache"),
    62  		Equals, false, Commentf("%s", out))
    63  }
    64  
    65  func (s *CliSuite) TestBuildWithNoCache3(c *C) {
    66  	p := s.RandomProject()
    67  	cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build", "--no-cache")
    68  	err := cmd.Run()
    69  
    70  	oneImageName := fmt.Sprintf("%s_one", p)
    71  	twoImageName := fmt.Sprintf("%s_two", p)
    72  
    73  	c.Assert(err, IsNil)
    74  
    75  	client := GetClient(c)
    76  	one, _, err := client.ImageInspectWithRaw(context.Background(), oneImageName)
    77  	c.Assert(err, IsNil)
    78  	c.Assert([]string(one.Config.Cmd), DeepEquals, []string{"echo", "one"})
    79  
    80  	two, _, err := client.ImageInspectWithRaw(context.Background(), twoImageName)
    81  	c.Assert(err, IsNil)
    82  	c.Assert([]string(two.Config.Cmd), DeepEquals, []string{"echo", "two"})
    83  }
    84  
    85  func (s *CliSuite) TestBuildWithArgs(c *C) {
    86  	p := s.RandomProject()
    87  	cmd := exec.Command(s.command, "-f", "./assets/v2-build-args/docker-compose.yml", "-p", p, "build")
    88  
    89  	output, err := cmd.Output()
    90  	c.Assert(err, IsNil)
    91  
    92  	c.Assert(strings.Contains(string(output), "buildno is 1"), Equals, true, Commentf("Expected 'buildno is 1' in output, got \n%s", string(output)))
    93  	c.Assert(strings.Contains(string(output), "buildno is 0"), Equals, false, Commentf("Expected to not find 'buildno is 0' in output, got \n%s", string(output)))
    94  }