mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Support for --cleanup flag
The --cleanup flag will cause watchtower to automatically remove the old image after a container is restart with a new image.
This commit is contained in:
parent
b8ba80df2d
commit
dd80aa4a0d
10 changed files with 117 additions and 7 deletions
|
@ -38,7 +38,40 @@ func TestCheckPrereqs_Success(t *testing.T) {
|
|||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, nil)
|
||||
client.On("StopContainer", c2, time.Duration(60)).Return(nil)
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
err := CheckPrereqs(client, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
client.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestCheckPrereqs_WithCleanup(t *testing.T) {
|
||||
cc := &dockerclient.ContainerConfig{
|
||||
Labels: map[string]string{"com.centurylinklabs.watchtower": "true"},
|
||||
}
|
||||
c1 := *container.NewContainer(
|
||||
&dockerclient.ContainerInfo{
|
||||
Name: "c1",
|
||||
Config: cc,
|
||||
Created: "2015-07-01T12:00:01.000000000Z",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
c2 := *container.NewContainer(
|
||||
&dockerclient.ContainerInfo{
|
||||
Name: "c2",
|
||||
Config: cc,
|
||||
Created: "2015-07-01T12:00:00.000000000Z",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
cs := []container.Container{c1, c2}
|
||||
|
||||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, nil)
|
||||
client.On("StopContainer", c2, time.Duration(60)).Return(nil)
|
||||
client.On("RemoveImage", c2).Return(nil)
|
||||
|
||||
err := CheckPrereqs(client, true)
|
||||
|
||||
assert.NoError(t, err)
|
||||
client.AssertExpectations(t)
|
||||
|
@ -61,7 +94,7 @@ func TestCheckPrereqs_OnlyOneContainer(t *testing.T) {
|
|||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, nil)
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
err := CheckPrereqs(client, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
client.AssertExpectations(t)
|
||||
|
@ -73,7 +106,7 @@ func TestCheckPrereqs_ListError(t *testing.T) {
|
|||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, errors.New("oops"))
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
err := CheckPrereqs(client, false)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.EqualError(t, err, "oops")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue