mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-15 14:40:13 +01:00
Refactoring & renaming
This commit is contained in:
parent
3dd06cffb1
commit
00f2875abf
15 changed files with 254 additions and 233 deletions
59
container/sort_test.go
Normal file
59
container/sort_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/samalba/dockerclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestByCreated(t *testing.T) {
|
||||
c1 := Container{
|
||||
containerInfo: &dockerclient.ContainerInfo{
|
||||
Created: "2015-07-01T12:00:01.000000000Z",
|
||||
},
|
||||
}
|
||||
c2 := Container{
|
||||
containerInfo: &dockerclient.ContainerInfo{
|
||||
Created: "2015-07-01T12:00:02.000000000Z",
|
||||
},
|
||||
}
|
||||
c3 := Container{
|
||||
containerInfo: &dockerclient.ContainerInfo{
|
||||
Created: "2015-07-01T12:00:02.000000001Z",
|
||||
},
|
||||
}
|
||||
cs := []Container{c3, c2, c1}
|
||||
|
||||
sort.Sort(ByCreated(cs))
|
||||
|
||||
assert.Equal(t, []Container{c1, c2, c3}, cs)
|
||||
}
|
||||
|
||||
func TestSortByDependencies_Success(t *testing.T) {
|
||||
c1 := NewTestContainer("1", []string{})
|
||||
c2 := NewTestContainer("2", []string{"1:"})
|
||||
c3 := NewTestContainer("3", []string{"2:"})
|
||||
c4 := NewTestContainer("4", []string{"3:"})
|
||||
c5 := NewTestContainer("5", []string{"4:"})
|
||||
c6 := NewTestContainer("6", []string{"5:", "3:"})
|
||||
containers := []Container{c6, c2, c4, c1, c3, c5}
|
||||
|
||||
result, err := SortByDependencies(containers)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []Container{c1, c2, c3, c4, c5, c6}, result)
|
||||
}
|
||||
|
||||
func TestSortByDependencies_Error(t *testing.T) {
|
||||
c1 := NewTestContainer("1", []string{"3:"})
|
||||
c2 := NewTestContainer("2", []string{"1:"})
|
||||
c3 := NewTestContainer("3", []string{"2:"})
|
||||
containers := []Container{c1, c2, c3}
|
||||
|
||||
_, err := SortByDependencies(containers)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.EqualError(t, err, "Circular reference to 1")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue