2014-04-17 21:43:01 +00:00
|
|
|
package daemon
|
2013-11-14 06:08:08 +00:00
|
|
|
|
2015-07-20 22:29:24 +00:00
|
|
|
import "testing"
|
2013-11-14 06:08:08 +00:00
|
|
|
|
|
|
|
func TestGetFullName(t *testing.T) {
|
2014-03-08 02:42:29 +00: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-08 02:42:29 +00:00
|
|
|
if _, err := GetFullContainerName(""); err == nil {
|
2013-11-14 06:08:08 +00:00
|
|
|
t.Fatal("Error should not be nil")
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 17:45:07 +00: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-04 20:51:48 +00:00
|
|
|
|
|
|
|
func TestContainerStopSignal(t *testing.T) {
|
|
|
|
c := &Container{
|
|
|
|
CommonContainer: CommonContainer{
|
|
|
|
Config: &runconfig.Config{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def, err := signal.ParseSignal(signal.DefaultStopSignal)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s := c.stopSignal()
|
|
|
|
if s != int(def) {
|
|
|
|
t.Fatalf("Expected %v, got %v", def, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
c = &Container{
|
|
|
|
CommonContainer: CommonContainer{
|
|
|
|
Config: &runconfig.Config{StopSignal: "SIGKILL"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s = c.stopSignal()
|
|
|
|
if s != 9 {
|
|
|
|
t.Fatalf("Expected 9, got %v", s)
|
|
|
|
}
|
|
|
|
}
|