Browse code

api/types: move EventsOptions to api/types/events

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/06/09 19:28:03
Showing 10 changed files
... ...
@@ -12,13 +12,6 @@ import (
12 12
 	units "github.com/docker/go-units"
13 13
 )
14 14
 
15
-// EventsOptions holds parameters to filter events with.
16
-type EventsOptions struct {
17
-	Since   string
18
-	Until   string
19
-	Filters filters.Args
20
-}
21
-
22 15
 // NewHijackedResponse intializes a HijackedResponse type
23 16
 func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
24 17
 	return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}
... ...
@@ -1,4 +1,5 @@
1 1
 package events // import "github.com/docker/docker/api/types/events"
2
+import "github.com/docker/docker/api/types/filters"
2 3
 
3 4
 // Type is used for event-types.
4 5
 type Type string
... ...
@@ -125,3 +126,10 @@ type Message struct {
125 125
 	Time     int64 `json:"time,omitempty"`
126 126
 	TimeNano int64 `json:"timeNano,omitempty"`
127 127
 }
128
+
129
+// ListOptions holds parameters to filter events with.
130
+type ListOptions struct {
131
+	Since   string
132
+	Until   string
133
+	Filters filters.Args
134
+}
... ...
@@ -2,6 +2,7 @@ package types
2 2
 
