parents_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package detailed_test
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "github.com/weaveworks/common/test"
  7. "github.com/weaveworks/scope/render"
  8. "github.com/weaveworks/scope/render/detailed"
  9. "github.com/weaveworks/scope/render/expected"
  10. "github.com/weaveworks/scope/report"
  11. "github.com/weaveworks/scope/test/fixture"
  12. "github.com/weaveworks/scope/test/reflect"
  13. )
  14. func TestParents(t *testing.T) {
  15. ctx := context.Background()
  16. for _, c := range []struct {
  17. name string
  18. node report.Node
  19. want []detailed.Parent
  20. }{
  21. {
  22. name: "Node accidentally tagged with itself",
  23. node: render.HostRenderer.Render(ctx, fixture.Report).Nodes[fixture.ClientHostNodeID].WithParents(
  24. report.MakeSets().Add(report.Host, report.MakeStringSet(fixture.ClientHostNodeID)),
  25. ),
  26. want: nil,
  27. },
  28. {
  29. node: render.HostRenderer.Render(ctx, fixture.Report).Nodes[fixture.ClientHostNodeID],
  30. want: nil,
  31. },
  32. {
  33. name: "Container image",
  34. node: render.ContainerImageRenderer.Render(ctx, fixture.Report).Nodes[expected.ClientContainerImageNodeID],
  35. want: []detailed.Parent{
  36. {ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
  37. },
  38. },
  39. {
  40. name: "Container",
  41. node: render.ContainerWithImageNameRenderer.Render(ctx, fixture.Report).Nodes[fixture.ClientContainerNodeID],
  42. want: []detailed.Parent{
  43. {ID: expected.ClientContainerImageNodeID, Label: fixture.ClientContainerImageName, TopologyID: "containers-by-image"},
  44. {ID: fixture.ClientPodNodeID, Label: "pong-a", TopologyID: "pods"},
  45. {ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
  46. },
  47. },
  48. {
  49. node: render.ProcessRenderer.Render(ctx, fixture.Report).Nodes[fixture.ClientProcess1NodeID],
  50. want: []detailed.Parent{
  51. {ID: fixture.ClientContainerNodeID, Label: fixture.ClientContainerName, TopologyID: "containers"},
  52. {ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
  53. },
  54. },
  55. } {
  56. name := c.name
  57. if name == "" {
  58. name = fmt.Sprintf("Node %q", c.node.ID)
  59. }
  60. if have := detailed.Parents(fixture.Report, c.node); !reflect.DeepEqual(c.want, have) {
  61. t.Errorf("%s: %s", name, test.Diff(c.want, have))
  62. }
  63. }
  64. }