ifTable_2009_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package snmp
  2. // #2009: un switch gestionado expone su interfaz de CPU como ifType other(1),
  3. // que no está en el mapa de no-físicas por la defensa de #1115. Pasaba el
  4. // filtro `!p.family` (rack y panel de puertos) y sumaba un puerto fantasma al
  5. // frontal. Se reconoce por nombre y SOLO cuando el ifType es other(1).
  6. import "testing"
  7. func TestIfFamilyForCPUInterface2009(t *testing.T) {
  8. cases := []struct {
  9. name string
  10. ps PortStats
  11. want string
  12. notes string
  13. }{
  14. {
  15. name: "XS708T CPU (ifDescr)",
  16. ps: PortStats{Type: 1, Index: 17,
  17. Descr: "CPU Interface for Slot: 3 Port: 1", Name: "CPU Interface: 3/1"},
  18. want: "cpu",
  19. },
  20. {
  21. name: "S3300 CPU (ifDescr de unidad)",
  22. ps: PortStats{Type: 1, Index: 313,
  23. Descr: "CPU Interface for Unit: 0 Slot: 5 Port: 1", Name: "CPU Interface: 0/5/1"},
  24. want: "cpu",
  25. },
  26. {
  27. name: "nombre suelto cpu0",
  28. ps: PortStats{Type: 1, Name: "cpu0"},
  29. want: "cpu",
  30. },
  31. {
  32. name: "other(1) con nombre normal sigue siendo físico",
  33. ps: PortStats{Type: 1, Name: "Port 9", Descr: "10G Ethernet"},
  34. want: "",
  35. },
  36. {
  37. name: "puerto real que se llama CPU pero es ethernet: físico",
  38. ps: PortStats{Type: 6, Name: "CPU Interface: 1/1"},
  39. want: "",
  40. },
  41. {
  42. name: "cpu con ifType propVirtual mantiene virtual",
  43. ps: PortStats{Type: 53, Name: "cpu0"},
  44. want: "virtual",
  45. },
  46. {
  47. name: "lag sigue siendo lag",
  48. ps: PortStats{Type: 161, Name: "po1"},
  49. want: "lag",
  50. },
  51. }
  52. for _, c := range cases {
  53. if got := ifFamilyFor(c.ps); got != c.want {
  54. t.Errorf("%s: ifFamilyFor(%+v) = %q, esperaba %q", c.name, c.ps, got, c.want)
  55. }
  56. }
  57. }