github.com/openshift/moby-moby@v1.13.2-0.20170601211448-f5ec1e2936dc/daemon/daemon_test.go (about) 1 // +build !solaris 2 3 package daemon 4 5 import ( 6 "io/ioutil" 7 "os" 8 "path/filepath" 9 "reflect" 10 "testing" 11 "time" 12 13 containertypes "github.com/docker/docker/api/types/container" 14 "github.com/docker/docker/container" 15 "github.com/docker/docker/pkg/discovery" 16 _ "github.com/docker/docker/pkg/discovery/memory" 17 "github.com/docker/docker/pkg/registrar" 18 "github.com/docker/docker/pkg/truncindex" 19 "github.com/docker/docker/registry" 20 "github.com/docker/docker/volume" 21 volumedrivers "github.com/docker/docker/volume/drivers" 22 "github.com/docker/docker/volume/local" 23 "github.com/docker/docker/volume/store" 24 "github.com/docker/go-connections/nat" 25 ) 26 27 // 28 // https://github.com/docker/docker/issues/8069 29 // 30 31 func TestGetContainer(t *testing.T) { 32 c1 := &container.Container{ 33 CommonContainer: container.CommonContainer{ 34 ID: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57", 35 Name: "tender_bardeen", 36 }, 37 } 38 39 c2 := &container.Container{ 40 CommonContainer: container.CommonContainer{ 41 ID: "3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de", 42 Name: "drunk_hawking", 43 }, 44 } 45 46 c3 := &container.Container{ 47 CommonContainer: container.CommonContainer{ 48 ID: "3cdbd1aa394fd68559fd1441d6eff2abfafdcba06e72d2febdba229008b0bf57", 49 Name: "3cdbd1aa", 50 }, 51 } 52 53 c4 := &container.Container{ 54 CommonContainer: container.CommonContainer{ 55 ID: "75fb0b800922abdbef2d27e60abcdfaf7fb0698b2a96d22d3354da361a6ff4a5", 56 Name: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57", 57 }, 58 } 59 60 c5 := &container.Container{ 61 CommonContainer: container.CommonContainer{ 62 ID: "d22d69a2b8960bf7fafdcba06e72d2febdba960bf7fafdcba06e72d2f9008b060b", 63 Name: "d22d69a2b896", 64 }, 65 } 66 67 store := container.NewMemoryStore() 68 store.Add(c1.ID, c1) 69 store.Add(c2.ID, c2) 70 store.Add(c3.ID, c3) 71 store.Add(c4.ID, c4) 72 store.Add(c5.ID, c5) 73 74 index := truncindex.NewTruncIndex([]string{}) 75 index.Add(c1.ID) 76 index.Add(c2.ID) 77 index.Add(c3.ID) 78 index.Add(c4.ID) 79 index.Add(c5.ID) 80 81 daemon := &Daemon{ 82 containers: store, 83 idIndex: index, 84 nameIndex: registrar.NewRegistrar(), 85 } 86 87 daemon.reserveName(c1.ID, c1.Name) 88 daemon.reserveName(c2.ID, c2.Name) 89 daemon.reserveName(c3.ID, c3.Name) 90 daemon.reserveName(c4.ID, c4.Name) 91 daemon.reserveName(c5.ID, c5.Name) 92 93 if container, _ := daemon.GetContainer("3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de"); container != c2 { 94 t.Fatal("Should explicitly match full container IDs") 95 } 96 97 if container, _ := daemon.GetContainer("75fb0b8009"); container != c4 { 98 t.Fatal("Should match a partial ID") 99 } 100 101 if container, _ := daemon.GetContainer("drunk_hawking"); container != c2 { 102 t.Fatal("Should match a full name") 103 } 104 105 // c3.Name is a partial match for both c3.ID and c2.ID 106 if c, _ := daemon.GetContainer("3cdbd1aa"); c != c3 { 107 t.Fatal("Should match a full name even though it collides with another container's ID") 108 } 109 110 if container, _ := daemon.GetContainer("d22d69a2b896"); container != c5 { 111 t.Fatal("Should match a container where the provided prefix is an exact match to the its name, and is also a prefix for its ID") 112 } 113 114 if _, err := daemon.GetContainer("3cdbd1"); err == nil { 115 t.Fatal("Should return an error when provided a prefix that partially matches multiple container ID's") 116 } 117 118 if _, err := daemon.GetContainer("nothing"); err == nil { 119 t.Fatal("Should return an error when provided a prefix that is neither a name or a partial match to an ID") 120 } 121 } 122 123 func initDaemonWithVolumeStore(tmp string) (*Daemon, error) { 124 var err error 125 daemon := &Daemon{ 126 repository: tmp, 127 root: tmp, 128 } 129 daemon.volumes, err = store.New(tmp) 130 if err != nil { 131 return nil, err 132 } 133 134 volumesDriver, err := local.New(tmp, 0, 0) 135 if err != nil { 136 return nil, err 137 } 138 volumedrivers.Register(volumesDriver, volumesDriver.Name()) 139 140 return daemon, nil 141 } 142 143 func TestValidContainerNames(t *testing.T) { 144 invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"} 145 validNames := []string{"word-word", "word_word", "1weoid"} 146 147 for _, name := range invalidNames { 148 if validContainerNamePattern.MatchString(name) { 149 t.Fatalf("%q is not a valid container name and was returned as valid.", name) 150 } 151 } 152 153 for _, name := range validNames { 154 if !validContainerNamePattern.MatchString(name) { 155 t.Fatalf("%q is a valid container name and was returned as invalid.", name) 156 } 157 } 158 } 159 160 func TestContainerInitDNS(t *testing.T) { 161 tmp, err := ioutil.TempDir("", "docker-container-test-") 162 if err != nil { 163 t.Fatal(err) 164 } 165 defer os.RemoveAll(tmp) 166 167 containerID := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e" 168 containerPath := filepath.Join(tmp, containerID) 169 if err := os.MkdirAll(containerPath, 0755); err != nil { 170 t.Fatal(err) 171 } 172 173 config := `{"State":{"Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":2464,"ExitCode":0, 174 "Error":"","StartedAt":"2015-05-26T16:48:53.869308965Z","FinishedAt":"0001-01-01T00:00:00Z"}, 175 "ID":"d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e","Created":"2015-05-26T16:48:53.7987917Z","Path":"top", 176 "Args":[],"Config":{"Hostname":"d59df5276e7b","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"", 177 "AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":true,"OpenStdin":true, 178 "StdinOnce":false,"Env":null,"Cmd":["top"],"Image":"ubuntu:latest","Volumes":null,"WorkingDir":"","Entrypoint":null, 179 "NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":{}},"Image":"07f8e8c5e66084bef8f848877857537ffe1c47edd01a93af27e7161672ad0e95", 180 "NetworkSettings":{"IPAddress":"172.17.0.1","IPPrefixLen":16,"MacAddress":"02:42:ac:11:00:01","LinkLocalIPv6Address":"fe80::42:acff:fe11:1", 181 "LinkLocalIPv6PrefixLen":64,"GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"Gateway":"172.17.42.1","IPv6Gateway":"","Bridge":"docker0","Ports":{}}, 182 "ResolvConfPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/resolv.conf", 183 "HostnamePath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hostname", 184 "HostsPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hosts", 185 "LogPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e-json.log", 186 "Name":"/ubuntu","Driver":"aufs","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","RestartCount":0, 187 "UpdateDns":false,"Volumes":{},"VolumesRW":{},"AppliedVolumesFrom":null}` 188 189 // Container struct only used to retrieve path to config file 190 container := &container.Container{CommonContainer: container.CommonContainer{Root: containerPath}} 191 configPath, err := container.ConfigPath() 192 if err != nil { 193 t.Fatal(err) 194 } 195 if err = ioutil.WriteFile(configPath, []byte(config), 0644); err != nil { 196 t.Fatal(err) 197 } 198 199 hostConfig := `{"Binds":[],"ContainerIDFile":"","Memory":0,"MemorySwap":0,"CpuShares":0,"CpusetCpus":"", 200 "Privileged":false,"PortBindings":{},"Links":null,"PublishAllPorts":false,"Dns":null,"DnsOptions":null,"DnsSearch":null,"ExtraHosts":null,"VolumesFrom":null, 201 "Devices":[],"NetworkMode":"bridge","IpcMode":"","PidMode":"","CapAdd":null,"CapDrop":null,"RestartPolicy":{"Name":"no","MaximumRetryCount":0}, 202 "SecurityOpt":null,"ReadonlyRootfs":false,"Ulimits":null,"LogConfig":{"Type":"","Config":null},"CgroupParent":""}` 203 204 hostConfigPath, err := container.HostConfigPath() 205 if err != nil { 206 t.Fatal(err) 207 } 208 if err = ioutil.WriteFile(hostConfigPath, []byte(hostConfig), 0644); err != nil { 209 t.Fatal(err) 210 } 211 212 daemon, err := initDaemonWithVolumeStore(tmp) 213 if err != nil { 214 t.Fatal(err) 215 } 216 defer volumedrivers.Unregister(volume.DefaultDriverName) 217 218 c, err := daemon.load(containerID) 219 if err != nil { 220 t.Fatal(err) 221 } 222 223 if c.HostConfig.DNS == nil { 224 t.Fatal("Expected container DNS to not be nil") 225 } 226 227 if c.HostConfig.DNSSearch == nil { 228 t.Fatal("Expected container DNSSearch to not be nil") 229 } 230 231 if c.HostConfig.DNSOptions == nil { 232 t.Fatal("Expected container DNSOptions to not be nil") 233 } 234 } 235 236 func newPortNoError(proto, port string) nat.Port { 237 p, _ := nat.NewPort(proto, port) 238 return p 239 } 240 241 func TestMerge(t *testing.T) { 242 volumesImage := make(map[string]struct{}) 243 volumesImage["/test1"] = struct{}{} 244 volumesImage["/test2"] = struct{}{} 245 portsImage := make(nat.PortSet) 246 portsImage[newPortNoError("tcp", "1111")] = struct{}{} 247 portsImage[newPortNoError("tcp", "2222")] = struct{}{} 248 configImage := &containertypes.Config{ 249 ExposedPorts: portsImage, 250 Env: []string{"VAR1=1", "VAR2=2"}, 251 Volumes: volumesImage, 252 } 253 254 portsUser := make(nat.PortSet) 255 portsUser[newPortNoError("tcp", "2222")] = struct{}{} 256 portsUser[newPortNoError("tcp", "3333")] = struct{}{} 257 volumesUser := make(map[string]struct{}) 258 volumesUser["/test3"] = struct{}{} 259 configUser := &containertypes.Config{ 260 ExposedPorts: portsUser, 261 Env: []string{"VAR2=3", "VAR3=3"}, 262 Volumes: volumesUser, 263 } 264 265 if err := merge(configUser, configImage); err != nil { 266 t.Error(err) 267 } 268 269 if len(configUser.ExposedPorts) != 3 { 270 t.Fatalf("Expected 3 ExposedPorts, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts)) 271 } 272 for portSpecs := range configUser.ExposedPorts { 273 if portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" { 274 t.Fatalf("Expected 1111 or 2222 or 3333, found %s", portSpecs) 275 } 276 } 277 if len(configUser.Env) != 3 { 278 t.Fatalf("Expected 3 env var, VAR1=1, VAR2=3 and VAR3=3, found %d", len(configUser.Env)) 279 } 280 for _, env := range configUser.Env { 281 if env != "VAR1=1" && env != "VAR2=3" && env != "VAR3=3" { 282 t.Fatalf("Expected VAR1=1 or VAR2=3 or VAR3=3, found %s", env) 283 } 284 } 285 286 if len(configUser.Volumes) != 3 { 287 t.Fatalf("Expected 3 volumes, /test1, /test2 and /test3, found %d", len(configUser.Volumes)) 288 } 289 for v := range configUser.Volumes { 290 if v != "/test1" && v != "/test2" && v != "/test3" { 291 t.Fatalf("Expected /test1 or /test2 or /test3, found %s", v) 292 } 293 } 294 295 ports, _, err := nat.ParsePortSpecs([]string{"0000"}) 296 if err != nil { 297 t.Error(err) 298 } 299 configImage2 := &containertypes.Config{ 300 ExposedPorts: ports, 301 } 302 303 if err := merge(configUser, configImage2); err != nil { 304 t.Error(err) 305 } 306 307 if len(configUser.ExposedPorts) != 4 { 308 t.Fatalf("Expected 4 ExposedPorts, 0000, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts)) 309 } 310 for portSpecs := range configUser.ExposedPorts { 311 if portSpecs.Port() != "0" && portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" { 312 t.Fatalf("Expected %q or %q or %q or %q, found %s", 0, 1111, 2222, 3333, portSpecs) 313 } 314 } 315 } 316 317 func TestDaemonReloadLabels(t *testing.T) { 318 daemon := &Daemon{} 319 daemon.configStore = &Config{ 320 CommonConfig: CommonConfig{ 321 Labels: []string{"foo:bar"}, 322 }, 323 } 324 325 valuesSets := make(map[string]interface{}) 326 valuesSets["labels"] = "foo:baz" 327 newConfig := &Config{ 328 CommonConfig: CommonConfig{ 329 Labels: []string{"foo:baz"}, 330 valuesSet: valuesSets, 331 }, 332 } 333 334 if err := daemon.Reload(newConfig); err != nil { 335 t.Fatal(err) 336 } 337 338 label := daemon.configStore.Labels[0] 339 if label != "foo:baz" { 340 t.Fatalf("Expected daemon label `foo:baz`, got %s", label) 341 } 342 } 343 344 func TestDaemonReloadInsecureRegistries(t *testing.T) { 345 daemon := &Daemon{} 346 // initialize daemon with existing insecure registries: "127.0.0.0/8", "10.10.1.11:5000", "10.10.1.22:5000" 347 daemon.RegistryService = registry.NewService(registry.ServiceOptions{ 348 InsecureRegistries: []string{ 349 "127.0.0.0/8", 350 "10.10.1.11:5000", 351 "10.10.1.22:5000", // this will be removed when reloading 352 "docker1.com", 353 "docker2.com", // this will be removed when reloading 354 }, 355 }) 356 357 daemon.configStore = &Config{} 358 359 insecureRegistries := []string{ 360 "127.0.0.0/8", // this will be kept 361 "10.10.1.11:5000", // this will be kept 362 "10.10.1.33:5000", // this will be newly added 363 "docker1.com", // this will be kept 364 "docker3.com", // this will be newly added 365 } 366 367 valuesSets := make(map[string]interface{}) 368 valuesSets["insecure-registries"] = insecureRegistries 369 370 newConfig := &Config{ 371 CommonConfig: CommonConfig{ 372 ServiceOptions: registry.ServiceOptions{ 373 InsecureRegistries: insecureRegistries, 374 }, 375 valuesSet: valuesSets, 376 }, 377 } 378 379 if err := daemon.Reload(newConfig); err != nil { 380 t.Fatal(err) 381 } 382 383 // After Reload, daemon.RegistryService will be changed which is useful 384 // for registry communication in daemon. 385 registries := daemon.RegistryService.ServiceConfig() 386 387 // After Reload(), newConfig has come to registries.InsecureRegistryCIDRs and registries.IndexConfigs in daemon. 388 // Then collect registries.InsecureRegistryCIDRs in dataMap. 389 // When collecting, we need to convert CIDRS into string as a key, 390 // while the times of key appears as value. 391 dataMap := map[string]int{} 392 for _, value := range registries.InsecureRegistryCIDRs { 393 if _, ok := dataMap[value.String()]; !ok { 394 dataMap[value.String()] = 1 395 } else { 396 dataMap[value.String()]++ 397 } 398 } 399 400 for _, value := range registries.IndexConfigs { 401 if _, ok := dataMap[value.Name]; !ok { 402 dataMap[value.Name] = 1 403 } else { 404 dataMap[value.Name]++ 405 } 406 } 407 408 // Finally compare dataMap with the original insecureRegistries. 409 // Each value in insecureRegistries should appear in daemon's insecure registries, 410 // and each can only appear exactly ONCE. 411 for _, r := range insecureRegistries { 412 if value, ok := dataMap[r]; !ok { 413 t.Fatalf("Expected daemon insecure registry %s, got none", r) 414 } else if value != 1 { 415 t.Fatalf("Expected only 1 daemon insecure registry %s, got %d", r, value) 416 } 417 } 418 419 // assert if "10.10.1.22:5000" is removed when reloading 420 if value, ok := dataMap["10.10.1.22:5000"]; ok { 421 t.Fatalf("Expected no insecure registry of 10.10.1.22:5000, got %d", value) 422 } 423 424 // assert if "docker2.com" is removed when reloading 425 if value, ok := dataMap["docker2.com"]; ok { 426 t.Fatalf("Expected no insecure registry of docker2.com, got %d", value) 427 } 428 } 429 430 func TestDaemonReloadNotAffectOthers(t *testing.T) { 431 daemon := &Daemon{} 432 daemon.configStore = &Config{ 433 CommonConfig: CommonConfig{ 434 Labels: []string{"foo:bar"}, 435 Debug: true, 436 }, 437 } 438 439 valuesSets := make(map[string]interface{}) 440 valuesSets["labels"] = "foo:baz" 441 newConfig := &Config{ 442 CommonConfig: CommonConfig{ 443 Labels: []string{"foo:baz"}, 444 valuesSet: valuesSets, 445 }, 446 } 447 448 if err := daemon.Reload(newConfig); err != nil { 449 t.Fatal(err) 450 } 451 452 label := daemon.configStore.Labels[0] 453 if label != "foo:baz" { 454 t.Fatalf("Expected daemon label `foo:baz`, got %s", label) 455 } 456 debug := daemon.configStore.Debug 457 if !debug { 458 t.Fatalf("Expected debug 'enabled', got 'disabled'") 459 } 460 } 461 462 func TestDaemonDiscoveryReload(t *testing.T) { 463 daemon := &Daemon{} 464 daemon.configStore = &Config{ 465 CommonConfig: CommonConfig{ 466 ClusterStore: "memory://127.0.0.1", 467 ClusterAdvertise: "127.0.0.1:3333", 468 }, 469 } 470 471 if err := daemon.initDiscovery(daemon.configStore); err != nil { 472 t.Fatal(err) 473 } 474 475 expected := discovery.Entries{ 476 &discovery.Entry{Host: "127.0.0.1", Port: "3333"}, 477 } 478 479 select { 480 case <-time.After(10 * time.Second): 481 t.Fatal("timeout waiting for discovery") 482 case <-daemon.discoveryWatcher.ReadyCh(): 483 } 484 485 stopCh := make(chan struct{}) 486 defer close(stopCh) 487 ch, errCh := daemon.discoveryWatcher.Watch(stopCh) 488 489 select { 490 case <-time.After(1 * time.Second): 491 t.Fatal("failed to get discovery advertisements in time") 492 case e := <-ch: 493 if !reflect.DeepEqual(e, expected) { 494 t.Fatalf("expected %v, got %v\n", expected, e) 495 } 496 case e := <-errCh: 497 t.Fatal(e) 498 } 499 500 valuesSets := make(map[string]interface{}) 501 valuesSets["cluster-store"] = "memory://127.0.0.1:2222" 502 valuesSets["cluster-advertise"] = "127.0.0.1:5555" 503 newConfig := &Config{ 504 CommonConfig: CommonConfig{ 505 ClusterStore: "memory://127.0.0.1:2222", 506 ClusterAdvertise: "127.0.0.1:5555", 507 valuesSet: valuesSets, 508 }, 509 } 510 511 expected = discovery.Entries{ 512 &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, 513 } 514 515 if err := daemon.Reload(newConfig); err != nil { 516 t.Fatal(err) 517 } 518 519 select { 520 case <-time.After(10 * time.Second): 521 t.Fatal("timeout waiting for discovery") 522 case <-daemon.discoveryWatcher.ReadyCh(): 523 } 524 525 ch, errCh = daemon.discoveryWatcher.Watch(stopCh) 526 527 select { 528 case <-time.After(1 * time.Second): 529 t.Fatal("failed to get discovery advertisements in time") 530 case e := <-ch: 531 if !reflect.DeepEqual(e, expected) { 532 t.Fatalf("expected %v, got %v\n", expected, e) 533 } 534 case e := <-errCh: 535 t.Fatal(e) 536 } 537 } 538 539 func TestDaemonDiscoveryReloadFromEmptyDiscovery(t *testing.T) { 540 daemon := &Daemon{} 541 daemon.configStore = &Config{} 542 543 valuesSet := make(map[string]interface{}) 544 valuesSet["cluster-store"] = "memory://127.0.0.1:2222" 545 valuesSet["cluster-advertise"] = "127.0.0.1:5555" 546 newConfig := &Config{ 547 CommonConfig: CommonConfig{ 548 ClusterStore: "memory://127.0.0.1:2222", 549 ClusterAdvertise: "127.0.0.1:5555", 550 valuesSet: valuesSet, 551 }, 552 } 553 554 expected := discovery.Entries{ 555 &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, 556 } 557 558 if err := daemon.Reload(newConfig); err != nil { 559 t.Fatal(err) 560 } 561 562 select { 563 case <-time.After(10 * time.Second): 564 t.Fatal("timeout waiting for discovery") 565 case <-daemon.discoveryWatcher.ReadyCh(): 566 } 567 568 stopCh := make(chan struct{}) 569 defer close(stopCh) 570 ch, errCh := daemon.discoveryWatcher.Watch(stopCh) 571 572 select { 573 case <-time.After(1 * time.Second): 574 t.Fatal("failed to get discovery advertisements in time") 575 case e := <-ch: 576 if !reflect.DeepEqual(e, expected) { 577 t.Fatalf("expected %v, got %v\n", expected, e) 578 } 579 case e := <-errCh: 580 t.Fatal(e) 581 } 582 } 583 584 func TestDaemonDiscoveryReloadOnlyClusterAdvertise(t *testing.T) { 585 daemon := &Daemon{} 586 daemon.configStore = &Config{ 587 CommonConfig: CommonConfig{ 588 ClusterStore: "memory://127.0.0.1", 589 }, 590 } 591 valuesSets := make(map[string]interface{}) 592 valuesSets["cluster-advertise"] = "127.0.0.1:5555" 593 newConfig := &Config{ 594 CommonConfig: CommonConfig{ 595 ClusterAdvertise: "127.0.0.1:5555", 596 valuesSet: valuesSets, 597 }, 598 } 599 expected := discovery.Entries{ 600 &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, 601 } 602 603 if err := daemon.Reload(newConfig); err != nil { 604 t.Fatal(err) 605 } 606 607 select { 608 case <-daemon.discoveryWatcher.ReadyCh(): 609 case <-time.After(10 * time.Second): 610 t.Fatal("Timeout waiting for discovery") 611 } 612 stopCh := make(chan struct{}) 613 defer close(stopCh) 614 ch, errCh := daemon.discoveryWatcher.Watch(stopCh) 615 616 select { 617 case <-time.After(1 * time.Second): 618 t.Fatal("failed to get discovery advertisements in time") 619 case e := <-ch: 620 if !reflect.DeepEqual(e, expected) { 621 t.Fatalf("expected %v, got %v\n", expected, e) 622 } 623 case e := <-errCh: 624 t.Fatal(e) 625 } 626 627 }