2015-07-21 18:04:41 +02:00
|
|
|
package container
|
2015-07-14 22:51:12 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/samalba/dockerclient"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2015-07-23 00:52:22 +02:00
|
|
|
func TestID(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{Id: "foo"},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "foo", c.ID())
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:51:12 +02:00
|
|
|
func TestName(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{Name: "foo"},
|
|
|
|
}
|
|
|
|
|
2015-07-23 00:52:22 +02:00
|
|
|
assert.Equal(t, "foo", c.Name())
|
|
|
|
}
|
2015-07-14 22:51:12 +02:00
|
|
|
|
2015-07-31 20:24:27 +02:00
|
|
|
func TestImageID(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
imageInfo: &dockerclient.ImageInfo{
|
|
|
|
Id: "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "foo", c.ImageID())
|
|
|
|
}
|
|
|
|
|
2015-07-23 00:52:22 +02:00
|
|
|
func TestImageName_Tagged(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Image: "foo:latest",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "foo:latest", c.ImageName())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImageName_Untagged(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Image: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "foo:latest", c.ImageName())
|
2015-07-14 22:51:12 +02:00
|
|
|
}
|
|
|
|
|
2015-08-12 22:49:45 +02:00
|
|
|
func TestImageName_Zodiac(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{"com.centurylinklabs.zodiac.original-image": "foo"},
|
|
|
|
Image: "1234567890",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "foo:latest", c.ImageName())
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:51:12 +02:00
|
|
|
func TestLinks(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
HostConfig: &dockerclient.HostConfig{
|
|
|
|
Links: []string{"foo:foo", "bar:bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
links := c.Links()
|
|
|
|
|
|
|
|
assert.Equal(t, []string{"foo", "bar"}, links)
|
|
|
|
}
|
2015-07-21 00:54:18 +02:00
|
|
|
|
|
|
|
func TestIsWatchtower_True(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{"com.centurylinklabs.watchtower": "true"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, c.IsWatchtower())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsWatchtower_WrongLabelValue(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{"com.centurylinklabs.watchtower": "false"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, c.IsWatchtower())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsWatchtower_NoLabel(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, c.IsWatchtower())
|
|
|
|
}
|
2015-07-23 00:52:22 +02:00
|
|
|
|
|
|
|
func TestStopSignal_Present(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"com.centurylinklabs.watchtower.stop-signal": "SIGQUIT",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "SIGQUIT", c.StopSignal())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStopSignal_NoLabel(t *testing.T) {
|
|
|
|
c := Container{
|
|
|
|
containerInfo: &dockerclient.ContainerInfo{
|
|
|
|
Config: &dockerclient.ContainerConfig{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.StopSignal())
|
|
|
|
}
|