mirror of
https://github.com/containrrr/watchtower.git
synced 2025-02-10 19:41:34 +02:00
test: remove unused cross package dependency on mock api server
This commit is contained in:
parent
26fba69169
commit
ec43ecedc4
@ -5,12 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containrrr/watchtower/internal/actions"
|
||||
|
||||
"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/onsi/ginkgo"
|
||||
@ -23,51 +18,42 @@ func TestActions(t *testing.T) {
|
||||
}
|
||||
|
||||
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() {
|
||||
When("given an empty array", func() {
|
||||
It("should not do anything", func() {
|
||||
client.TestData.Containers = []container.Container{}
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
client := CreateMockClient(
|
||||
&TestData{},
|
||||
// pullImages:
|
||||
false,
|
||||
// removeVolumes:
|
||||
false,
|
||||
)
|
||||
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
|
||||
})
|
||||
})
|
||||
When("given an array of one", func() {
|
||||
It("should not do anything", func() {
|
||||
client.TestData.Containers = []container.Container{
|
||||
CreateMockContainer(
|
||||
"test-container",
|
||||
"test-container",
|
||||
"watchtower",
|
||||
time.Now()),
|
||||
}
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
client := CreateMockClient(
|
||||
&TestData{
|
||||
Containers: []container.Container{
|
||||
CreateMockContainer(
|
||||
"test-container",
|
||||
"test-container",
|
||||
"watchtower",
|
||||
time.Now()),
|
||||
},
|
||||
},
|
||||
// pullImages:
|
||||
false,
|
||||
// removeVolumes:
|
||||
false,
|
||||
)
|
||||
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
|
||||
})
|
||||
})
|
||||
When("given multiple containers", func() {
|
||||
var client MockClient
|
||||
BeforeEach(func() {
|
||||
pullImages := false
|
||||
removeVolumes := false
|
||||
client = CreateMockClient(
|
||||
&TestData{
|
||||
NameOfContainerToKeep: "test-container-02",
|
||||
@ -84,9 +70,10 @@ var _ = Describe("the actions package", func() {
|
||||
time.Now()),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
pullImages,
|
||||
removeVolumes,
|
||||
// pullImages:
|
||||
false,
|
||||
// removeVolumes:
|
||||
false,
|
||||
)
|
||||
})
|
||||
|
||||
@ -96,10 +83,8 @@ var _ = Describe("the actions package", func() {
|
||||
})
|
||||
})
|
||||
When("deciding whether to cleanup images", func() {
|
||||
var client MockClient
|
||||
BeforeEach(func() {
|
||||
pullImages := false
|
||||
removeVolumes := false
|
||||
|
||||
client = CreateMockClient(
|
||||
&TestData{
|
||||
Containers: []container.Container{
|
||||
@ -115,9 +100,10 @@ var _ = Describe("the actions package", func() {
|
||||
time.Now()),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
pullImages,
|
||||
removeVolumes,
|
||||
// pullImages:
|
||||
false,
|
||||
// removeVolumes:
|
||||
false,
|
||||
)
|
||||
})
|
||||
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)
|
||||
}
|
||||
|
@ -7,13 +7,11 @@ import (
|
||||
"time"
|
||||
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
cli "github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
// MockClient is a mock that passes as a watchtower Client
|
||||
type MockClient struct {
|
||||
TestData *TestData
|
||||
api cli.CommonAPIClient
|
||||
pullImages bool
|
||||
removeVolumes bool
|
||||
}
|
||||
@ -31,10 +29,9 @@ func (testdata *TestData) TriedToRemoveImage() bool {
|
||||
}
|
||||
|
||||
// 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, pullImages bool, removeVolumes bool) MockClient {
|
||||
return MockClient{
|
||||
data,
|
||||
api,
|
||||
pullImages,
|
||||
removeVolumes,
|
||||
}
|
||||
|
@ -3,10 +3,8 @@ package actions_test
|
||||
import (
|
||||
"github.com/containrrr/watchtower/internal/actions"
|
||||
"github.com/containrrr/watchtower/pkg/container"
|
||||
"github.com/containrrr/watchtower/pkg/container/mocks"
|
||||
"github.com/containrrr/watchtower/pkg/types"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
cli "github.com/docker/docker/client"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"time"
|
||||
|
||||
@ -16,16 +14,8 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("the update action", func() {
|
||||
var dockerClient cli.CommonAPIClient
|
||||
var client MockClient
|
||||
|
||||
BeforeEach(func() {
|
||||
server := mocks.NewMockAPIServer()
|
||||
dockerClient, _ = cli.NewClientWithOpts(
|
||||
cli.WithHost(server.URL),
|
||||
cli.WithHTTPClient(server.Client()))
|
||||
})
|
||||
|
||||
When("watchtower has been instructed to clean up", func() {
|
||||
BeforeEach(func() {
|
||||
pullImages := false
|
||||
@ -51,7 +41,6 @@ var _ = Describe("the update action", func() {
|
||||
time.Now()),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
pullImages,
|
||||
removeVolumes,
|
||||
)
|
||||
@ -117,7 +106,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -147,7 +135,6 @@ var _ = Describe("the update action", func() {
|
||||
time.Now()),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -186,7 +173,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -222,7 +208,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -258,7 +243,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -293,7 +277,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
@ -329,7 +312,6 @@ var _ = Describe("the update action", func() {
|
||||
}),
|
||||
},
|
||||
},
|
||||
dockerClient,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user