fix: correctly handle non-stale restarts (#1220)

This commit is contained in:
nils måsén 2022-04-18 19:36:38 +02:00 committed by GitHub
parent d12ce7ce79
commit e9c83af533
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 166 additions and 93 deletions

View file

@ -3,9 +3,10 @@ package mocks
import (
"errors"
"fmt"
"github.com/containrrr/watchtower/pkg/container"
"time"
"github.com/containrrr/watchtower/pkg/container"
t "github.com/containrrr/watchtower/pkg/types"
)
@ -21,6 +22,7 @@ type TestData struct {
TriedToRemoveImageCount int
NameOfContainerToKeep string
Containers []container.Container
Staleness map[string]bool
}
// TriedToRemoveImage is a test helper function to check whether RemoveImageByID has been called
@ -85,9 +87,13 @@ func (client MockClient) ExecuteCommand(_ t.ContainerID, command string, _ int)
}
}
// IsContainerStale is always true for the mock client
func (client MockClient) IsContainerStale(_ container.Container) (bool, t.ImageID, error) {
return true, "", nil
// IsContainerStale is true if not explicitly stated in TestData for the mock client
func (client MockClient) IsContainerStale(cont container.Container) (bool, t.ImageID, error) {
stale, found := client.TestData.Staleness[cont.Name()]
if !found {
stale = true
}
return stale, "", nil
}
// WarnOnHeadPullFailed is always true for the mock client