1
0
mirror of https://github.com/containrrr/watchtower.git synced 2025-06-30 23:23:50 +02:00
Files
watchtower/updater/sorter_test.go
Brian DeHamer c02c4b9ec1 Handle container links
Ensures that linked containers are restarted if any of their
dependencies are restarted -- and makes sure that everything happens in
the correct order.
2015-07-15 22:22:00 +00:00

38 lines
1.1 KiB
Go

package updater
import (
"testing"
"github.com/CenturyLinkLabs/watchtower/docker"
"github.com/stretchr/testify/assert"
)
func TestContainerSorter_Success(t *testing.T) {
c1 := docker.NewTestContainer("1", []string{})
c2 := docker.NewTestContainer("2", []string{"1:"})
c3 := docker.NewTestContainer("3", []string{"2:"})
c4 := docker.NewTestContainer("4", []string{"3:"})
c5 := docker.NewTestContainer("5", []string{"4:"})
c6 := docker.NewTestContainer("6", []string{"5:", "3:"})
containers := []docker.Container{c6, c2, c4, c1, c3, c5}
cs := ContainerSorter{}
result, err := cs.Sort(containers)
assert.NoError(t, err)
assert.Equal(t, []docker.Container{c1, c2, c3, c4, c5, c6}, result)
}
func TestContainerSorter_Error(t *testing.T) {
c1 := docker.NewTestContainer("1", []string{"3:"})
c2 := docker.NewTestContainer("2", []string{"1:"})
c3 := docker.NewTestContainer("3", []string{"2:"})
containers := []docker.Container{c1, c2, c3}
cs := ContainerSorter{}
_, err := cs.Sort(containers)
assert.Error(t, err)
assert.EqualError(t, err, "Circular reference to 1")
}