3 3
 import (
4 4
 	"github.com/docker/docker/api/types/container"
5
+	"github.com/docker/docker/api/types/events"
5 6
 	"github.com/docker/docker/api/types/image"
6 7
 	"github.com/docker/docker/api/types/network"
7 8
 	"github.com/docker/docker/api/types/volume"
... ...
@@ -111,3 +112,8 @@ type CopyToContainerOptions = container.CopyToContainerOptions
111 111
 //
112 112
 // Deprecated: use [container.StatsResponse].
113 113
 type ContainerStats = container.StatsResponse
114
+
115
+// EventsOptions holds parameters to filter events with.
116
+//
117
+// Deprecated: use [events.ListOptions].
118
+type EventsOptions = events.ListOptions
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"net/url"
7 7
 	"time"
8 8
 
9
-	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/api/types/events"
11 10
 	"github.com/docker/docker/api/types/filters"
12 11
 	timetypes "github.com/docker/docker/api/types/time"
... ...
@@ -16,7 +15,7 @@ import (
16 16
 // by cancelling the context. Once the stream has been completely read an io.EOF error will
17 17
 // be sent over the error channel. If an error is sent all processing will be stopped. It's up
18 18
 // to the caller to reopen the stream in the event of an error by reinvoking this method.
19
-func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) {
19
+func (cli *Client) Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error) {
20 20
 	messages := make(chan events.Message)
21 21
 	errs := make(chan error, 1)
22 22
 
... ...
@@ -68,7 +67,7 @@ func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-c
68 68
 	return messages, errs
69 69
 }
70 70
 
71
-func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url.Values, error) {
71
+func buildEventsQueryParams(cliVersion string, options events.ListOptions) (url.Values, error) {
72 72
 	query := url.Values{}
73 73
 	ref := time.Now()
74 74
 
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"strings"
11 11
 	"testing"
12 12
 
13
-	"github.com/docker/docker/api/types"
14 13
 	"github.com/docker/docker/api/types/events"
15 14
 	"github.com/docker/docker/api/types/filters"
16 15
 	"github.com/docker/docker/errdefs"
... ...
@@ -20,17 +19,17 @@ import (
20 20
 
21 21
 func TestEventsErrorInOptions(t *testing.T) {
22 22
 	errorCases := []struct {
23
-		options       types.EventsOptions
23
+		options       events.ListOptions
24 24
 		expectedError string
25 25
 	}{
26 26
 		{
27
-			options: types.EventsOptions{
27
+			options: events.ListOptions{
28 28
 				Since: "2006-01-02TZ",
29 29
 			},
30 30
 			expectedError: `parsing time "2006-01-02TZ"`,
31 31
 		},
32 32
 		{
33
-			options: types.EventsOptions{
33
+			options: events.ListOptions{
34 34
 				Until: "2006-01-02TZ",
35 35
 			},
36 36
 			expectedError: `parsing time "2006-01-02TZ"`,
... ...
@@ -52,7 +51,7 @@ func TestEventsErrorFromServer(t *testing.T) {
52 52
 	client := &Client{
53 53
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
54 54
 	}
55
-	_, errs := client.Events(context.Background(), types.EventsOptions{})
55
+	_, errs := client.Events(context.Background(), events.ListOptions{})
56 56
 	err := <-errs
57 57
 	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
58 58
 }
... ...
@@ -64,13 +63,13 @@ func TestEvents(t *testing.T) {
64 64
 	expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType)
65 65
 
66 66
 	eventsCases := []struct {
67
-		options             types.EventsOptions
67
+		options             events.ListOptions
68 68
 		events              []events.Message
69 69
 		expectedEvents      map[string]bool
70 70
 		expectedQueryParams map[string]string
71 71
 	}{
72 72
 		{
73
-			options: types.EventsOptions{
73
+			options: events.ListOptions{
74 74
 				Filters: fltrs,
75 75
 			},
76 76
 			expectedQueryParams: map[string]string{
... ...
@@ -80,7 +79,7 @@ func TestEvents(t *testing.T) {
80 80
 			expectedEvents: make(map[string]bool),
81 81
 		},
82 82
 		{
83
-			options: types.EventsOptions{
83
+			options: events.ListOptions{
84 84
 				Filters: fltrs,
85 85
 			},
86 86
 			expectedQueryParams: map[string]string{
... ...
@@ -165,7 +165,7 @@ type SwarmAPIClient interface {
165 165
 
166 166
 // SystemAPIClient defines API client methods for the system
167 167
 type SystemAPIClient interface {
168
-	Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
168
+	Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error)
169 169
 	Info(ctx context.Context) (system.Info, error)
170 170
 	RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error)
171 171
 	DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"time"
7 7
 
8 8
 	cerrdefs "github.com/containerd/errdefs"
9
-	"github.com/docker/docker/api/types"
10 9
 	containertypes "github.com/docker/docker/api/types/container"
11 10
 	"github.com/docker/docker/api/types/events"
12 11
 	"github.com/docker/docker/api/types/filters"
... ...
@@ -41,7 +40,7 @@ func TestPause(t *testing.T) {
41 41
 
42 42
 	until := request.DaemonUnixTime(ctx, t, apiClient, testEnv)
43 43
 
44
-	messages, errs := apiClient.Events(ctx, types.EventsOptions{
44
+	messages, errs := apiClient.Events(ctx, events.ListOptions{
45 45
 		Since:   since,
46 46
 		Until:   until,
47 47
 		Filters: filters.NewArgs(filters.Arg(string(events.ContainerEventType), cID)),
... ...
@@ -244,7 +244,7 @@ func TestContainerRestartWithCancelledRequest(t *testing.T) {
244 244
 	}()
245 245
 
246 246
 	// Start listening for events.
247
-	messages, errs := apiClient.Events(ctx, types.EventsOptions{
247
+	messages, errs := apiClient.Events(ctx, events.ListOptions{
248 248
 		Filters: filters.NewArgs(
249 249
 			filters.Arg("container", cID),
250 250
 			filters.Arg("event", string(events.ActionRestart)),
... ...
@@ -287,7 +287,7 @@ func systemTime(ctx context.Context, t *testing.T, client client.APIClient, test
287 287
 }
288 288
 
289 289
 func systemEventsSince(ctx context.Context, client client.APIClient, since string) (<-chan eventtypes.Message, <-chan error, func()) {
290
-	eventOptions := types.EventsOptions{
290
+	eventOptions := eventtypes.ListOptions{
291 291
 		Since: since,
292 292
 	}
293 293
 	ctx, cancel := context.WithCancel(ctx)
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"testing"
12 12
 	"time"
13 13
 
14
-	"github.com/docker/docker/api/types"
15 14
 	containertypes "github.com/docker/docker/api/types/container"
16 15
 	"github.com/docker/docker/api/types/events"
17 16
 	"github.com/docker/docker/api/types/filters"
... ...
@@ -38,7 +37,7 @@ func TestEventsExecDie(t *testing.T) {
38 38
 	})
39 39
 	assert.NilError(t, err)
40 40
 
41
-	msg, errs := client.Events(ctx, types.EventsOptions{
41
+	msg, errs := client.Events(ctx, events.ListOptions{
42 42
 		Filters: filters.NewArgs(
43 43
 			filters.Arg("container", cID),
44 44
 			filters.Arg("event", string(events.ActionExecDie)),
... ...
@@ -156,7 +155,7 @@ func TestEventsVolumeCreate(t *testing.T) {
156 156
 		filters.Arg("event", "create"),
157 157
 		filters.Arg("volume", volName),
158 158
 	)
159
-	messages, errs := client.Events(ctx, types.EventsOptions{
159
+	messages, errs := client.Events(ctx, events.ListOptions{
160 160
 		Since:   since,
161 161
 		Until:   request.DaemonUnixTime(ctx, t, client, testEnv),
162 162
 		Filters: filter,
... ...
@@ -172,7 +171,7 @@ func TestEventsVolumeCreate(t *testing.T) {
172 172
 		Target: "/tmp/foo",
173 173
 	}))
174 174
 
175
-	messages, errs = client.Events(ctx, types.EventsOptions{
175
+	messages, errs = client.Events(ctx, events.ListOptions{
176 176
 		Since:   since,
177 177
 		Until:   request.DaemonUnixTime(ctx, t, client, testEnv),
178 178
 		Filters: filter,