inspect_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package service
  2. import (
  3. "bytes"
  4. "strings"
  5. "testing"
  6. "time"
  7. "github.com/docker/docker/api/types/swarm"
  8. )
  9. func TestPrettyPrintWithNoUpdateConfig(t *testing.T) {
  10. b := new(bytes.Buffer)
  11. endpointSpec := &swarm.EndpointSpec{
  12. Mode: "vip",
  13. Ports: []swarm.PortConfig{
  14. {
  15. Protocol: swarm.PortConfigProtocolTCP,
  16. TargetPort: 5000,
  17. },
  18. },
  19. }
  20. two := uint64(2)
  21. s := swarm.Service{
  22. ID: "de179gar9d0o7ltdybungplod",
  23. Meta: swarm.Meta{
  24. Version: swarm.Version{Index: 315},
  25. CreatedAt: time.Now(),
  26. UpdatedAt: time.Now(),
  27. },
  28. Spec: swarm.ServiceSpec{
  29. Annotations: swarm.Annotations{
  30. Name: "my_service",
  31. Labels: map[string]string{"com.label": "foo"},
  32. },
  33. TaskTemplate: swarm.TaskSpec{
  34. ContainerSpec: swarm.ContainerSpec{
  35. Image: "foo/bar@sha256:this_is_a_test",
  36. },
  37. },
  38. Mode: swarm.ServiceMode{
  39. Replicated: &swarm.ReplicatedService{
  40. Replicas: &two,
  41. },
  42. },
  43. UpdateConfig: nil,
  44. Networks: []swarm.NetworkAttachmentConfig{
  45. {
  46. Target: "5vpyomhb6ievnk0i0o60gcnei",
  47. Aliases: []string{"web"},
  48. },
  49. },
  50. EndpointSpec: endpointSpec,
  51. },
  52. Endpoint: swarm.Endpoint{
  53. Spec: *endpointSpec,
  54. Ports: []swarm.PortConfig{
  55. {
  56. Protocol: swarm.PortConfigProtocolTCP,
  57. TargetPort: 5000,
  58. PublishedPort: 30000,
  59. },
  60. },
  61. VirtualIPs: []swarm.EndpointVirtualIP{
  62. {
  63. NetworkID: "6o4107cj2jx9tihgb0jyts6pj",
  64. Addr: "10.255.0.4/16",
  65. },
  66. },
  67. },
  68. UpdateStatus: swarm.UpdateStatus{
  69. StartedAt: time.Now(),
  70. CompletedAt: time.Now(),
  71. },
  72. }
  73. printService(b, s)
  74. if strings.Contains(b.String(), "UpdateStatus") {
  75. t.Fatal("Pretty print failed before parsing UpdateStatus")
  76. }
  77. }