roaming_anomalies_test.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package adapters
  2. import (
  3. "testing"
  4. )
  5. func TestClassifyRoamingDaemon(t *testing.T) {
  6. cases := []struct {
  7. name string
  8. usteer bool
  9. dawn bool
  10. expected RoamingDaemon
  11. }{
  12. {"none", false, false, RoamingDaemonNone},
  13. {"usteer", true, false, RoamingDaemonUsteer},
  14. {"dawn", false, true, RoamingDaemonDawn},
  15. {"both", true, true, RoamingDaemonBoth},
  16. }
  17. for _, tc := range cases {
  18. t.Run(tc.name, func(t *testing.T) {
  19. got := classifyRoamingDaemon(tc.usteer, tc.dawn)
  20. if got != tc.expected {
  21. t.Errorf("classifyRoamingDaemon(%v, %v) = %q, want %q", tc.usteer, tc.dawn, got, tc.expected)
  22. }
  23. })
  24. }
  25. }
  26. func TestBuildRoamingAnomalies(t *testing.T) {
  27. t.Run("sin anomalias", func(t *testing.T) {
  28. got := buildRoamingAnomalies(map[string][]dot11rIfaceRef{
  29. "temiscira": {
  30. {routerID: "r1", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: false}},
  31. {routerID: "r2", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: false}},
  32. },
  33. })
  34. if len(got) != 0 {
  35. t.Fatalf("esperaba 0 anomalias, got %d: %+v", len(got), got)
  36. }
  37. })
  38. t.Run("mobility domain distinto", func(t *testing.T) {
  39. got := buildRoamingAnomalies(map[string][]dot11rIfaceRef{
  40. "temiscira": {
  41. {routerID: "r1", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: false}},
  42. {routerID: "r2", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2026", FTOverDS: false}},
  43. },
  44. })
  45. if len(got) != 1 || got[0].Kind != "mobility_domain_mismatch" {
  46. t.Fatalf("esperaba mobility_domain_mismatch, got %+v", got)
  47. }
  48. })
  49. t.Run("ft mode mixto", func(t *testing.T) {
  50. got := buildRoamingAnomalies(map[string][]dot11rIfaceRef{
  51. "temiscira": {
  52. {routerID: "r1", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: true}},
  53. {routerID: "r2", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: false}},
  54. },
  55. })
  56. if len(got) != 1 || got[0].Kind != "ft_mode_mismatch" {
  57. t.Fatalf("esperaba ft_mode_mismatch, got %+v", got)
  58. }
  59. })
  60. t.Run("802.11r parcial", func(t *testing.T) {
  61. got := buildRoamingAnomalies(map[string][]dot11rIfaceRef{
  62. "temiscira": {
  63. {routerID: "r1", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: false}},
  64. {routerID: "r2", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: false, MobilityDomain: "", FTOverDS: false}},
  65. },
  66. })
  67. if len(got) != 1 || got[0].Kind != "partial_11r" {
  68. t.Fatalf("esperaba partial_11r, got %+v", got)
  69. }
  70. })
  71. t.Run("varias anomalias", func(t *testing.T) {
  72. got := buildRoamingAnomalies(map[string][]dot11rIfaceRef{
  73. "temiscira": {
  74. {routerID: "r1", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2025", FTOverDS: true}},
  75. {routerID: "r2", iface: Dot11rIface{SSID: "temiscira", Dot11REnabled: true, MobilityDomain: "2026", FTOverDS: false}},
  76. },
  77. })
  78. if len(got) != 2 {
  79. t.Fatalf("esperaba 2 anomalias, got %d: %+v", len(got), got)
  80. }
  81. })
  82. }