Update peer_test.go

This commit is contained in:
Ocenka 2025-08-05 15:38:08 +01:00 committed by GitHub
parent 3765f28a1b
commit d27ab3ee4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -266,6 +266,23 @@ func TestNewPeer(t *testing.T) {
p.Disconnect(DiscAlreadyConnected) // Should not hang p.Disconnect(DiscAlreadyConnected) // Should not hang
} }
// TestCapsReturnsCopy verifies that Caps() returns a copy of the internal slice.
func TestCapsReturnsCopy(t *testing.T) {
id := randomID()
name := "nodename"
caps := []Cap{{"a", 1}, {"b", 2}}
p := NewPeer(id, name, caps)
returned := p.Caps()
// Modify the returned slice.
returned[0] = Cap{"modified", 99}
// Ensure the internal slice was not affected.
if reflect.DeepEqual(returned, p.Caps()) {
t.Fatal("Caps() should return a copy, not a reference to the internal slice")
}
}
func TestMatchProtocols(t *testing.T) { func TestMatchProtocols(t *testing.T) {
tests := []struct { tests := []struct {
Remote []Cap Remote []Cap