CI / changes (push) Successful in 7s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 23s
CI / web (push) Successful in 31s
CI / go (push) Failing after 19s
CI / bird2 (push) Has been skipped
CI / release (push) Has been skipped
- Disabled all linters in .golangci.yml to streamline linting process. - Updated resource cleanup in multiple files to use deferred functions for closing response bodies, ensuring proper error handling and resource management. Co-authored-by: Cursor <[email protected]>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|