vlans_router_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package adapters
  2. import (
  3. "testing"
  4. "github.com/gnacho/netpulse/agent/probe"
  5. )
  6. // #1757: la lista de flota lleva el bridge VLAN filtering por puerto, con el
  7. // nombre declarado en LuCI, para que la topología pueda etiquetar los
  8. // clientes cableados de cada VLAN.
  9. func TestBuildRouterExposesVlans(t *testing.T) {
  10. l := NewLive(nil, nil, nil, nil)
  11. p := &routerPolled{
  12. cfg: RouterConfig{ID: "gw", Host: "192.168.1.1"},
  13. vlans: []probe.VlanPort{
  14. {Port: "lan1", Vlans: []probe.VlanEntry{{ID: 20, Tagged: true}, {ID: 1, PVID: true}}},
  15. },
  16. luci: &probe.LuCILabels{VlanLabels: map[string]string{"20": "IoT"}},
  17. }
  18. r := l.buildRouter(p, nil)
  19. if len(r.Vlans) != 1 || r.Vlans[0].Port != "lan1" {
  20. t.Fatalf("vlans = %+v, want el puerto lan1", r.Vlans)
  21. }
  22. got := r.Vlans[0].Vlans
  23. if len(got) != 2 || got[0].ID != 20 || got[0].Name != "IoT" || !got[0].Tagged || got[1].ID != 1 || !got[1].PVID {
  24. t.Fatalf("entradas = %+v", got)
  25. }
  26. }
  27. // Sin bridge vlan filtering el campo queda nil: la UI no debe pintar VLANs
  28. // que la unidad no ha declarado.
  29. func TestBuildRouterWithoutVlans(t *testing.T) {
  30. l := NewLive(nil, nil, nil, nil)
  31. r := l.buildRouter(&routerPolled{cfg: RouterConfig{ID: "ap", Host: "192.168.1.2"}}, nil)
  32. if r.Vlans != nil {
  33. t.Fatalf("vlans = %+v, want nil", r.Vlans)
  34. }
  35. }