mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-02 11:07:26 +01:00
added --showAll flag that will show all containers (default: false) (#109)
This commit is contained in:
committed by
Amir Raminfar
parent
197c2cc87b
commit
b356ffcd68
@@ -30,7 +30,7 @@ type dockerProxy interface {
|
||||
|
||||
// Client is a proxy around the docker client
|
||||
type Client interface {
|
||||
ListContainers() ([]Container, error)
|
||||
ListContainers(showAll bool) ([]Container, error)
|
||||
FindContainer(string) (Container, error)
|
||||
ContainerLogs(context.Context, string, int) (<-chan string, <-chan error)
|
||||
Events(context.Context) (<-chan events.Message, <-chan error)
|
||||
@@ -61,7 +61,7 @@ func NewClientWithFilters(f map[string]string) Client {
|
||||
|
||||
func (d *dockerClient) FindContainer(id string) (Container, error) {
|
||||
var container Container
|
||||
containers, err := d.ListContainers()
|
||||
containers, err := d.ListContainers(true)
|
||||
if err != nil {
|
||||
return container, err
|
||||
}
|
||||
@@ -81,9 +81,10 @@ func (d *dockerClient) FindContainer(id string) (Container, error) {
|
||||
return container, nil
|
||||
}
|
||||
|
||||
func (d *dockerClient) ListContainers() ([]Container, error) {
|
||||
func (d *dockerClient) ListContainers(showAll bool) ([]Container, error) {
|
||||
containerListOptions := types.ContainerListOptions{
|
||||
Filters: d.filters,
|
||||
All: showAll,
|
||||
}
|
||||
list, err := d.cli.ContainerList(context.Background(), containerListOptions)
|
||||
if err != nil {
|
||||
|
||||
@@ -44,7 +44,7 @@ func Test_dockerClient_ListContainers_null(t *testing.T) {
|
||||
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, nil)
|
||||
client := &dockerClient{proxy, filters.NewArgs()}
|
||||
|
||||
list, err := client.ListContainers()
|
||||
list, err := client.ListContainers(true)
|
||||
assert.Empty(t, list, "list should be empty")
|
||||
require.NoError(t, err, "error should not return an error.")
|
||||
|
||||
@@ -56,7 +56,7 @@ func Test_dockerClient_ListContainers_error(t *testing.T) {
|
||||
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(nil, errors.New("test"))
|
||||
client := &dockerClient{proxy, filters.NewArgs()}
|
||||
|
||||
list, err := client.ListContainers()
|
||||
list, err := client.ListContainers(true)
|
||||
assert.Nil(t, list, "list should be nil")
|
||||
require.Error(t, err, "test.")
|
||||
|
||||
@@ -79,7 +79,7 @@ func Test_dockerClient_ListContainers_happy(t *testing.T) {
|
||||
proxy.On("ContainerList", mock.Anything, mock.Anything).Return(containers, nil)
|
||||
client := &dockerClient{proxy, filters.NewArgs()}
|
||||
|
||||
list, err := client.ListContainers()
|
||||
list, err := client.ListContainers(true)
|
||||
require.NoError(t, err, "error should not return an error.")
|
||||
|
||||
assert.Equal(t, list, []Container{
|
||||
|
||||
Reference in New Issue
Block a user