2015-11-12 19:55:17 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2017-04-11 17:34:19 +00:00
|
|
|
"path/filepath"
|
2015-11-12 19:55:17 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2017-04-11 17:34:19 +00:00
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
2015-11-12 19:55:17 +00:00
|
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContainerStopSignal(t *testing.T) {
|
|
|
|
c := &Container{
|
|
|
|
CommonContainer: CommonContainer{
|
2015-12-18 18:36:17 +00:00
|
|
|
Config: &container.Config{},
|
2015-11-12 19:55:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2015-12-18 18:36:17 +00:00
|
|
|
Config: &container.Config{StopSignal: "SIGKILL"},
|
2015-11-12 19:55:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
s = c.StopSignal()
|
|
|
|
if s != 9 {
|
|
|
|
t.Fatalf("Expected 9, got %v", s)
|
|
|
|
}
|
|
|
|
}
|
2016-05-26 20:34:48 +00:00
|
|
|
|
|
|
|
func TestContainerStopTimeout(t *testing.T) {
|
|
|
|
c := &Container{
|
|
|
|
CommonContainer: CommonContainer{
|
|
|
|
Config: &container.Config{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
s := c.StopTimeout()
|
2016-06-07 03:29:05 +00:00
|
|
|
if s != DefaultStopTimeout {
|
|
|
|
t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s)
|
2016-05-26 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stopTimeout := 15
|
|
|
|
c = &Container{
|
|
|
|
CommonContainer: CommonContainer{
|
|
|
|
Config: &container.Config{StopTimeout: &stopTimeout},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s = c.StopSignal()
|
|
|
|
if s != 15 {
|
|
|
|
t.Fatalf("Expected 15, got %v", s)
|
|
|
|
}
|
|
|
|
}
|
2017-04-11 17:34:19 +00:00
|
|
|
|
|
|
|
func TestContainerSecretReferenceDestTarget(t *testing.T) {
|
|
|
|
ref := &swarmtypes.SecretReference{
|
|
|
|
File: &swarmtypes.SecretReferenceFileTarget{
|
|
|
|
Name: "app",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
d := getSecretTargetPath(ref)
|
|
|
|
expected := filepath.Join(containerSecretMountPath, "app")
|
|
|
|
if d != expected {
|
|
|
|
t.Fatalf("expected secret dest %q; received %q", expected, d)
|
|
|
|
}
|
|
|
|
}
|