2014-04-17 14:43:01 -07:00
|
|
|
package daemon
|
2013-11-14 06:08:08 +00:00
|
|
|
|
2015-07-21 00:29:24 +02:00
|
|
|
import "testing"
|
2013-11-14 06:08:08 +00:00
|
|
|
|
|
|
|
func TestGetFullName(t *testing.T) {
|
2014-03-07 18:42:29 -08:00
|
|
|
name, err := GetFullContainerName("testing")
|
2013-11-14 06:08:08 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if name != "/testing" {
|
|
|
|
t.Fatalf("Expected /testing got %s", name)
|
|
|
|
}
|
2014-03-07 18:42:29 -08:00
|
|
|
if _, err := GetFullContainerName(""); err == nil {
|
2013-11-14 06:08:08 +00:00
|
|
|
t.Fatal("Error should not be nil")
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 10:45:07 -07:00
|
|
|
|
|
|
|
func TestValidContainerNames(t *testing.T) {
|
|
|
|
invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"}
|
|
|
|
validNames := []string{"word-word", "word_word", "1weoid"}
|
|
|
|
|
|
|
|
for _, name := range invalidNames {
|
|
|
|
if validContainerNamePattern.MatchString(name) {
|
|
|
|
t.Fatalf("%q is not a valid container name and was returned as valid.", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range validNames {
|
|
|
|
if !validContainerNamePattern.MatchString(name) {
|
|
|
|
t.Fatalf("%q is a valid container name and was returned as invalid.", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|