@@ -386,17 +386,19 @@ func (s *DockerDaemonSuite) TestDaemonEvents(c *check.C) {
386386 out , err := s .d .Cmd ("info" )
387387 c .Assert (err , checker .IsNil )
388388 daemonID := ""
389+ daemonName := ""
389390 for _ , line := range strings .Split (out , "\n " ) {
390391 if strings .HasPrefix (line , "ID: " ) {
391392 daemonID = strings .TrimPrefix (line , "ID: " )
392- break
393+ } else if strings .HasPrefix (line , "Name: " ) {
394+ daemonName = strings .TrimPrefix (line , "Name: " )
393395 }
394396 }
395397 c .Assert (daemonID , checker .Not (checker .Equals ), "" )
396398
397399 configFile , err = os .Create (configFilePath )
398400 c .Assert (err , checker .IsNil )
399- daemonConfig = `{"labels":["bar=foo"]}`
401+ daemonConfig = `{"max-concurrent-downloads":1," labels":["bar=foo"]}`
400402 fmt .Fprintf (configFile , "%s" , daemonConfig )
401403 configFile .Close ()
402404
@@ -406,5 +408,58 @@ func (s *DockerDaemonSuite) TestDaemonEvents(c *check.C) {
406408
407409 out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ))
408410 c .Assert (err , checker .IsNil )
409- c .Assert (out , checker .Contains , fmt .Sprintf ("daemon reload %s (cluster-advertise=, cluster-store=, cluster-store-opts={}, debug=true, labels=[\" bar=foo\" ])" , daemonID ))
411+ c .Assert (out , checker .Contains , fmt .Sprintf ("daemon reload %s (cluster-advertise=, cluster-store=, cluster-store-opts={}, debug=true, labels=[\" bar=foo\" ], max-concurrent-downloads=1, max-concurrent-uploads=5, name=%s)" , daemonID , daemonName ))
412+ }
413+
414+ func (s * DockerDaemonSuite ) TestDaemonEventsWithFilters (c * check.C ) {
415+ testRequires (c , SameHostDaemon , DaemonIsLinux )
416+
417+ // daemon config file
418+ configFilePath := "test.json"
419+ configFile , err := os .Create (configFilePath )
420+ c .Assert (err , checker .IsNil )
421+ defer os .Remove (configFilePath )
422+
423+ daemonConfig := `{"labels":["foo=bar"]}`
424+ fmt .Fprintf (configFile , "%s" , daemonConfig )
425+ configFile .Close ()
426+ c .Assert (s .d .Start (fmt .Sprintf ("--config-file=%s" , configFilePath )), check .IsNil )
427+
428+ // Get daemon ID
429+ out , err := s .d .Cmd ("info" )
430+ c .Assert (err , checker .IsNil )
431+ daemonID := ""
432+ daemonName := ""
433+ for _ , line := range strings .Split (out , "\n " ) {
434+ if strings .HasPrefix (line , "ID: " ) {
435+ daemonID = strings .TrimPrefix (line , "ID: " )
436+ } else if strings .HasPrefix (line , "Name: " ) {
437+ daemonName = strings .TrimPrefix (line , "Name: " )
438+ }
439+ }
440+ c .Assert (daemonID , checker .Not (checker .Equals ), "" )
441+
442+ syscall .Kill (s .d .cmd .Process .Pid , syscall .SIGHUP )
443+
444+ time .Sleep (3 * time .Second )
445+
446+ out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ), "--filter" , fmt .Sprintf ("daemon=%s" , daemonID ))
447+ c .Assert (err , checker .IsNil )
448+ c .Assert (out , checker .Contains , fmt .Sprintf ("daemon reload %s" , daemonID ))
449+
450+ out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ), "--filter" , fmt .Sprintf ("daemon=%s" , daemonName ))
451+ c .Assert (err , checker .IsNil )
452+ c .Assert (out , checker .Contains , fmt .Sprintf ("daemon reload %s" , daemonID ))
453+
454+ out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ), "--filter" , "daemon=foo" )
455+ c .Assert (err , checker .IsNil )
456+ c .Assert (out , checker .Not (checker .Contains ), fmt .Sprintf ("daemon reload %s" , daemonID ))
457+
458+ out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ), "--filter" , "type=daemon" )
459+ c .Assert (err , checker .IsNil )
460+ c .Assert (out , checker .Contains , fmt .Sprintf ("daemon reload %s" , daemonID ))
461+
462+ out , err = s .d .Cmd ("events" , "--since=0" , "--until" , daemonUnixTime (c ), "--filter" , "type=container" )
463+ c .Assert (err , checker .IsNil )
464+ c .Assert (out , checker .Not (checker .Contains ), fmt .Sprintf ("daemon reload %s" , daemonID ))
410465}
0 commit comments