Skip to content

Commit ec43ece

Browse files
committed
test: remove unused cross package dependency on mock api server
1 parent 26fba69 commit ec43ece

File tree

3 files changed

+35
-82
lines changed

3 files changed

+35
-82
lines changed

internal/actions/actions_suite_test.go

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import (
55
"time"
66

77
"github.com/containrrr/watchtower/internal/actions"
8-
98
"github.com/containrrr/watchtower/pkg/container"
10-
"github.com/containrrr/watchtower/pkg/container/mocks"
11-
12-
"github.com/docker/docker/api/types"
13-
cli "github.com/docker/docker/client"
149

1510
. "github.com/containrrr/watchtower/internal/actions/mocks"
1611
. "github.com/onsi/ginkgo"
@@ -23,51 +18,42 @@ func TestActions(t *testing.T) {
2318
}
2419

2520
var _ = Describe("the actions package", func() {
26-
var dockerClient cli.CommonAPIClient
27-
var client MockClient
28-
BeforeSuite(func() {
29-
server := mocks.NewMockAPIServer()
30-
dockerClient, _ = cli.NewClientWithOpts(
31-
cli.WithHost(server.URL),
32-
cli.WithHTTPClient(server.Client()))
33-
})
34-
BeforeEach(func() {
35-
pullImages := false
36-
removeVolumes := false
37-
38-
client = CreateMockClient(
39-
&TestData{},
40-
dockerClient,
41-
pullImages,
42-
removeVolumes,
43-
)
44-
})
45-
4621
Describe("the check prerequisites method", func() {
4722
When("given an empty array", func() {
4823
It("should not do anything", func() {
49-
client.TestData.Containers = []container.Container{}
50-
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
51-
Expect(err).NotTo(HaveOccurred())
24+
client := CreateMockClient(
25+
&TestData{},
26+
// pullImages:
27+
false,
28+
// removeVolumes:
29+
false,
30+
)
31+
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
5232
})
5333
})
5434
When("given an array of one", func() {
5535
It("should not do anything", func() {
56-
client.TestData.Containers = []container.Container{
57-
CreateMockContainer(
58-
"test-container",
59-
"test-container",
60-
"watchtower",
61-
time.Now()),
62-
}
63-
err := actions.CheckForMultipleWatchtowerInstances(client, false, "")
64-
Expect(err).NotTo(HaveOccurred())
36+
client := CreateMockClient(
37+
&TestData{
38+
Containers: []container.Container{
39+
CreateMockContainer(
40+
"test-container",
41+
"test-container",
42+
"watchtower",
43+
time.Now()),
44+
},
45+
},
46+
// pullImages:
47+
false,
48+
// removeVolumes:
49+
false,
50+
)
51+
Expect(actions.CheckForMultipleWatchtowerInstances(client, false, "")).To(Succeed())
6552
})
6653
})
6754
When("given multiple containers", func() {
55+
var client MockClient
6856
BeforeEach(func() {
69-
pullImages := false
70-
removeVolumes := false
7157
client = CreateMockClient(
7258
&TestData{
7359
NameOfContainerToKeep: "test-container-02",
@@ -84,9 +70,10 @@ var _ = Describe("the actions package", func() {
8470
time.Now()),
8571
},
8672
},
87-
dockerClient,
88-
pullImages,
89-
removeVolumes,
73+
// pullImages:
74+
false,
75+
// removeVolumes:
76+
false,
9077
)
9178
})
9279

@@ -96,10 +83,8 @@ var _ = Describe("the actions package", func() {
9683
})
9784
})
9885
When("deciding whether to cleanup images", func() {
86+
var client MockClient
9987
BeforeEach(func() {
100-
pullImages := false
101-
removeVolumes := false
102-
10388
client = CreateMockClient(
10489
&TestData{
10590
Containers: []container.Container{
@@ -115,9 +100,10 @@ var _ = Describe("the actions package", func() {
115100
time.Now()),
116101
},
117102
},
118-
dockerClient,
119-
pullImages,
120-
removeVolumes,
103+
// pullImages:
104+
false,
105+
// removeVolumes:
106+
false,
121107
)
122108
})
123109
It("should try to delete the image if the cleanup flag is true", func() {
@@ -133,15 +119,3 @@ var _ = Describe("the actions package", func() {
133119
})
134120
})
135121
})
136-
137-
func createMockContainer(id string, name string, image string, created time.Time) container.Container {
138-
content := types.ContainerJSON{
139-
ContainerJSONBase: &types.ContainerJSONBase{
140-
ID: id,
141-
Image: image,
142-
Name: name,
143-
Created: created.String(),
144-
},
145-
}
146-
return *container.NewContainer(&content, nil)
147-
}

internal/actions/mocks/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import (
77
"time"
88

99
t "github.com/containrrr/watchtower/pkg/types"
10-
cli "github.com/docker/docker/client"
1110
)
1211

1312
// MockClient is a mock that passes as a watchtower Client
1413
type MockClient struct {
1514
TestData *TestData
16-
api cli.CommonAPIClient
1715
pullImages bool
1816
removeVolumes bool
1917
}
@@ -31,10 +29,9 @@ func (testdata *TestData) TriedToRemoveImage() bool {
3129
}
3230

3331
// CreateMockClient creates a mock watchtower Client for usage in tests
34-
func CreateMockClient(data *TestData, api cli.CommonAPIClient, pullImages bool, removeVolumes bool) MockClient {
32+
func CreateMockClient(data *TestData, pullImages bool, removeVolumes bool) MockClient {
3533
return MockClient{
3634
data,
37-
api,
3835
pullImages,
3936
removeVolumes,
4037
}

internal/actions/update_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package actions_test
33
import (
44
"github.com/containrrr/watchtower/internal/actions"
55
"github.com/containrrr/watchtower/pkg/container"
6-
"github.com/containrrr/watchtower/pkg/container/mocks"
76
"github.com/containrrr/watchtower/pkg/types"
87
dockerContainer "github.com/docker/docker/api/types/container"
9-
cli "github.com/docker/docker/client"
108
"github.com/docker/go-connections/nat"
119
"time"
1210

@@ -16,16 +14,8 @@ import (
1614
)
1715

1816
var _ = Describe("the update action", func() {
19-
var dockerClient cli.CommonAPIClient
2017
var client MockClient
2118

22-
BeforeEach(func() {
23-
server := mocks.NewMockAPIServer()
24-
dockerClient, _ = cli.NewClientWithOpts(
25-
cli.WithHost(server.URL),
26-
cli.WithHTTPClient(server.Client()))
27-
})
28-
2919
When("watchtower has been instructed to clean up", func() {
3020
BeforeEach(func() {
3121
pullImages := false
@@ -51,7 +41,6 @@ var _ = Describe("the update action", func() {
5141
time.Now()),
5242
},
5343
},
54-
dockerClient,
5544
pullImages,
5645
removeVolumes,
5746
)
@@ -117,7 +106,6 @@ var _ = Describe("the update action", func() {
117106
}),
118107
},
119108
},
120-
dockerClient,
121109
false,
122110
false,
123111
)
@@ -147,7 +135,6 @@ var _ = Describe("the update action", func() {
147135
time.Now()),
148136
},
149137
},
150-
dockerClient,
151138
false,
152139
false,
153140
)
@@ -186,7 +173,6 @@ var _ = Describe("the update action", func() {
186173
}),
187174
},
188175
},
189-
dockerClient,
190176
false,
191177
false,
192178
)
@@ -222,7 +208,6 @@ var _ = Describe("the update action", func() {
222208
}),
223209
},
224210
},
225-
dockerClient,
226211
false,
227212
false,
228213
)
@@ -258,7 +243,6 @@ var _ = Describe("the update action", func() {
258243
}),
259244
},
260245
},
261-
dockerClient,
262246
false,
263247
false,
264248
)
@@ -293,7 +277,6 @@ var _ = Describe("the update action", func() {
293277
}),
294278
},
295279
},
296-
dockerClient,
297280
false,
298281
false,
299282
)
@@ -329,7 +312,6 @@ var _ = Describe("the update action", func() {
329312
}),
330313
},
331314
},
332-
dockerClient,
333315
false,
334316
false,
335317
)

0 commit comments

Comments
 (0)