mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
Refactor Client interface
This commit is contained in:
parent
cc1efc20e2
commit
a8dec129f5
6 changed files with 164 additions and 162 deletions
|
@ -19,7 +19,7 @@ func CheckPrereqs(client container.Client) error {
|
|||
|
||||
// Iterate over all containers execept the last one
|
||||
for _, c := range containers[0 : len(containers)-1] {
|
||||
client.Stop(c, 60)
|
||||
client.StopContainer(c, 60)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ func TestCheckPrereqs_Success(t *testing.T) {
|
|||
cs := []container.Container{c1, c2}
|
||||
|
||||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.ContainerFilter")).Return(cs, nil)
|
||||
client.On("Stop", c2, time.Duration(60)).Return(nil)
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, nil)
|
||||
client.On("StopContainer", c2, time.Duration(60)).Return(nil)
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
|
||||
|
@ -59,7 +59,7 @@ func TestCheckPrereqs_OnlyOneContainer(t *testing.T) {
|
|||
cs := []container.Container{c1}
|
||||
|
||||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.ContainerFilter")).Return(cs, nil)
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, nil)
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func TestCheckPrereqs_ListError(t *testing.T) {
|
|||
cs := []container.Container{}
|
||||
|
||||
client := &mockclient.MockClient{}
|
||||
client.On("ListContainers", mock.AnythingOfType("container.ContainerFilter")).Return(cs, errors.New("oops"))
|
||||
client.On("ListContainers", mock.AnythingOfType("container.Filter")).Return(cs, errors.New("oops"))
|
||||
|
||||
err := CheckPrereqs(client)
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ func Update(client container.Client) error {
|
|||
return err
|
||||
}
|
||||
|
||||
for i := range containers {
|
||||
if err := client.RefreshImage(&containers[i]); err != nil {
|
||||
for i, container := range containers {
|
||||
stale, err := client.IsContainerStale(container)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
containers[i].Stale = stale
|
||||
}
|
||||
|
||||
containers, err = container.SortByDependencies(containers)
|
||||
|
@ -40,7 +42,7 @@ func Update(client container.Client) error {
|
|||
}
|
||||
|
||||
if container.Stale {
|
||||
if err := client.Stop(container, 10); err != nil {
|
||||
if err := client.StopContainer(container, 10); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -54,12 +56,12 @@ func Update(client container.Client) error {
|
|||
// from re-using the same container name so we first rename the current
|
||||
// instance so that the new one can adopt the old name.
|
||||
if container.IsWatchtower() {
|
||||
if err := client.Rename(container, randName()); err != nil {
|
||||
if err := client.RenameContainer(container, randName()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := client.Start(container); err != nil {
|
||||
if err := client.StartContainer(container); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue