theinternet_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package render_test
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/weaveworks/common/test"
  6. "github.com/weaveworks/scope/render"
  7. "github.com/weaveworks/scope/report"
  8. )
  9. func TestReportLocalNetworks(t *testing.T) {
  10. r := report.Report{
  11. Host: report.Topology{
  12. Nodes: report.Nodes{
  13. "nonets": report.MakeNode("nonets"),
  14. "foo": report.MakeNode("foo").WithSets(report.MakeSets().
  15. Add(report.HostLocalNetworks, report.MakeStringSet(
  16. "10.0.0.1/8", "192.168.1.1/24", "10.0.0.1/8", "badnet/33")),
  17. ),
  18. },
  19. },
  20. Overlay: report.Topology{
  21. Nodes: report.Nodes{
  22. "router": report.MakeNode("router").WithSets(report.MakeSets().
  23. Add(report.HostLocalNetworks, report.MakeStringSet("10.32.0.1/12")),
  24. ),
  25. },
  26. },
  27. }.Copy()
  28. want := report.MakeNetworks()
  29. for _, cidr := range []string{"10.0.0.1/8", "192.168.1.1/24", "10.32.0.1/12"} {
  30. if err := want.AddCIDR(cidr); err != nil {
  31. panic(err)
  32. }
  33. }
  34. have := render.LocalNetworks(r)
  35. if !reflect.DeepEqual(want, have) {
  36. t.Errorf("%s", test.Diff(want, have))
  37. }
  38. }