(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestServiceCreateCompatiblePlatforms(t *testing.T) { |
| 57 | client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) { |
| 58 | if strings.HasPrefix(req.URL.Path, defaultAPIPath+"/services/create") { |
| 59 | var serviceSpec swarm.ServiceSpec |
| 60 | |
| 61 | // check if the /distribution endpoint returned correct output |
| 62 | err := json.NewDecoder(req.Body).Decode(&serviceSpec) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | |
| 67 | assert.Check(t, is.Equal("foobar:1.0@sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", serviceSpec.TaskTemplate.ContainerSpec.Image)) |
| 68 | assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1)) |
| 69 | |
| 70 | p := serviceSpec.TaskTemplate.Placement.Platforms[0] |
| 71 | return mockJSONResponse(http.StatusOK, nil, swarm.ServiceCreateResponse{ |
| 72 | ID: "service_" + p.OS + "_" + p.Architecture, |
| 73 | })(req) |
| 74 | } else if strings.HasPrefix(req.URL.Path, defaultAPIPath+"/distribution/") { |
| 75 | return mockJSONResponse(http.StatusOK, nil, registrytypes.DistributionInspect{ |
| 76 | Descriptor: ocispec.Descriptor{ |
| 77 | Digest: "sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", |
| 78 | }, |
| 79 | Platforms: []ocispec.Platform{ |
| 80 | { |
| 81 | Architecture: "amd64", |
| 82 | OS: "linux", |
| 83 | }, |
| 84 | }, |
| 85 | })(req) |
| 86 | } else { |
| 87 | return nil, fmt.Errorf("unexpected URL '%s'", req.URL.Path) |
| 88 | } |
| 89 | })) |
| 90 | assert.NilError(t, err) |
| 91 | |
| 92 | r, err := client.ServiceCreate(t.Context(), ServiceCreateOptions{ |
| 93 | Spec: swarm.ServiceSpec{ |
| 94 | TaskTemplate: swarm.TaskSpec{ |
| 95 | ContainerSpec: &swarm.ContainerSpec{Image: "foobar:1.0"}, |
| 96 | }, |
| 97 | }, |
| 98 | QueryRegistry: true, |
| 99 | }) |
| 100 | assert.NilError(t, err) |
| 101 | assert.Check(t, is.Equal("service_linux_amd64", r.ID)) |
| 102 | } |
| 103 | |
| 104 | func TestServiceCreateDigestPinning(t *testing.T) { |
| 105 | dgst := "sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96" |
nothing calls this directly
no test coverage detected
searching dependent graphs…