Merge pull request #46350 from thaJeztah/strongtype_eventstype

api/types/events: make events.Type an actual type
This commit is contained in:
Sebastiaan van Stijn 2023-08-28 16:44:26 +02:00 committed by GitHub
commit 8309206160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 8 deletions

View file

@ -1,7 +1,7 @@
package events // import "github.com/docker/docker/api/types/events"
// Type is used for event-types.
type Type = string
type Type string
// List of known event types.
const (

View file

@ -60,7 +60,7 @@ func TestEventsErrorFromServer(t *testing.T) {
func TestEvents(t *testing.T) {
const expectedURL = "/events"
fltrs := filters.NewArgs(filters.Arg("type", events.ContainerEventType))
fltrs := filters.NewArgs(filters.Arg("type", string(events.ContainerEventType)))
expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType)
eventsCases := []struct {

View file

@ -722,7 +722,7 @@ func (c *containerConfig) applyPrivileges(hc *enginecontainer.HostConfig) {
func (c *containerConfig) eventFilter() filters.Args {
return filters.NewArgs(
filters.Arg("type", events.ContainerEventType),
filters.Arg("type", string(events.ContainerEventType)),
filters.Arg("name", c.name()),
filters.Arg("label", fmt.Sprintf("%v.task.id=%v", systemLabelPrefix, c.task.ID)),
)

View file

@ -19,7 +19,7 @@ func NewFilter(filter filters.Args) *Filter {
// Include returns true when the event ev is included by the filters
func (ef *Filter) Include(ev events.Message) bool {
return ef.matchEvent(ev) &&
ef.filter.ExactMatch("type", ev.Type) &&
ef.filter.ExactMatch("type", string(ev.Type)) &&
ef.matchScope(ev.Scope) &&
ef.matchDaemon(ev) &&
ef.matchContainer(ev) &&
@ -103,8 +103,7 @@ func (ef *Filter) matchConfig(ev events.Message) bool {
}
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType events.Type) bool {
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])
return ef.filter.FuzzyMatch(string(eventType), ev.Actor.ID) || ef.filter.FuzzyMatch(string(eventType), ev.Actor.Attributes["name"])
}
// matchImage matches against both event.Actor.ID (for image events)

View file

@ -65,7 +65,7 @@ func Scan(text string) (*events.Message, error) {
return &events.Message{
Time: t,
TimeNano: time.Unix(t, tn).UnixNano(),
Type: md["eventType"],
Type: events.Type(md["eventType"]),
Action: md["action"],
Actor: events.Actor{
ID: md["id"],

View file

@ -48,7 +48,7 @@ func TestPause(t *testing.T) {
messages, errs := apiClient.Events(ctx, types.EventsOptions{
Since: since,
Until: until,
Filters: filters.NewArgs(filters.Arg(events.ContainerEventType, cID)),
Filters: filters.NewArgs(filters.Arg(string(events.ContainerEventType), cID)),
})
assert.Check(t, is.DeepEqual([]string{"pause", "unpause"}, getEventActions(t, messages, errs)))
}