(t *testing.T)
| 32 | ) |
| 33 | |
| 34 | func TestImages(t *testing.T) { |
| 35 | mockCtrl := gomock.NewController(t) |
| 36 | defer mockCtrl.Finish() |
| 37 | |
| 38 | api, cli := prepareMocks(mockCtrl) |
| 39 | tested, err := NewComposeService(cli) |
| 40 | assert.NilError(t, err) |
| 41 | |
| 42 | args := projectFilter(strings.ToLower(testProject)) |
| 43 | listOpts := client.ContainerListOptions{All: true, Filters: args} |
| 44 | api.EXPECT().Ping(gomock.Any(), client.PingOptions{NegotiateAPIVersion: true}).Return(client.PingResult{APIVersion: "1.96"}, nil).AnyTimes() |
| 45 | api.EXPECT().ClientVersion().Return("1.96").AnyTimes() |
| 46 | timeStr1 := "2025-06-06T06:06:06.000000000Z" |
| 47 | created1, _ := time.Parse(time.RFC3339Nano, timeStr1) |
| 48 | timeStr2 := "2025-03-03T03:03:03.000000000Z" |
| 49 | created2, _ := time.Parse(time.RFC3339Nano, timeStr2) |
| 50 | image1 := imageInspect("image1", "foo:1", 12345, timeStr1) |
| 51 | image2 := imageInspect("image2", "bar:2", 67890, timeStr2) |
| 52 | api.EXPECT().ImageInspect(anyCancellableContext(), "foo:1").Return(client.ImageInspectResult{InspectResponse: image1}, nil).MaxTimes(2) |
| 53 | api.EXPECT().ImageInspect(anyCancellableContext(), "bar:2").Return(client.ImageInspectResult{InspectResponse: image2}, nil) |
| 54 | c1 := containerDetail("service1", "123", container.StateRunning, "foo:1") |
| 55 | c2 := containerDetail("service1", "456", container.StateRunning, "bar:2") |
| 56 | c2.Ports = []container.PortSummary{{PublicPort: 80, PrivatePort: 90, IP: netip.MustParseAddr("127.0.0.1")}} |
| 57 | c3 := containerDetail("service2", "789", container.StateExited, "foo:1") |
| 58 | api.EXPECT().ContainerList(t.Context(), listOpts).Return(client.ContainerListResult{ |
| 59 | Items: []container.Summary{c1, c2, c3}, |
| 60 | }, nil) |
| 61 | |
| 62 | images, err := tested.Images(t.Context(), strings.ToLower(testProject), compose.ImagesOptions{}) |
| 63 | |
| 64 | expected := map[string]compose.ImageSummary{ |
| 65 | "123": { |
| 66 | ID: "image1", |
| 67 | Repository: "foo", |
| 68 | Tag: "1", |
| 69 | Size: 12345, |
| 70 | Created: &created1, |
| 71 | }, |
| 72 | "456": { |
| 73 | ID: "image2", |
| 74 | Repository: "bar", |
| 75 | Tag: "2", |
| 76 | Size: 67890, |
| 77 | Created: &created2, |
| 78 | }, |
| 79 | "789": { |
| 80 | ID: "image1", |
| 81 | Repository: "foo", |
| 82 | Tag: "1", |
| 83 | Size: 12345, |
| 84 | Created: &created1, |
| 85 | }, |
| 86 | } |
| 87 | assert.NilError(t, err) |
| 88 | assert.DeepEqual(t, images, expected) |
| 89 | } |
| 90 | |
| 91 | func imageInspect(id string, imageReference string, size int64, created string) image.InspectResponse { |
nothing calls this directly
no test coverage detected