MCPcopy Index your code
hub / github.com/docker/cli / TestServiceUpdateResolveImageChanged

Function TestServiceUpdateResolveImageChanged

cli/command/stack/deploy_test.go:42–118  ·  view source on GitHub ↗

TestServiceUpdateResolveImageChanged tests that the service's image digest, and "ForceUpdate" is preserved if the image did not change in the compose file

(t *testing.T)

Source from the content-addressed store, hash-verified

40// image digest, and "ForceUpdate" is preserved if the image did not change in
41// the compose file
42func TestServiceUpdateResolveImageChanged(t *testing.T) {
43 namespace := convert.NewNamespace("mystack")
44
45 var receivedOptions client.ServiceUpdateOptions
46
47 fakeCli := test.NewFakeCli(&fakeClient{
48 serviceListFunc: func(options client.ServiceListOptions) (client.ServiceListResult, error) {
49 return client.ServiceListResult{
50 Items: []swarm.Service{
51 {
52 Spec: swarm.ServiceSpec{
53 Annotations: swarm.Annotations{
54 Name: namespace.Name() + "_myservice",
55 Labels: map[string]string{"com.docker.stack.image": "foobar:1.2.3"},
56 },
57 TaskTemplate: swarm.TaskSpec{
58 ContainerSpec: &swarm.ContainerSpec{
59 Image: "foobar:1.2.3@sha256:deadbeef",
60 },
61 ForceUpdate: 123,
62 },
63 },
64 },
65 },
66 }, nil
67 },
68 serviceUpdateFunc: func(serviceID string, options client.ServiceUpdateOptions) (client.ServiceUpdateResult, error) {
69 receivedOptions = options
70 return client.ServiceUpdateResult{}, nil
71 },
72 })
73
74 testcases := []struct {
75 image string
76 expectedQueryRegistry bool
77 expectedImage string
78 expectedForceUpdate uint64
79 }{
80 // Image not changed
81 {
82 image: "foobar:1.2.3",
83 expectedQueryRegistry: false,
84 expectedImage: "foobar:1.2.3@sha256:deadbeef",
85 expectedForceUpdate: 123,
86 },
87 // Image changed
88 {
89 image: "foobar:1.2.4",
90 expectedQueryRegistry: true,
91 expectedImage: "foobar:1.2.4",
92 expectedForceUpdate: 123,
93 },
94 }
95
96 ctx := context.Background()
97
98 for _, tc := range testcases {
99 t.Run(tc.image, func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

NameMethod · 0.95
deployServicesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…