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.
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package actions
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/CenturyLinkLabs/watchtower/container"
|
|
"github.com/samalba/dockerclient"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCheckDependencies(t *testing.T) {
|
|
cs := []container.Container{
|
|
newTestContainer("1", []string{}),
|
|
newTestContainer("2", []string{"1:"}),
|
|
newTestContainer("3", []string{"2:"}),
|
|
newTestContainer("4", []string{"3:"}),
|
|
newTestContainer("5", []string{"4:"}),
|
|
newTestContainer("6", []string{"5:"}),
|
|
}
|
|
cs[3].Stale = true
|
|
|
|
checkDependencies(cs)
|
|
|
|
assert.False(t, cs[0].Stale)
|
|
assert.False(t, cs[1].Stale)
|
|
assert.False(t, cs[2].Stale)
|
|
assert.True(t, cs[3].Stale)
|
|
assert.True(t, cs[4].Stale)
|
|
assert.True(t, cs[5].Stale)
|
|
}
|
|
|
|
func TestRandName(t *testing.T) {
|
|
validPattern := regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]+$`)
|
|
|
|
name := randName()
|
|
|
|
assert.True(t, validPattern.MatchString(name))
|
|
}
|
|
|
|
func newTestContainer(name string, links []string) container.Container {
|
|
return *container.NewContainer(
|
|
&dockerclient.ContainerInfo{
|
|
Name: name,
|
|
HostConfig: &dockerclient.HostConfig{
|
|
Links: links,
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
}
|