You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
2.4 KiB
Go
125 lines
2.4 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 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 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())
|
|
}
|