mirror of
https://github.com/containrrr/watchtower.git
synced 2026-03-09 14:12:36 +01:00
Introduce test cases for proposed dependency sorting
This commit is contained in:
parent
348f121a61
commit
d65e6cd96c
4 changed files with 175 additions and 9 deletions
|
|
@ -22,6 +22,8 @@ type TestData struct {
|
|||
TriedToRemoveImageCount int
|
||||
NameOfContainerToKeep string
|
||||
Containers []container.Container
|
||||
StopOrder []string
|
||||
RestartOrder []string
|
||||
}
|
||||
|
||||
// TriedToRemoveImage is a test helper function to check whether RemoveImageByID has been called
|
||||
|
|
@ -49,11 +51,13 @@ func (client MockClient) StopContainer(c container.Container, d time.Duration) e
|
|||
if c.Name() == client.TestData.NameOfContainerToKeep {
|
||||
return errors.New("tried to stop the instance we want to keep")
|
||||
}
|
||||
client.TestData.StopOrder = append(client.TestData.StopOrder, c.Name())
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartContainer is a mock method
|
||||
func (client MockClient) StartContainer(c container.Container) (string, error) {
|
||||
client.TestData.RestartOrder = append(client.TestData.RestartOrder, c.Name())
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// CreateMockContainer creates a container substitute valid for testing
|
||||
func CreateMockContainer(id string, name string, image string, created time.Time) container.Container {
|
||||
func CreateMockContainer(id string, name string, image string, created time.Time, depends []string) container.Container {
|
||||
content := types.ContainerJSON{
|
||||
ContainerJSONBase: &types.ContainerJSONBase{
|
||||
ID: id,
|
||||
|
|
@ -20,6 +20,15 @@ func CreateMockContainer(id string, name string, image string, created time.Time
|
|||
Labels: make(map[string]string),
|
||||
},
|
||||
}
|
||||
dependency_string := ""
|
||||
for ind, i := range depends {
|
||||
if ind == 0 {
|
||||
dependency_string += i;
|
||||
}else{
|
||||
dependency_string += "," + i;
|
||||
}
|
||||
}
|
||||
content.Config.Labels["com.centurylinklabs.watchtower.depends-on"] = dependency_string
|
||||
return *container.NewContainer(
|
||||
&content,
|
||||
&types.ImageInspect{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue