Skip to content

Commit

Permalink
Fix: change append to use slice index in ps.go
Browse files Browse the repository at this point in the history
Signed-off-by: Blane Tschida <btdothemath@gmail.com>
  • Loading branch information
IDOMATH authored and ndeloof committed May 30, 2024
1 parent 495a087 commit 250c311
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 250c311

Please sign in to comment.