Ejemplo n.º 1
0
func newWeavePublisher(dockerEndpoint, weaveAddr, weaveHostname, containerName string) (*app.WeavePublisher, error) {
	dockerClient, err := docker.NewDockerClientStub(dockerEndpoint)
	if err != nil {
		return nil, err
	}
	weaveClient := weave.NewClient(weaveAddr)
	return app.NewWeavePublisher(
		weaveClient,
		dockerClient,
		app.Interfaces,
		weaveHostname,
		containerName,
	), nil
}
Ejemplo n.º 2
0
func TestWeave(t *testing.T) {
	weaveClient := &mockWeaveClient{
		published: map[string]entry{},
	}
	dockerClient := mockDockerClient{}
	interfaces := func() ([]app.Interface, error) {
		return []app.Interface{
			{
				Name: "eth0",
				Addrs: []net.Addr{
					&net.IPAddr{
						IP: ip,
					},
				},
			},
			{
				Name: "docker0",
				Addrs: []net.Addr{
					&net.IPAddr{
						IP: net.ParseIP("4.3.2.1"),
					},
				},
			},
		}, nil
	}
	publisher := app.NewWeavePublisher(
		weaveClient, dockerClient, interfaces,
		hostname, containerName)
	defer publisher.Stop()

	want := map[string]entry{
		hostname: {containerID, ip},
	}
	test.Poll(t, 100*time.Millisecond, want, func() interface{} {
		weaveClient.Lock()
		defer weaveClient.Unlock()
		result := map[string]entry{}
		for k, v := range weaveClient.published {
			result[k] = v
		}
		return result
	})
}