container_unit_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package container
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/docker/docker/api/types/container"
  6. swarmtypes "github.com/docker/docker/api/types/swarm"
  7. "github.com/docker/docker/pkg/signal"
  8. )
  9. func TestContainerStopSignal(t *testing.T) {
  10. c := &Container{
  11. Config: &container.Config{},
  12. }
  13. def, err := signal.ParseSignal(signal.DefaultStopSignal)
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. s := c.StopSignal()
  18. if s != int(def) {
  19. t.Fatalf("Expected %v, got %v", def, s)
  20. }
  21. c = &Container{
  22. Config: &container.Config{StopSignal: "SIGKILL"},
  23. }
  24. s = c.StopSignal()
  25. if s != 9 {
  26. t.Fatalf("Expected 9, got %v", s)
  27. }
  28. }
  29. func TestContainerStopTimeout(t *testing.T) {
  30. c := &Container{
  31. Config: &container.Config{},
  32. }
  33. s := c.StopTimeout()
  34. if s != DefaultStopTimeout {
  35. t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s)
  36. }
  37. stopTimeout := 15
  38. c = &Container{
  39. Config: &container.Config{StopTimeout: &stopTimeout},
  40. }
  41. s = c.StopSignal()
  42. if s != 15 {
  43. t.Fatalf("Expected 15, got %v", s)
  44. }
  45. }
  46. func TestContainerSecretReferenceDestTarget(t *testing.T) {
  47. ref := &swarmtypes.SecretReference{
  48. File: &swarmtypes.SecretReferenceFileTarget{
  49. Name: "app",
  50. },
  51. }
  52. d := getSecretTargetPath(ref)
  53. expected := filepath.Join(containerSecretMountPath, "app")
  54. if d != expected {
  55. t.Fatalf("expected secret dest %q; received %q", expected, d)
  56. }
  57. }