add tests for check action, resolve wt cleanup bug (#284)

add unit tests for the check action to allow for some
refactoring and bug fixing without having to worry about
breaking stuff.

resolve watchtower cleanup bug by adding an initial 1 second sleep
in the check action. without the sleep, the docker client returns an
empty array, which is why we were left with two watchtowers.
This commit is contained in:
Simon Aronsson 2019-04-20 16:44:41 +02:00 committed by GitHub
parent 90bd4a1e3e
commit 46ffa16ee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 239 additions and 20 deletions

View file

@ -4,7 +4,7 @@ import (
"fmt"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
"github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
)
@ -102,9 +102,7 @@ func (c Container) Links() []string {
// identified by the presence of the "com.centurylinklabs.watchtower" label in
// the container metadata.
func (c Container) IsWatchtower() bool {
log.Debugf("Checking if %s is a watchtower instance.", c.Name())
wasWatchtower := ContainsWatchtowerLabel(c.containerInfo.Config.Labels)
return wasWatchtower
return ContainsWatchtowerLabel(c.containerInfo.Config.Labels)
}
// StopSignal returns the custom stop signal (if any) that is encoded in the
@ -189,4 +187,4 @@ func (c Container) hostConfig() *dockercontainer.HostConfig {
func ContainsWatchtowerLabel(labels map[string]string) bool {
val, ok := labels[watchtowerLabel]
return ok && val == "true"
}
}