container_unit_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. CommonContainer: CommonContainer{
  12. Config: &container.Config{},
  13. },
  14. }
  15. def, err := signal.ParseSignal(signal.DefaultStopSignal)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. s := c.StopSignal()
  20. if s != int(def) {
  21. t.Fatalf("Expected %v, got %v", def, s)
  22. }
  23. c = &Container{
  24. CommonContainer: CommonContainer{
  25. Config: &container.Config{StopSignal: "SIGKILL"},
  26. },
  27. }
  28. s = c.StopSignal()
  29. if s != 9 {
  30. t.Fatalf("Expected 9, got %v", s)
  31. }
  32. }
  33. func TestContainerStopTimeout(t *testing.T) {
  34. c := &Container{
  35. CommonContainer: CommonContainer{
  36. Config: &container.Config{},
  37. },
  38. }
  39. s := c.StopTimeout()
  40. if s != DefaultStopTimeout {
  41. t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s)
  42. }
  43. stopTimeout := 15
  44. c = &Container{
  45. CommonContainer: CommonContainer{
  46. Config: &container.Config{StopTimeout: &stopTimeout},
  47. },
  48. }
  49. s = c.StopSignal()
  50. if s != 15 {
  51. t.Fatalf("Expected 15, got %v", s)
  52. }
  53. }
  54. func TestContainerSecretReferenceDestTarget(t *testing.T) {
  55. ref := &swarmtypes.SecretReference{
  56. File: &swarmtypes.SecretReferenceFileTarget{
  57. Name: "app",
  58. },
  59. }
  60. d := getSecretTargetPath(ref)
  61. expected := filepath.Join(containerSecretMountPath, "app")
  62. if d != expected {
  63. t.Fatalf("expected secret dest %q; received %q", expected, d)
  64. }
  65. }