|
|
@ -5,12 +5,7 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/containrrr/watchtower/internal/actions"
|
|
|
|
"github.com/containrrr/watchtower/internal/actions"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/containrrr/watchtower/pkg/container"
|
|
|
|
"github.com/containrrr/watchtower/pkg/container"
|
|
|
|
"github.com/containrrr/watchtower/pkg/container/mocks"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
|
|
|
|
cli "github.com/docker/docker/client"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
. "github.com/containrrr/watchtower/internal/actions/mocks"
|
|
|
|
. "github.com/containrrr/watchtower/internal/actions/mocks"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
@ -23,51 +18,42 @@ func TestActions(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var _ = Describe("the actions package", func() {
|
|
|
|
var _ = Describe("the actions package", func() {
|
|
|
|
var dockerClient cli.CommonAPIClient
|
|
|
|
|
|
|
|
var client MockClient
|
|
|
|
|
|
|
|
BeforeSuite(func() {
|
|
|
|
|
|
|
|
server := mocks.NewMockAPIServer()
|
|
|
|
|
|
|
|
dockerClient, _ = cli.NewClientWithOpts(
|
|
|
|
|
|
|
|
cli.WithHost(server.URL),
|
|
|
|
|
|
|
|
cli.WithHTTPClient(server.Client()))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
|
|
|
|
pullImages := false
|
|
|
|
|
|
|
|
removeVolumes := false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = CreateMockClient(
|
|
|
|
|
|
|
|
&TestData{},
|
|
|
|
|
|
|
|
dockerClient,
|
|
|
|
|
|
|
|
pullImages,
|
|
|
|
|
|
|
|
removeVolumes,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Describe("the check prerequisites method", func() {
|
|
|
|
Describe("the check prerequisites method", func() {
|
|
|
|
When("given an empty array", func() {
|
|
|
|
When("given an empty array", func() {
|
|
|
|
It("should not do anything", func() {
|
|
|
|
It("should not do anything", func() {
|
|
|
|
client.TestData.Containers = []container.Container{}
|
|
|
|
client := CreateMockClient(
|
|
|
|
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
|
|
|
|
&TestData{},
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// pullImages:
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
// removeVolumes:
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
When("given an array of one", func() {
|
|
|
|
When("given an array of one", func() {
|
|
|
|
It("should not do anything", func() {
|
|
|
|
It("should not do anything", func() {
|
|
|
|
client.TestData.Containers = []container.Container{
|
|
|
|
client := CreateMockClient(
|
|
|
|
|
|
|
|
&TestData{
|
|
|
|
|
|
|
|
Containers: []container.Container{
|
|
|
|
CreateMockContainer(
|
|
|
|
CreateMockContainer(
|
|
|
|
"test-container",
|
|
|
|
"test-container",
|
|
|
|
"test-container",
|
|
|
|
"test-container",
|
|
|
|
"watchtower",
|
|
|
|
"watchtower",
|
|
|
|
time.Now()),
|
|
|
|
time.Now()),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
|
|
|
|
},
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// pullImages:
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
// removeVolumes:
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
When("given multiple containers", func() {
|
|
|
|
When("given multiple containers", func() {
|
|
|
|
|
|
|
|
var client MockClient
|
|
|
|
BeforeEach(func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
pullImages := false
|
|
|
|
|
|
|
|
removeVolumes := false
|
|
|
|
|
|
|
|
client = CreateMockClient(
|
|
|
|
client = CreateMockClient(
|
|
|
|
&TestData{
|
|
|
|
&TestData{
|
|
|
|
NameOfContainerToKeep: "test-container-02",
|
|
|
|
NameOfContainerToKeep: "test-container-02",
|
|
|
@ -84,9 +70,10 @@ var _ = Describe("the actions package", func() {
|
|
|
|
time.Now()),
|
|
|
|
time.Now()),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dockerClient,
|
|
|
|
// pullImages:
|
|
|
|
pullImages,
|
|
|
|
false,
|
|
|
|
removeVolumes,
|
|
|
|
// removeVolumes:
|
|
|
|
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
@ -96,10 +83,8 @@ var _ = Describe("the actions package", func() {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
When("deciding whether to cleanup images", func() {
|
|
|
|
When("deciding whether to cleanup images", func() {
|
|
|
|
|
|
|
|
var client MockClient
|
|
|
|
BeforeEach(func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
pullImages := false
|
|
|
|
|
|
|
|
removeVolumes := false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = CreateMockClient(
|
|
|
|
client = CreateMockClient(
|
|
|
|
&TestData{
|
|
|
|
&TestData{
|
|
|
|
Containers: []container.Container{
|
|
|
|
Containers: []container.Container{
|
|
|
@ -115,9 +100,10 @@ var _ = Describe("the actions package", func() {
|
|
|
|
time.Now()),
|
|
|
|
time.Now()),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dockerClient,
|
|
|
|
// pullImages:
|
|
|
|
pullImages,
|
|
|
|
false,
|
|
|
|
removeVolumes,
|
|
|
|
// removeVolumes:
|
|
|
|
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
It("should try to delete the image if the cleanup flag is true", func() {
|
|
|
|
It("should try to delete the image if the cleanup flag is true", func() {
|
|
|
@ -133,15 +119,3 @@ var _ = Describe("the actions package", func() {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
func createMockContainer(id string, name string, image string, created time.Time) container.Container {
|
|
|
|
|
|
|
|
content := types.ContainerJSON{
|
|
|
|
|
|
|
|
ContainerJSONBase: &types.ContainerJSONBase{
|
|
|
|
|
|
|
|
ID: id,
|
|
|
|
|
|
|
|
Image: image,
|
|
|
|
|
|
|
|
Name: name,
|
|
|
|
|
|
|
|
Created: created.String(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return *container.NewContainer(&content, nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|