(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func TestPs(t *testing.T) { |
| 33 | mockCtrl := gomock.NewController(t) |
| 34 | defer mockCtrl.Finish() |
| 35 | |
| 36 | api, cli := prepareMocks(mockCtrl) |
| 37 | tested, err := NewComposeService(cli) |
| 38 | assert.NilError(t, err) |
| 39 | |
| 40 | listOpts := client.ContainerListOptions{ |
| 41 | Filters: projectFilter(strings.ToLower(testProject)).Add("label", compose.ConfigHashLabel, oneOffFilter(false)), |
| 42 | All: false, |
| 43 | } |
| 44 | c1, inspect1 := containerDetails("service1", "123", containerType.StateRunning, containerType.Healthy, 0) |
| 45 | c2, inspect2 := containerDetails("service1", "456", containerType.StateRunning, "", 0) |
| 46 | c2.Ports = []containerType.PortSummary{{PublicPort: 80, PrivatePort: 90, IP: netip.MustParseAddr("127.0.0.1")}} |
| 47 | c3, inspect3 := containerDetails("service2", "789", containerType.StateExited, "", 130) |
| 48 | api.EXPECT().ContainerList(t.Context(), listOpts).Return(client.ContainerListResult{ |
| 49 | Items: []containerType.Summary{c1, c2, c3}, |
| 50 | }, nil) |
| 51 | api.EXPECT().ContainerInspect(anyCancellableContext(), "123", gomock.Any()).Return(client.ContainerInspectResult{Container: inspect1}, nil) |
| 52 | api.EXPECT().ContainerInspect(anyCancellableContext(), "456", gomock.Any()).Return(client.ContainerInspectResult{Container: inspect2}, nil) |
| 53 | api.EXPECT().ContainerInspect(anyCancellableContext(), "789", gomock.Any()).Return(client.ContainerInspectResult{Container: inspect3}, nil) |
| 54 | |
| 55 | containers, err := tested.Ps(t.Context(), strings.ToLower(testProject), compose.PsOptions{}) |
| 56 | |
| 57 | expected := []compose.ContainerSummary{ |
| 58 | { |
| 59 | ID: "123", Name: "123", Names: []string{"/123"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", |
| 60 | State: containerType.StateRunning, |
| 61 | Health: containerType.Healthy, |
| 62 | Publishers: []compose.PortPublisher{}, |
| 63 | Labels: map[string]string{ |
| 64 | compose.ProjectLabel: strings.ToLower(testProject), |
| 65 | compose.ConfigFilesLabel: "/src/pkg/compose/testdata/compose.yaml", |
| 66 | compose.WorkingDirLabel: "/src/pkg/compose/testdata", |
| 67 | compose.ServiceLabel: "service1", |
| 68 | }, |
| 69 | }, |
| 70 | { |
| 71 | ID: "456", Name: "456", Names: []string{"/456"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", |
| 72 | State: containerType.StateRunning, |
| 73 | Publishers: []compose.PortPublisher{{URL: "127.0.0.1", TargetPort: 90, PublishedPort: 80}}, |
| 74 | Labels: map[string]string{ |
| 75 | compose.ProjectLabel: strings.ToLower(testProject), |
| 76 | compose.ConfigFilesLabel: "/src/pkg/compose/testdata/compose.yaml", |
| 77 | compose.WorkingDirLabel: "/src/pkg/compose/testdata", |
| 78 | compose.ServiceLabel: "service1", |
| 79 | }, |
| 80 | }, |
| 81 | { |
| 82 | ID: "789", Name: "789", Names: []string{"/789"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service2", |
| 83 | State: containerType.StateExited, |
| 84 | ExitCode: 130, |
| 85 | Publishers: []compose.PortPublisher{}, |
| 86 | Labels: map[string]string{ |
| 87 | compose.ProjectLabel: strings.ToLower(testProject), |
| 88 | compose.ConfigFilesLabel: "/src/pkg/compose/testdata/compose.yaml", |
| 89 | compose.WorkingDirLabel: "/src/pkg/compose/testdata", |
nothing calls this directly
no test coverage detected