1
0
mirror of https://github.com/containrrr/watchtower.git synced 2024-12-15 09:14:13 +02:00
watchtower/container/container_test.go
Brian DeHamer 7cf2d7f1d8 Support Zodiac-based deployments
Since Zodiac always uses image IDs for deployments we can relay on the
standard container image field to determine the image that was used to
start the container. Luckily, Zodiac writes the original image name to a
label in the container metadata. If we find that Zodiac-specific label
on a running container we will use the associated value when trying to
determine if the container's image has changed.
2015-08-13 16:06:00 +00:00

148 lines
2.9 KiB
Go

package container
import (
"testing"
"github.com/samalba/dockerclient"
"github.com/stretchr/testify/assert"
)
func TestID(t *testing.T) {
c := Container{
containerInfo: &dockerclient.ContainerInfo{Id: "foo"},
}
assert.Equal(t, "foo", c.ID())
}
func TestName(t *testing.T) {
c := Container{
containerInfo: &dockerclient.ContainerInfo{Name: "foo"},
}
assert.Equal(t, "foo", c.Name())
}
func TestImageID(t *testing.T) {
c := Container{
imageInfo: &dockerclient.ImageInfo{
Id: "foo",
},
}
assert.Equal(t, "foo", c.ImageID())
}
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())
}
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())
}
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)
}
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())
}
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())
}