4
0

networks_1889_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package adapters
  2. import (
  3. "testing"
  4. "github.com/gnacho/netpulse/agent/probe"
  5. )
  6. // #1889: la vista de redes lee el trafico del device de cada red, no el de sus
  7. // puertos, y una red sin contadores se queda sin cifra en vez de inventarla.
  8. func TestNetworkInfosTraficoDelDevice(t *testing.T) {
  9. nets := []probe.UciNetwork{
  10. {Name: "IOT", Device: "br-iot", Proto: "static", Subnet: "192.168.111.1/24", Vlan: 999, Ports: []string{"eth0.999"}},
  11. {Name: "Guest", Device: "br_switch.777", Proto: "none", Vlan: 777},
  12. }
  13. ports := []EthPort{
  14. {ID: "if-br-iot", Iface: "br-iot", RxBps: 1200, TxBps: 3400},
  15. {ID: "lan1", Iface: "lan1", RxBps: 99999, TxBps: 99999},
  16. }
  17. out := networkInfos(nets, ports)
  18. if len(out) != 2 {
  19. t.Fatalf("redes = %d", len(out))
  20. }
  21. iot := out[0]
  22. if iot.Name != "IOT" || iot.Vlan != 999 || iot.Subnet != "192.168.111.1/24" {
  23. t.Fatalf("IOT = %+v", iot)
  24. }
  25. if iot.RxBps != 1200 || iot.TxBps != 3400 {
  26. t.Fatalf("trafico de IOT = %v/%v, quiero el de br-iot", iot.RxBps, iot.TxBps)
  27. }
  28. if len(iot.Ports) != 1 || iot.Ports[0] != "eth0.999" {
  29. t.Fatalf("miembros de IOT = %v", iot.Ports)
  30. }
  31. guest := out[1]
  32. if guest.RxBps != 0 || guest.TxBps != 0 {
  33. t.Fatalf("Guest sin contadores = %v/%v", guest.RxBps, guest.TxBps)
  34. }
  35. if guest.Vlan != 777 || guest.Proto != "none" {
  36. t.Fatalf("Guest = %+v", guest)
  37. }
  38. }