pod_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package render_test
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/weaveworks/common/test"
  6. "github.com/weaveworks/scope/render"
  7. "github.com/weaveworks/scope/render/expected"
  8. "github.com/weaveworks/scope/report"
  9. "github.com/weaveworks/scope/test/fixture"
  10. "github.com/weaveworks/scope/test/reflect"
  11. "github.com/weaveworks/scope/test/utils"
  12. )
  13. func TestPodRenderer(t *testing.T) {
  14. have := utils.Prune(render.PodRenderer.Render(context.Background(), fixture.Report).Nodes)
  15. want := utils.Prune(expected.RenderedPods)
  16. if !reflect.DeepEqual(want, have) {
  17. t.Error(test.Diff(want, have))
  18. }
  19. }
  20. var filterNonKubeSystem = render.Transformers([]render.Transformer{
  21. render.Complement(render.IsNamespace("kube-system")),
  22. render.FilterUnconnectedPseudo,
  23. })
  24. func TestPodFilterRenderer(t *testing.T) {
  25. // tag on containers or pod namespace in the topology and ensure
  26. // it is filtered out correctly.
  27. input := fixture.Report.Copy()
  28. input.Pod.Nodes[fixture.ClientPodNodeID] = input.Pod.Nodes[fixture.ClientPodNodeID].WithLatests(map[string]string{
  29. report.KubernetesNamespace: "kube-system",
  30. })
  31. have := utils.Prune(render.Render(context.Background(), input, render.PodRenderer, filterNonKubeSystem).Nodes)
  32. want := utils.Prune(expected.RenderedPods.Copy())
  33. delete(want, fixture.ClientPodNodeID)
  34. if !reflect.DeepEqual(want, have) {
  35. t.Error(test.Diff(want, have))
  36. }
  37. }
  38. func TestPodServiceRenderer(t *testing.T) {
  39. have := utils.Prune(render.PodServiceRenderer.Render(context.Background(), fixture.Report).Nodes)
  40. want := utils.Prune(expected.RenderedPodServices)
  41. if !reflect.DeepEqual(want, have) {
  42. t.Error(test.Diff(want, have))
  43. }
  44. }
  45. func TestPodServiceFilterRenderer(t *testing.T) {
  46. // tag on containers or pod namespace in the topology and ensure
  47. // it is filtered out correctly.
  48. input := fixture.Report.Copy()
  49. input.Service.Nodes[fixture.ServiceNodeID] = input.Service.Nodes[fixture.ServiceNodeID].WithLatests(map[string]string{
  50. report.KubernetesNamespace: "kube-system",
  51. })
  52. have := utils.Prune(render.Render(context.Background(), input, render.PodServiceRenderer, filterNonKubeSystem).Nodes)
  53. want := utils.Prune(expected.RenderedPodServices.Copy())
  54. delete(want, fixture.ServiceNodeID)
  55. delete(want, render.IncomingInternetID)
  56. if !reflect.DeepEqual(want, have) {
  57. t.Error(test.Diff(want, have))
  58. }
  59. }