github.com/MOXA-ISD/edge-library-libcompose@v0.4.1-0.20200417083957-c90441e63650/integration/env_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"os"
     7  	"os/exec"
     8  
     9  	. "gopkg.in/check.v1"
    10  )
    11  
    12  func (s *CliSuite) TestCreateWithEnvInCurrentDir(c *C) {
    13  	cwd, err := os.Getwd()
    14  	c.Assert(err, IsNil)
    15  	defer os.Chdir(cwd)
    16  
    17  	c.Assert(os.Chdir("./assets/env"), IsNil, Commentf("Could not change current directory to ./assets/env"))
    18  
    19  	projectName := s.RandomProject()
    20  	cmd := exec.Command("../../../bundles/libcompose-cli", "--verbose", "-p", projectName, "-f", "-", "create")
    21  	cmd.Stdin = bytes.NewBufferString(`
    22  hello:
    23    image: tianon/true
    24    labels:
    25      - "FOO=${FOO}"
    26  `)
    27  	output, err := cmd.CombinedOutput()
    28  	c.Assert(err, IsNil, Commentf("%s", output))
    29  
    30  	name := fmt.Sprintf("%s_%s_1", projectName, "hello")
    31  	cn := s.GetContainerByName(c, name)
    32  	c.Assert(cn, NotNil)
    33  
    34  	c.Assert(len(cn.Config.Labels), Equals, 7, Commentf("%v", cn.Config.Env))
    35  	c.Assert(cn.Config.Labels["FOO"], Equals, "bar", Commentf("%v", cn.Config.Labels))
    36  }
    37  
    38  func (s *CliSuite) TestCreateWithEnvNotInCurrentDir(c *C) {
    39  	p := s.CreateProjectFromText(c, `
    40  hello:
    41    image: tianon/true
    42  `)
    43  
    44  	name := fmt.Sprintf("%s_%s_1", p, "hello")
    45  	cn := s.GetContainerByName(c, name)
    46  	c.Assert(cn, NotNil)
    47  
    48  	c.Assert(len(cn.Config.Labels), Equals, 6, Commentf("%v", cn.Config.Labels))
    49  }