ssh_uplink_flake_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package adapters
  2. import (
  3. "slices"
  4. "testing"
  5. "github.com/gnacho/netpulse/agent/probe"
  6. )
  7. // Un fallo transitorio de ubus en el sondeo SSH no debe olvidar el uplink:
  8. // sin él, Automático volvería a contar como clientes a los vecinos de la red
  9. // de arriba durante el minuto que se cachea el fallo.
  10. func TestSSHUplinkDevsKeepsLastGoodOnUbusFailure(t *testing.T) {
  11. cached := []string{"phy1-sta0", "phy1-sta0"}
  12. got := sshUplinkDevs(probe.WanInfo{Device: "phy1-sta0", Port: "phy1-sta0"}, nil)
  13. if !slices.Equal(got, cached) {
  14. t.Fatalf("lectura buena: got %v, want %v", got, cached)
  15. }
  16. if got := sshUplinkDevs(probe.WanInfo{}, cached); !slices.Equal(got, cached) {
  17. t.Fatalf("con ubus fallido debía conservar la última lista buena: got %v", got)
  18. }
  19. p := &routerPolled{
  20. cfg: RouterConfig{ID: "travel", Name: "travel"},
  21. uplinkDevs: sshUplinkDevs(probe.WanInfo{}, cached),
  22. arp: map[string]string{
  23. "AA:BB:CC:00:00:01": "10.20.0.1",
  24. "AA:BB:CC:00:00:02": "192.168.2.50",
  25. },
  26. arpDevs: map[string]string{
  27. "AA:BB:CC:00:00:01": "phy1-sta0",
  28. "AA:BB:CC:00:00:02": "br-lan",
  29. },
  30. }
  31. l := NewLive(nil, nil, nil, nil)
  32. devs := l.buildDevices(map[string]*routerPolled{"travel": p}, "")
  33. if len(devs) != 1 || devs[0].MAC != "AA:BB:CC:00:00:02" {
  34. t.Fatalf("con ubus fallido solo debía contar el vecino de la LAN, got %+v", devs)
  35. }
  36. }