func TestWeaveTaggerOverlayTopology(t *testing.T) { oldExecCmd := exec.Command defer func() { exec.Command = oldExecCmd }() exec.Command = func(name string, args ...string) exec.Cmd { return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP)) } s := httptest.NewServer(http.HandlerFunc(mockWeaveRouter)) defer s.Close() w := overlay.NewWeave(mockHostID, s.URL) defer w.Stop() w.Tick() { have, err := w.Report() if err != nil { t.Fatal(err) } if want, have := report.MakeTopology().AddNode( report.MakeOverlayNodeID(mockWeavePeerName), report.MakeNodeWith(map[string]string{ overlay.WeavePeerName: mockWeavePeerName, overlay.WeavePeerNickName: mockWeavePeerNickName, }), ), have.Overlay; !reflect.DeepEqual(want, have) { t.Error(test.Diff(want, have)) } } { nodeID := report.MakeContainerNodeID(mockHostID, mockContainerID) want := report.Report{ Container: report.MakeTopology().AddNode(nodeID, report.MakeNodeWith(map[string]string{ docker.ContainerID: mockContainerID, overlay.WeaveDNSHostname: mockHostname, overlay.WeaveMACAddress: mockContainerMAC, }).WithSets(report.Sets{ docker.ContainerIPs: report.MakeStringSet(mockContainerIP), docker.ContainerIPsWithScopes: report.MakeStringSet(mockContainerIPWithScope), })), } have, err := w.Tag(report.Report{ Container: report.MakeTopology().AddNode(nodeID, report.MakeNodeWith(map[string]string{ docker.ContainerID: mockContainerID, })), }) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(want, have) { t.Error(test.Diff(want, have)) } } }
func TestExpose(t *testing.T) { oldExecCmd := exec.Command defer func() { exec.Command = oldExecCmd }() psCalled := false exec.Command = func(name string, args ...string) exec.Cmd { if args[0] == "expose" { t.Fatal("Expose not expected") return nil } psCalled = true return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP)) } client := weave.NewClient("") if err := client.Expose(); err != nil { t.Fatal(err) } if !psCalled { t.Fatal("Expected a call to weave ps") } psCalled, exposeCalled := false, false exec.Command = func(name string, args ...string) exec.Cmd { if args[0] == "expose" { exposeCalled = true return testExec.NewMockCmdString("") } psCalled = true return testExec.NewMockCmdString("") } if err := client.Expose(); err != nil { t.Fatal(err) } if !psCalled || !exposeCalled { t.Fatal("Expected a call to weave ps & expose") } }
func TestPS(t *testing.T) { oldExecCmd := exec.Command defer func() { exec.Command = oldExecCmd }() exec.Command = func(name string, args ...string) exec.Cmd { return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP)) } client := weave.NewClient("") entries, err := client.PS() if err != nil { t.Fatal(err) } want := map[string]weave.PSEntry{ mockContainerID: { ContainerIDPrefix: mockContainerID, MACAddress: mockContainerMAC, IPs: []string{mockContainerIP}, }, } if !reflect.DeepEqual(entries, want) { t.Fatal(test.Diff(entries, want)) } }
func TestWeaveTaggerOverlayTopology(t *testing.T) { oldExecCmd := exec.Command defer func() { exec.Command = oldExecCmd }() exec.Command = func(name string, args ...string) exec.Cmd { return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP)) } s := httptest.NewServer(http.HandlerFunc(mockWeaveRouter)) defer s.Close() w, err := overlay.NewWeave(mockHostID, s.URL) if err != nil { t.Fatal(err) } { have, err := w.Report() if err != nil { t.Fatal(err) } if want, have := (report.Topology{ Adjacency: report.Adjacency{}, EdgeMetadatas: report.EdgeMetadatas{}, NodeMetadatas: report.NodeMetadatas{ report.MakeOverlayNodeID(mockWeavePeerName): report.MakeNodeMetadataWith(map[string]string{ overlay.WeavePeerName: mockWeavePeerName, overlay.WeavePeerNickName: mockWeavePeerNickName, }), }, }), have.Overlay; !reflect.DeepEqual(want, have) { t.Error(test.Diff(want, have)) } } { nodeID := report.MakeContainerNodeID(mockHostID, mockContainerID) want := report.Report{ Container: report.Topology{ NodeMetadatas: report.NodeMetadatas{ nodeID: report.MakeNodeMetadataWith(map[string]string{ docker.ContainerID: mockContainerID, overlay.WeaveDNSHostname: mockHostname, overlay.WeaveMACAddress: mockContainerMAC, docker.ContainerIPs: mockContainerIP, }), }, }, } have, err := w.Tag(report.Report{ Container: report.Topology{ NodeMetadatas: report.NodeMetadatas{ nodeID: report.MakeNodeMetadataWith(map[string]string{ docker.ContainerID: mockContainerID, }), }, }, }) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(want, have) { t.Error(test.Diff(want, have)) } } }