github.com/gunjan5/docker@v1.8.2/daemon/container_unit_test.go (about) 1 package daemon 2 3 import "testing" 4 5 func TestGetFullName(t *testing.T) { 6 name, err := GetFullContainerName("testing") 7 if err != nil { 8 t.Fatal(err) 9 } 10 if name != "/testing" { 11 t.Fatalf("Expected /testing got %s", name) 12 } 13 if _, err := GetFullContainerName(""); err == nil { 14 t.Fatal("Error should not be nil") 15 } 16 } 17 18 func TestValidContainerNames(t *testing.T) { 19 invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"} 20 validNames := []string{"word-word", "word_word", "1weoid"} 21 22 for _, name := range invalidNames { 23 if validContainerNamePattern.MatchString(name) { 24 t.Fatalf("%q is not a valid container name and was returned as valid.", name) 25 } 26 } 27 28 for _, name := range validNames { 29 if !validContainerNamePattern.MatchString(name) { 30 t.Fatalf("%q is a valid container name and was returned as invalid.", name) 31 } 32 } 33 }