2014-04-17 17:43:01 -04:00
|
|
|
package daemon
|
2013-11-14 01:08:08 -05:00
|
|
|
|
2015-08-18 13:30:44 -04:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
2013-11-14 01:08:08 -05:00
|
|
|
|
|
|
|
func TestGetFullName(t *testing.T) {
|
2014-03-07 21:42:29 -05:00
|
|
|
name, err := GetFullContainerName("testing")
|
2013-11-14 01:08:08 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if name != "/testing" {
|
|
|
|
t.Fatalf("Expected /testing got %s", name)
|
|
|
|
}
|
2014-03-07 21:42:29 -05:00
|
|
|
if _, err := GetFullContainerName(""); err == nil {
|
2013-11-14 01:08:08 -05:00
|
|
|
t.Fatal("Error should not be nil")
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 13:45:07 -04: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 16:51:48 -04: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)
|
|
|
|
}
|
|
|
|
}
|