inspect_test.go 2.0 KB

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