From 14e6ff1c1f4a042a5c7e56302605f61c4fa57856 Mon Sep 17 00:00:00 2001 From: lpessoa Date: Tue, 26 Oct 2021 13:52:24 -0300 Subject: [PATCH 1/9] Use sort containers by state by default Implements #224 Use sort containers by state as default behavior Legacy sort by name behavior can be set using a user config setting. `sortContainersByName` is false by default. --- pkg/commands/docker.go | 17 ++++++ pkg/commands/os_default_platform.go | 1 + pkg/config/app_config.go | 6 +++ pkg/config/config_default_platform.go | 1 + pkg/gui/containers_panel.go | 1 + pkg/i18n/english.go | 74 ++++++++++++++------------- 6 files changed, 64 insertions(+), 36 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index ce228705..98ac4825 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -243,6 +243,7 @@ func (c *DockerCommand) RefreshContainersAndServices() error { c.Containers = containers c.Services = services c.DisplayContainers = c.filterOutExited(displayContainers) + c.DisplayContainers = c.sortedContainers(c.DisplayContainers) return nil } @@ -274,6 +275,22 @@ func (c *DockerCommand) filterOutExited(containers []*Container) []*Container { return toReturn } +// sortedContainers returns containers sorted by state if c.SortContainersByState is true (follows 1- running, 2- exited, 3- created) +// and sorted by name if c.SortContainersByState is false +func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { + if !c.Config.UserConfig.Gui.SortContainersByName { + sort.Slice(containers, func(i, j int) bool { + states := map[string]int{ + "running": 1, + "exited": 2, + "created": 3, + } + return states[containers[i].Container.State] < states[containers[j].Container.State] + }) + } + return containers +} + // obtainStandaloneContainers returns standalone containers. Standalone containers are containers which are either one-off containers, or whose service is not part of this docker-compose context func (c *DockerCommand) obtainStandaloneContainers(containers []*Container, services []*Service) []*Container { standaloneContainers := []*Container{} diff --git a/pkg/commands/os_default_platform.go b/pkg/commands/os_default_platform.go index 067bb5e6..7d289796 100644 --- a/pkg/commands/os_default_platform.go +++ b/pkg/commands/os_default_platform.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package commands diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 00f62208..2c984087 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -112,6 +112,11 @@ type GuiConfig struct { // WrapMainPanel determines whether we use word wrap on the main panel WrapMainPanel bool `yaml:"wrapMainPanel,omitempty"` + + // SortContainersByName determines if containers should be sorted by name. + // By default, containers are now sorted by status. This setting allows users to + // use legacy behaviour instead. + SortContainersByName bool `yaml:"sortContainersByName, omitempty"` } // CommandTemplatesConfig determines what commands actually get called when we @@ -325,6 +330,7 @@ func GetDefaultConfig() UserConfig { ShowAllContainers: false, ReturnImmediately: false, WrapMainPanel: false, + SortContainersByName: false, }, Reporting: "undetermined", ConfirmOnQuit: false, diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go index e9e2f63b..fd1defdc 100644 --- a/pkg/config/config_default_platform.go +++ b/pkg/config/config_default_platform.go @@ -1,3 +1,4 @@ +//go:build !windows && !linux // +build !windows,!linux package config diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 7b8a172e..0b6c04a2 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -618,3 +618,4 @@ func (gui *Gui) openContainerInBrowser(container *commands.Container) error { link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort) return gui.OSCommand.OpenLink(link) } + diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 81aaf0c9..95242c9b 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -84,6 +84,7 @@ type TranslationSet struct { RunCustomCommand string ViewBulkCommands string OpenInBrowser string + SortContainersByState string LogsTitle string ConfigTitle string @@ -118,42 +119,43 @@ func englishSet() TranslationSet { Donate: "Donate", Confirm: "Confirm", - Return: "return", - FocusMain: "focus main panel", - Navigate: "navigate", - Execute: "execute", - Close: "close", - Menu: "menu", - Scroll: "scroll", - OpenConfig: "open lazydocker config", - EditConfig: "edit lazydocker config", - Cancel: "cancel", - Remove: "remove", - HideStopped: "Hide/Show stopped containers", - ForceRemove: "force remove", - RemoveWithVolumes: "remove with volumes", - RemoveService: "remove containers", - Stop: "stop", - Restart: "restart", - Rebuild: "rebuild", - Recreate: "recreate", - PreviousContext: "previous tab", - NextContext: "next tab", - Attach: "attach", - ViewLogs: "view logs", - RemoveImage: "remove image", - RemoveVolume: "remove volume", - RemoveWithoutPrune: "remove without deleting untagged parents", - PruneContainers: "prune exited containers", - PruneVolumes: "prune unused volumes", - PruneImages: "prune unused images", - StopAllContainers: "stop all containers", - RemoveAllContainers: "remove all containers (forced)", - ViewRestartOptions: "view restart options", - ExecShell: "exec shell", - RunCustomCommand: "run predefined custom command", - ViewBulkCommands: "view bulk commands", - OpenInBrowser: "open in browser (first port is http)", + Return: "return", + FocusMain: "focus main panel", + Navigate: "navigate", + Execute: "execute", + Close: "close", + Menu: "menu", + Scroll: "scroll", + OpenConfig: "open lazydocker config", + EditConfig: "edit lazydocker config", + Cancel: "cancel", + Remove: "remove", + HideStopped: "Hide/Show stopped containers", + ForceRemove: "force remove", + RemoveWithVolumes: "remove with volumes", + RemoveService: "remove containers", + Stop: "stop", + Restart: "restart", + Rebuild: "rebuild", + Recreate: "recreate", + PreviousContext: "previous tab", + NextContext: "next tab", + Attach: "attach", + ViewLogs: "view logs", + RemoveImage: "remove image", + RemoveVolume: "remove volume", + RemoveWithoutPrune: "remove without deleting untagged parents", + PruneContainers: "prune exited containers", + PruneVolumes: "prune unused volumes", + PruneImages: "prune unused images", + StopAllContainers: "stop all containers", + RemoveAllContainers: "remove all containers (forced)", + ViewRestartOptions: "view restart options", + ExecShell: "exec shell", + RunCustomCommand: "run predefined custom command", + ViewBulkCommands: "view bulk commands", + OpenInBrowser: "open in browser (first port is http)", + SortContainersByState: "sort containers by state", AnonymousReportingTitle: "Help make lazydocker better", AnonymousReportingPrompt: "Would you like to enable anonymous reporting data to help improve lazydocker?", From 1681d839fa2818031b2246db772e4ffdf684a20b Mon Sep 17 00:00:00 2001 From: lpessoa Date: Fri, 10 Dec 2021 16:39:42 +0000 Subject: [PATCH 2/9] Fixing gofmt errors --- pkg/config/app_config.go | 8 ++++---- pkg/gui/containers_panel.go | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 2c984087..e0988f78 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -20,7 +20,7 @@ import ( "time" "github.com/OpenPeeDeeP/xdg" - yaml "github.com/jesseduffield/yaml" + "github.com/jesseduffield/yaml" ) // UserConfig holds all of the user-configurable options @@ -327,9 +327,9 @@ func GetDefaultConfig() UserConfig { InactiveBorderColor: []string{"default"}, OptionsTextColor: []string{"blue"}, }, - ShowAllContainers: false, - ReturnImmediately: false, - WrapMainPanel: false, + ShowAllContainers: false, + ReturnImmediately: false, + WrapMainPanel: false, SortContainersByName: false, }, Reporting: "undetermined", diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 0b6c04a2..7b8a172e 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -618,4 +618,3 @@ func (gui *Gui) openContainerInBrowser(container *commands.Container) error { link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort) return gui.OSCommand.OpenLink(link) } - From db288a1727284f986608b13285f6d0dc760b71e3 Mon Sep 17 00:00:00 2001 From: lpessoa Date: Fri, 10 Dec 2021 17:12:52 +0000 Subject: [PATCH 3/9] Updated sortedContainer slice ordering --- pkg/commands/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 98ac4825..58374445 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -285,7 +285,7 @@ func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { "exited": 2, "created": 3, } - return states[containers[i].Container.State] < states[containers[j].Container.State] + return states[containers[i].Container.State] > states[containers[j].Container.State] }) } return containers From 615ce6536bdbb8b99418cf6562abca887803cea8 Mon Sep 17 00:00:00 2001 From: lpessoa Date: Mon, 3 Jan 2022 22:52:51 +0000 Subject: [PATCH 4/9] adding tests for legacy and new default sort for containers --- pkg/commands/docker.go | 2 +- pkg/commands/sort_container_test.go | 155 ++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 pkg/commands/sort_container_test.go diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 58374445..98ac4825 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -285,7 +285,7 @@ func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { "exited": 2, "created": 3, } - return states[containers[i].Container.State] > states[containers[j].Container.State] + return states[containers[i].Container.State] < states[containers[j].Container.State] }) } return containers diff --git a/pkg/commands/sort_container_test.go b/pkg/commands/sort_container_test.go new file mode 100644 index 00000000..d92fcafd --- /dev/null +++ b/pkg/commands/sort_container_test.go @@ -0,0 +1,155 @@ +package commands + +import ( + "github.com/docker/docker/api/types" + "github.com/jesseduffield/lazydocker/pkg/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func sampleContainers(userConfig *config.AppConfig) []*Container { + return []*Container{ + { + ID: "1", + Container: types.Container{ + State: "exited", + }, + Config: userConfig, + }, + { + ID: "2", + Container: types.Container{ + State: "running", + }, + Config: userConfig, + }, + { + ID: "3", + Container: types.Container{ + State: "running", + }, + Config: userConfig, + }, + { + ID: "4", + Container: types.Container{ + State: "created", + }, + Config: userConfig, + }, + } +} + +func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { + return []*Container{ + { + ID: "2", + Container: types.Container{ + State: "running", + }, + Config: appConfig, + }, + { + ID: "3", + Container: types.Container{ + State: "running", + }, + Config: appConfig, + }, + { + ID: "1", + Container: types.Container{ + State: "exited", + }, + Config: appConfig, + }, + { + ID: "4", + Container: types.Container{ + State: "created", + }, + Config: appConfig, + }, + } +} + +func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { + return []*Container{ + { + ID: "1", + Container: types.Container{ + State: "exited", + }, + Config: appConfig, + }, + { + ID: "2", + Container: types.Container{ + State: "running", + }, + Config: appConfig, + }, + { + ID: "3", + Container: types.Container{ + State: "running", + }, + Config: appConfig, + }, + { + ID: "4", + Container: types.Container{ + State: "created", + }, + Config: appConfig, + }, + } +} + +func TestSortContainers(t *testing.T) { + appConfig := NewDummyAppConfig() + appConfig.UserConfig = &config.UserConfig{ + Gui: config.GuiConfig{ + SortContainersByName: false, + }, + } + command := &DockerCommand{ + Config: appConfig, + } + + containers := sampleContainers(appConfig) + + sorted := expectedPerStatusContainers(appConfig) + + ct := command.sortedContainers(containers) + + assert.Equal(t, len(ct), len(sorted)) + + for i := 0; i < len(ct); i++ { + assert.Equal(t, ct[i].Container.State, sorted[i].Container.State) + assert.Equal(t, ct[i].Container.ID, sorted[i].Container.ID) + } +} + +func TestLegacySortedContainers(t *testing.T) { + appConfig := NewDummyAppConfig() + appConfig.UserConfig = &config.UserConfig{ + Gui: config.GuiConfig{ + SortContainersByName: true, + }, + } + command := &DockerCommand{ + Config: appConfig, + } + + containers := sampleContainers(appConfig) + + sorted := expectedLegacySortedContainers(appConfig) + + ct := command.sortedContainers(containers) + + for i := 0; i < len(ct); i++ { + assert.Equal(t, sorted[i].Container.State, ct[i].Container.State,) + assert.Equal(t, sorted[i].Container.ID, ct[i].Container.ID) + } +} From e585277c8924e4cbeb217af939a10d3c542e0ccd Mon Sep 17 00:00:00 2001 From: lpessoa Date: Mon, 3 Jan 2022 22:55:02 +0000 Subject: [PATCH 5/9] fixing gofmt errors --- pkg/commands/sort_container_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/sort_container_test.go b/pkg/commands/sort_container_test.go index d92fcafd..1003f684 100644 --- a/pkg/commands/sort_container_test.go +++ b/pkg/commands/sort_container_test.go @@ -149,7 +149,7 @@ func TestLegacySortedContainers(t *testing.T) { ct := command.sortedContainers(containers) for i := 0; i < len(ct); i++ { - assert.Equal(t, sorted[i].Container.State, ct[i].Container.State,) + assert.Equal(t, sorted[i].Container.State, ct[i].Container.State) assert.Equal(t, sorted[i].Container.ID, ct[i].Container.ID) } } From 0279534811f62f14307f21f0d60bb979c5ce394f Mon Sep 17 00:00:00 2001 From: lpessoa Date: Tue, 11 Jan 2022 21:10:05 +0000 Subject: [PATCH 6/9] moved states outside Slice call --- pkg/commands/docker.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 98ac4825..de340929 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -279,12 +279,12 @@ func (c *DockerCommand) filterOutExited(containers []*Container) []*Container { // and sorted by name if c.SortContainersByState is false func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { if !c.Config.UserConfig.Gui.SortContainersByName { + states := map[string]int{ + "running": 1, + "exited": 2, + "created": 3, + } sort.Slice(containers, func(i, j int) bool { - states := map[string]int{ - "running": 1, - "exited": 2, - "created": 3, - } return states[containers[i].Container.State] < states[containers[j].Container.State] }) } From a78b5af56bf3e37653ee1c29d515657d9e1614ef Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 12 Jan 2022 23:24:15 +1100 Subject: [PATCH 7/9] fix crash --- pkg/config/app_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index e0988f78..9d063d83 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -116,7 +116,7 @@ type GuiConfig struct { // SortContainersByName determines if containers should be sorted by name. // By default, containers are now sorted by status. This setting allows users to // use legacy behaviour instead. - SortContainersByName bool `yaml:"sortContainersByName, omitempty"` + SortContainersByName bool `yaml:"sortContainersByName,omitempty"` } // CommandTemplatesConfig determines what commands actually get called when we From cbacd32a686a692bbc393e344070bc1a07e432b8 Mon Sep 17 00:00:00 2001 From: lpessoa Date: Mon, 17 Jan 2022 19:58:51 -0300 Subject: [PATCH 8/9] Changing SortContainersByName to LegacySortContainers LegacySortContainers will default to legacy behaviour. New behaviour will sort by status followed by name. --- pkg/commands/docker.go | 7 ++++++- pkg/commands/sort_container_test.go | 28 ++++++++++++++++++++++------ pkg/config/app_config.go | 6 +++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index de340929..d15df440 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -278,13 +278,18 @@ func (c *DockerCommand) filterOutExited(containers []*Container) []*Container { // sortedContainers returns containers sorted by state if c.SortContainersByState is true (follows 1- running, 2- exited, 3- created) // and sorted by name if c.SortContainersByState is false func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { - if !c.Config.UserConfig.Gui.SortContainersByName { + if !c.Config.UserConfig.Gui.LegacySortContainers { states := map[string]int{ "running": 1, "exited": 2, "created": 3, } sort.Slice(containers, func(i, j int) bool { + stateLeft := states[containers[i].Container.State] + stateRight := states[containers[j].Container.State] + if stateLeft == stateRight { + return containers[i].Name < containers[j].Name + } return states[containers[i].Container.State] < states[containers[j].Container.State] }) } diff --git a/pkg/commands/sort_container_test.go b/pkg/commands/sort_container_test.go index 1003f684..08197cd3 100644 --- a/pkg/commands/sort_container_test.go +++ b/pkg/commands/sort_container_test.go @@ -11,6 +11,7 @@ func sampleContainers(userConfig *config.AppConfig) []*Container { return []*Container{ { ID: "1", + Name:"1", Container: types.Container{ State: "exited", }, @@ -18,6 +19,7 @@ func sampleContainers(userConfig *config.AppConfig) []*Container { }, { ID: "2", + Name:"2", Container: types.Container{ State: "running", }, @@ -25,6 +27,7 @@ func sampleContainers(userConfig *config.AppConfig) []*Container { }, { ID: "3", + Name:"3", Container: types.Container{ State: "running", }, @@ -32,6 +35,7 @@ func sampleContainers(userConfig *config.AppConfig) []*Container { }, { ID: "4", + Name:"4", Container: types.Container{ State: "created", }, @@ -44,6 +48,7 @@ func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { return []*Container{ { ID: "2", + Name:"2", Container: types.Container{ State: "running", }, @@ -51,6 +56,7 @@ func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { }, { ID: "3", + Name:"3", Container: types.Container{ State: "running", }, @@ -58,6 +64,7 @@ func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { }, { ID: "1", + Name:"1", Container: types.Container{ State: "exited", }, @@ -65,6 +72,7 @@ func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { }, { ID: "4", + Name:"4", Container: types.Container{ State: "created", }, @@ -77,6 +85,7 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { return []*Container{ { ID: "1", + Name:"1", Container: types.Container{ State: "exited", }, @@ -84,6 +93,7 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { }, { ID: "2", + Name:"2", Container: types.Container{ State: "running", }, @@ -91,6 +101,7 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { }, { ID: "3", + Name:"3", Container: types.Container{ State: "running", }, @@ -98,6 +109,7 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { }, { ID: "4", + Name:"4", Container: types.Container{ State: "created", }, @@ -106,11 +118,17 @@ func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { } } +func assertEqualContainers(t *testing.T, left *Container, right *Container) { + assert.Equal(t, left.Container.State, right.Container.State) + assert.Equal(t, left.Container.ID, right.Container.ID) + assert.Equal(t, left.Name, right.Name) +} + func TestSortContainers(t *testing.T) { appConfig := NewDummyAppConfig() appConfig.UserConfig = &config.UserConfig{ Gui: config.GuiConfig{ - SortContainersByName: false, + LegacySortContainers: false, }, } command := &DockerCommand{ @@ -126,8 +144,7 @@ func TestSortContainers(t *testing.T) { assert.Equal(t, len(ct), len(sorted)) for i := 0; i < len(ct); i++ { - assert.Equal(t, ct[i].Container.State, sorted[i].Container.State) - assert.Equal(t, ct[i].Container.ID, sorted[i].Container.ID) + assertEqualContainers(t, sorted[i], ct[i]) } } @@ -135,7 +152,7 @@ func TestLegacySortedContainers(t *testing.T) { appConfig := NewDummyAppConfig() appConfig.UserConfig = &config.UserConfig{ Gui: config.GuiConfig{ - SortContainersByName: true, + LegacySortContainers: true, }, } command := &DockerCommand{ @@ -149,7 +166,6 @@ func TestLegacySortedContainers(t *testing.T) { ct := command.sortedContainers(containers) for i := 0; i < len(ct); i++ { - assert.Equal(t, sorted[i].Container.State, ct[i].Container.State) - assert.Equal(t, sorted[i].Container.ID, ct[i].Container.ID) + assertEqualContainers(t, sorted[i], ct[i]) } } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 9d063d83..cd54367d 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -113,10 +113,10 @@ type GuiConfig struct { // WrapMainPanel determines whether we use word wrap on the main panel WrapMainPanel bool `yaml:"wrapMainPanel,omitempty"` - // SortContainersByName determines if containers should be sorted by name. + // LegacySortContainers determines if containers should be sorted using legacy approach. // By default, containers are now sorted by status. This setting allows users to // use legacy behaviour instead. - SortContainersByName bool `yaml:"sortContainersByName,omitempty"` + LegacySortContainers bool `yaml:"legacySortContainers,omitempty"` } // CommandTemplatesConfig determines what commands actually get called when we @@ -330,7 +330,7 @@ func GetDefaultConfig() UserConfig { ShowAllContainers: false, ReturnImmediately: false, WrapMainPanel: false, - SortContainersByName: false, + LegacySortContainers: false, }, Reporting: "undetermined", ConfirmOnQuit: false, From 62eeaac4376bbf59e1a18d5e18884e9a3885f1cf Mon Sep 17 00:00:00 2001 From: lpessoa Date: Mon, 17 Jan 2022 21:24:02 -0300 Subject: [PATCH 9/9] Fixed code format issues --- pkg/commands/docker.go | 2 +- pkg/commands/sort_container_test.go | 48 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index d15df440..b23db8bf 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -287,7 +287,7 @@ func (c *DockerCommand) sortedContainers(containers []*Container) []*Container { sort.Slice(containers, func(i, j int) bool { stateLeft := states[containers[i].Container.State] stateRight := states[containers[j].Container.State] - if stateLeft == stateRight { + if stateLeft == stateRight { return containers[i].Name < containers[j].Name } return states[containers[i].Container.State] < states[containers[j].Container.State] diff --git a/pkg/commands/sort_container_test.go b/pkg/commands/sort_container_test.go index 08197cd3..5a8cb2a1 100644 --- a/pkg/commands/sort_container_test.go +++ b/pkg/commands/sort_container_test.go @@ -10,32 +10,32 @@ import ( func sampleContainers(userConfig *config.AppConfig) []*Container { return []*Container{ { - ID: "1", - Name:"1", + ID: "1", + Name: "1", Container: types.Container{ State: "exited", }, Config: userConfig, }, { - ID: "2", - Name:"2", + ID: "2", + Name: "2", Container: types.Container{ State: "running", }, Config: userConfig, }, { - ID: "3", - Name:"3", + ID: "3", + Name: "3", Container: types.Container{ State: "running", }, Config: userConfig, }, { - ID: "4", - Name:"4", + ID: "4", + Name: "4", Container: types.Container{ State: "created", }, @@ -47,32 +47,32 @@ func sampleContainers(userConfig *config.AppConfig) []*Container { func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { return []*Container{ { - ID: "2", - Name:"2", + ID: "2", + Name: "2", Container: types.Container{ State: "running", }, Config: appConfig, }, { - ID: "3", - Name:"3", + ID: "3", + Name: "3", Container: types.Container{ State: "running", }, Config: appConfig, }, { - ID: "1", - Name:"1", + ID: "1", + Name: "1", Container: types.Container{ State: "exited", }, Config: appConfig, }, { - ID: "4", - Name:"4", + ID: "4", + Name: "4", Container: types.Container{ State: "created", }, @@ -84,32 +84,32 @@ func expectedPerStatusContainers(appConfig *config.AppConfig) []*Container { func expectedLegacySortedContainers(appConfig *config.AppConfig) []*Container { return []*Container{ { - ID: "1", - Name:"1", + ID: "1", + Name: "1", Container: types.Container{ State: "exited", }, Config: appConfig, }, { - ID: "2", - Name:"2", + ID: "2", + Name: "2", Container: types.Container{ State: "running", }, Config: appConfig, }, { - ID: "3", - Name:"3", + ID: "3", + Name: "3", Container: types.Container{ State: "running", }, Config: appConfig, }, { - ID: "4", - Name:"4", + ID: "4", + Name: "4", Container: types.Container{ State: "created", },