Ejemplo n.º 1
0
func (s *MySuite) TestLinksDoNotExist(c *C) {
	data := `web:
    image: ubuntu
    links:
        - no
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "Linked service 'no' in service 'web' does not exist\n")

	data = `web:
    image: ubuntu
    links:
        - alias:no
`
	err = ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "Linked service 'no' in service 'web' does not exist\n")
}
Ejemplo n.º 2
0
func (s *MySuite) TestStackList(c *C) {
	err := stack.CreateCmd("test1", s.StackFile)
	c.Assert(err, IsNil)
	err = stack.CreateCmd("test2", s.StackFile)
	c.Assert(err, IsNil)
	err = stack.ListCmd()
	c.Assert(err, IsNil)
}
Ejemplo n.º 3
0
func (s *MySuite) TestStackCreate(c *C) {
	err := stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	data, _ := ioutil.ReadFile(stack.DefinitionFilePath("test"))
	c.Assert(string(data), Equals, s.Data)
	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
}
Ejemplo n.º 4
0
func (s *MySuite) TestMinimumStackValidation(c *C) {
	data := `web:
    image: ubuntu
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	stackObj, err := stack.Read("test")
	if err != nil {
		log.Fatal(err)
	}

	s1 := stackObj.Definition["web"]
	c.Assert(s1.Image, Equals, "ubuntu")
	c.Assert(s1.Command, Equals, "")
	c.Assert(s1.Links, DeepEquals, []string(nil))
	c.Assert(s1.Ports, DeepEquals, []string(nil))
	c.Assert(s1.Volumes, DeepEquals, []string(nil))
	c.Assert(s1.Volumes_from, DeepEquals, []string(nil))
	c.Assert(s1.Environment, DeepEquals, []string(nil))
	c.Assert(s1.Entrypoint, Equals, "")
	c.Assert(s1.Mem_limit, Equals, "")
	c.Assert(s1.Privileged, Equals, false)
	c.Assert(s1.Restart, Equals, "no")
	c.Assert(s1.Strategy, Equals, "balance")
	c.Assert(s1.Scale, Equals, 1)
	c.Assert(s1.Tags, DeepEquals, []string(nil))
}
Ejemplo n.º 5
0
func (s *MySuite) TestStackRemove(c *C) {
	err := stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	err = stack.RemoveCmd("test")
	c.Assert(err, IsNil)
	filePath := stack.DefinitionFilePath("test")
	_, err = os.Stat(filePath)
	c.Assert(err, NotNil)
	err = stack.RemoveCmd("test")
	c.Assert(err, NotNil)
}
Ejemplo n.º 6
0
func (s *MySuite) TestWrongServiceName(c *C) {
	data := `web-test:
    image: ubuntu
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("Test01", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "Service name not valid: 'web-test' does not match pattern '^[0-9a-zA-Z]{1,25}$'\n")
}
Ejemplo n.º 7
0
func (s *MySuite) TestStackWithTabs(c *C) {
	data := `web:
	image: ubuntu
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "'\t' characters are not allowed in YAML files")
}
Ejemplo n.º 8
0
func (s *MySuite) TestWrongLinks(c *C) {
	data := `web:
    image: ubuntu
    links:
        - data-base
        - d-b:database
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "Service web not valid. see errors:\n"+
		"links.0: 'data-base' does not match pattern '^[0-9a-zA-Z]{1,20}(:[0-9a-zA-Z]{1,20})?$'\n"+
		"links.1: 'd-b:database' does not match pattern '^[0-9a-zA-Z]{1,20}(:[0-9a-zA-Z]{1,20})?$'\n")
}
Ejemplo n.º 9
0
func (s *MySuite) TestWrongPorts(c *C) {
	data := `web:
    image: ubuntu
    ports:
        - 0:10
        - 888-888
        - 12a34
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "Service web not valid. see errors:\n"+
		"ports.0: '0:10' does not match pattern '^[1-9][0-9]{0,4}(:[1-9][0-9]{0,4})?$'\n"+
		"ports.1: '888-888' does not match pattern '^[1-9][0-9]{0,4}(:[1-9][0-9]{0,4})?$'\n"+
		"ports.2: '12a34' does not match pattern '^[1-9][0-9]{0,4}(:[1-9][0-9]{0,4})?$'\n")
}
Ejemplo n.º 10
0
func (s *MySuite) TestStackUpdate(c *C) {
	err := stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	data := `web:
    image: ubuntu
    privileged: true
`
	err = ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}
	err = stack.UpdateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	content, err := ioutil.ReadFile(stack.DefinitionFilePath("test"))
	if err != nil {
		log.Fatal(err)
	}
	c.Assert(string(content), Equals, data)
	err = stack.UpdateCmd("test2", s.StackFile)
	c.Assert(err, NotNil)
}
Ejemplo n.º 11
0
func (s *MySuite) TestFullStackValidation(c *C) {
	data := `web:
    image: ubuntu
    command: ls
    links:
        - db:database
        - database
    ports:
        - 80:80
        - 443:4443
    volumes:
        - /tmp1
        - /tmp2:/tmp2
        - /tmp3:/tmp3:ro
        - /tmp4:/tmp4:rw
    volumes_from:
        - database
    environment:
        - PATH
        - TEST=test
    entrypoint: ls
    mem_limit: 1000m
    privileged: true
    restart: always
    strategy: every_node
    scale: 2
    tags:
        - node-1
        - staging
database:
    image: mysql
`
	err := ioutil.WriteFile(s.StackFile, []byte(data), 0644)
	if err != nil {
		log.Fatal(err)
	}

	err = stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	stackObj, err := stack.Read("test")
	if err != nil {
		log.Fatal(err)
	}
	s1 := stackObj.Definition["web"]
	s2 := stackObj.Definition["database"]

	c.Assert(s1.Image, Equals, "ubuntu")
	c.Assert(s1.Command, Equals, "ls")
	c.Assert(s1.Links, DeepEquals, []string{"db:database", "database"})
	c.Assert(s1.Ports, DeepEquals, []string{"80:80", "443:4443"})
	c.Assert(s1.Volumes, DeepEquals, []string{"/tmp1", "/tmp2:/tmp2", "/tmp3:/tmp3:ro", "/tmp4:/tmp4:rw"})
	c.Assert(s1.Volumes_from, DeepEquals, []string{"database"})
	c.Assert(s1.Environment, DeepEquals, []string{"PATH", "TEST=test"})
	c.Assert(s1.Entrypoint, Equals, "ls")
	c.Assert(s1.Mem_limit, Equals, "1000m")
	c.Assert(s1.Privileged, Equals, true)
	c.Assert(s1.Restart, Equals, "always")
	c.Assert(s1.Strategy, Equals, "every_node")
	c.Assert(s1.Scale, Equals, 2)
	c.Assert(s1.Tags, DeepEquals, []string{"node-1", "staging"})
	c.Assert(s2.Image, Equals, "mysql")
}
Ejemplo n.º 12
0
func (s *MySuite) TestStackExport(c *C) {
	err := stack.CreateCmd("test", s.StackFile)
	c.Assert(err, IsNil)
	err = stack.ExportCmd("test")
	c.Assert(err, IsNil)
}