container_unit_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package container
  2. import (
  3. "testing"
  4. "github.com/docker/docker/api/types/container"
  5. "github.com/docker/docker/pkg/signal"
  6. )
  7. func TestContainerStopSignal(t *testing.T) {
  8. c := &Container{
  9. CommonContainer: CommonContainer{
  10. Config: &container.Config{},
  11. },
  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. CommonContainer: CommonContainer{
  23. Config: &container.Config{StopSignal: "SIGKILL"},
  24. },
  25. }
  26. s = c.StopSignal()
  27. if s != 9 {
  28. t.Fatalf("Expected 9, got %v", s)
  29. }
  30. }
  31. func TestContainerStopTimeout(t *testing.T) {
  32. c := &Container{
  33. CommonContainer: CommonContainer{
  34. Config: &container.Config{},
  35. },
  36. }
  37. s := c.StopTimeout()
  38. if s != DefaultStopTimeout {
  39. t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s)
  40. }
  41. stopTimeout := 15
  42. c = &Container{
  43. CommonContainer: CommonContainer{
  44. Config: &container.Config{StopTimeout: &stopTimeout},
  45. },
  46. }
  47. s = c.StopSignal()
  48. if s != 15 {
  49. t.Fatalf("Expected 15, got %v", s)
  50. }
  51. }