|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
cli "github.com/docker/docker/client"
|
|
|
|
cli "github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MockClient is a mock that passes as a watchtower Client
|
|
|
|
type MockClient struct {
|
|
|
|
type MockClient struct {
|
|
|
|
TestData *TestData
|
|
|
|
TestData *TestData
|
|
|
|
api cli.CommonAPIClient
|
|
|
|
api cli.CommonAPIClient
|
|
|
@ -16,16 +17,19 @@ type MockClient struct {
|
|
|
|
removeVolumes bool
|
|
|
|
removeVolumes bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TestData is the data used to perform the test
|
|
|
|
type TestData struct {
|
|
|
|
type TestData struct {
|
|
|
|
TriedToRemoveImageCount int
|
|
|
|
TriedToRemoveImageCount int
|
|
|
|
NameOfContainerToKeep string
|
|
|
|
NameOfContainerToKeep string
|
|
|
|
Containers []container.Container
|
|
|
|
Containers []container.Container
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TriedToRemoveImage is a test helper function to check whether RemoveImageByID has been called
|
|
|
|
func (testdata *TestData) TriedToRemoveImage() bool {
|
|
|
|
func (testdata *TestData) TriedToRemoveImage() bool {
|
|
|
|
return testdata.TriedToRemoveImageCount > 0
|
|
|
|
return testdata.TriedToRemoveImageCount > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreateMockClient creates a mock watchtower Client for usage in tests
|
|
|
|
func CreateMockClient(data *TestData, api cli.CommonAPIClient, pullImages bool, removeVolumes bool) MockClient {
|
|
|
|
func CreateMockClient(data *TestData, api cli.CommonAPIClient, pullImages bool, removeVolumes bool) MockClient {
|
|
|
|
return MockClient {
|
|
|
|
return MockClient {
|
|
|
|
data,
|
|
|
|
data,
|
|
|
@ -35,37 +39,45 @@ func CreateMockClient(data *TestData, api cli.CommonAPIClient, pullImages bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ListContainers is a mock method returning the provided container testdata
|
|
|
|
func (client MockClient) ListContainers(f t.Filter) ([]container.Container, error) {
|
|
|
|
func (client MockClient) ListContainers(f t.Filter) ([]container.Container, error) {
|
|
|
|
return client.TestData.Containers, nil
|
|
|
|
return client.TestData.Containers, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StopContainer is a mock method
|
|
|
|
func (client MockClient) StopContainer(c container.Container, d time.Duration) error {
|
|
|
|
func (client MockClient) StopContainer(c container.Container, d time.Duration) error {
|
|
|
|
if c.Name() == client.TestData.NameOfContainerToKeep {
|
|
|
|
if c.Name() == client.TestData.NameOfContainerToKeep {
|
|
|
|
return errors.New("tried to stop the instance we want to keep")
|
|
|
|
return errors.New("tried to stop the instance we want to keep")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StartContainer is a mock method
|
|
|
|
func (client MockClient) StartContainer(c container.Container) (string, error) {
|
|
|
|
func (client MockClient) StartContainer(c container.Container) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RenameContainer is a mock method
|
|
|
|
func (client MockClient) RenameContainer(c container.Container, s string) error {
|
|
|
|
func (client MockClient) RenameContainer(c container.Container, s string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RemoveImageByID increments the TriedToRemoveImageCount on being called
|
|
|
|
func (client MockClient) RemoveImageByID(id string) error {
|
|
|
|
func (client MockClient) RemoveImageByID(id string) error {
|
|
|
|
client.TestData.TriedToRemoveImageCount++
|
|
|
|
client.TestData.TriedToRemoveImageCount++
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetContainer is a mock method
|
|
|
|
func (client MockClient) GetContainer(containerID string) (container.Container, error) {
|
|
|
|
func (client MockClient) GetContainer(containerID string) (container.Container, error) {
|
|
|
|
return container.Container{}, nil
|
|
|
|
return container.Container{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ExecuteCommand is a mock method
|
|
|
|
func (client MockClient) ExecuteCommand(containerID string, command string) error {
|
|
|
|
func (client MockClient) ExecuteCommand(containerID string, command string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsContainerStale is always true for the mock client
|
|
|
|
func (client MockClient) IsContainerStale(c container.Container) (bool, error) {
|
|
|
|
func (client MockClient) IsContainerStale(c container.Container) (bool, error) {
|
|
|
|
return true, nil
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|