package store import "testing" func TestEffectivePeerEnabledOnCreate(t *testing.T) { if !EffectivePeerEnabledOnCreate(false, "") { t.Fatal("omitted enabled (false) + empty session should default to enabled") } if !EffectivePeerEnabledOnCreate(true, "") { t.Fatal("explicit true") } if !EffectivePeerEnabledOnCreate(true, "down") { t.Fatal("true with session") } if EffectivePeerEnabledOnCreate(false, "Idle") { t.Fatal("false with non-empty session should stay disabled") } } func TestParsePeerNeighbor(t *testing.T) { tests := []struct { in string want string wantOK bool }{ {"192.168.0.2", "192.168.0.2", true}, {"192.168.0.2/32", "192.168.0.2", true}, {" 192.168.0.2/32 ", "192.168.0.2", true}, {"2001:db8::1", "2001:db8::1", true}, {"2001:db8::1/128", "2001:db8::1", true}, {"192.168.0.0/24", "", false}, {"not-an-ip", "", false}, {"", "", false}, } for _, tt := range tests { addr, ok := ParsePeerNeighbor(tt.in) if ok != tt.wantOK { t.Errorf("ParsePeerNeighbor(%q) ok=%v want %v", tt.in, ok, tt.wantOK) continue } if !tt.wantOK { continue } if got := addr.String(); got != tt.want { t.Errorf("ParsePeerNeighbor(%q) = %q want %q", tt.in, got, tt.want) } } }