From 250c3112b984c57c2dd34dcb61882b38a813cdfe Mon Sep 17 00:00:00 2001 From: IDOMATH Date: Wed, 29 May 2024 13:59:15 -0500 Subject: [PATCH] Fix: change append to use slice index in ps.go Signed-off-by: Blane Tschida --- pkg/compose/ps.go | 8 ++++---- pkg/compose/ps_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/compose/ps.go b/pkg/compose/ps.go index b4f619f66..93f5013ce 100644 --- a/pkg/compose/ps.go +++ b/pkg/compose/ps.go @@ -45,17 +45,17 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api for i, container := range containers { i, container := i, container eg.Go(func() error { - var publishers []api.PortPublisher + publishers := make([]api.PortPublisher, len(container.Ports)) sort.Slice(container.Ports, func(i, j int) bool { return container.Ports[i].PrivatePort < container.Ports[j].PrivatePort }) - for _, p := range container.Ports { - publishers = append(publishers, api.PortPublisher{ + for i, p := range container.Ports { + publishers[i] = api.PortPublisher{ URL: p.IP, TargetPort: int(p.PrivatePort), PublishedPort: int(p.PublicPort), Protocol: p.Type, - }) + } } inspect, err := s.apiClient().ContainerInspect(ctx, container.ID) diff --git a/pkg/compose/ps_test.go b/pkg/compose/ps_test.go index a8d21b24f..681200b76 100644 --- a/pkg/compose/ps_test.go +++ b/pkg/compose/ps_test.go @@ -56,7 +56,7 @@ func TestPs(t *testing.T) { expected := []compose.ContainerSummary{ {ID: "123", Name: "123", Names: []string{"/123"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", - State: "running", Health: "healthy", Publishers: nil, + State: "running", Health: "healthy", Publishers: []compose.PortPublisher{}, Labels: map[string]string{ compose.ProjectLabel: strings.ToLower(testProject), compose.ConfigFilesLabel: "/src/pkg/compose/testdata/compose.yaml", @@ -75,7 +75,7 @@ func TestPs(t *testing.T) { }, }, {ID: "789", Name: "789", Names: []string{"/789"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service2", - State: "exited", Health: "", ExitCode: 130, Publishers: nil, + State: "exited", Health: "", ExitCode: 130, Publishers: []compose.PortPublisher{}, Labels: map[string]string{ compose.ProjectLabel: strings.ToLower(testProject), compose.ConfigFilesLabel: "/src/pkg/compose/testdata/compose.yaml",