mirror of
https://github.com/vishvananda/netlink.git
synced 2025-11-03 10:01:08 +08:00
Remove always-nil deserializeFouMsg error return value
The error is always nil. Remove it to simplify the callers.
This commit is contained in:
committed by
Alessandro Boch
parent
7a3403a870
commit
3d9b64dc8d
86
fou_test.go
86
fou_test.go
@@ -13,71 +13,63 @@ func TestFouDeserializeMsg(t *testing.T) {
|
||||
|
||||
// deserialize a valid message
|
||||
msg = []byte{3, 1, 0, 0, 5, 0, 2, 0, 2, 0, 0, 0, 6, 0, 1, 0, 21, 179, 0, 0, 5, 0, 3, 0, 4, 0, 0, 0, 5, 0, 4, 0, 1, 0, 0, 0}
|
||||
if fou, err := deserializeFouMsg(msg); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else {
|
||||
fou := deserializeFouMsg(msg)
|
||||
// check if message was deserialized correctly
|
||||
if fou.Family != FAMILY_V4 {
|
||||
t.Errorf("expected family %d, got %d", FAMILY_V4, fou.Family)
|
||||
}
|
||||
|
||||
// check if message was deserialized correctly
|
||||
if fou.Family != FAMILY_V4 {
|
||||
t.Errorf("expected family %d, got %d", FAMILY_V4, fou.Family)
|
||||
}
|
||||
if fou.Port != 5555 {
|
||||
t.Errorf("expected port 5555, got %d", fou.Port)
|
||||
}
|
||||
|
||||
if fou.Port != 5555 {
|
||||
t.Errorf("expected port 5555, got %d", fou.Port)
|
||||
}
|
||||
if fou.Protocol != 4 { // ipip
|
||||
t.Errorf("expected protocol 4, got %d", fou.Protocol)
|
||||
}
|
||||
|
||||
if fou.Protocol != 4 { // ipip
|
||||
t.Errorf("expected protocol 4, got %d", fou.Protocol)
|
||||
}
|
||||
|
||||
if fou.EncapType != FOU_ENCAP_DIRECT {
|
||||
t.Errorf("expected encap type %d, got %d", FOU_ENCAP_DIRECT, fou.EncapType)
|
||||
}
|
||||
if fou.EncapType != FOU_ENCAP_DIRECT {
|
||||
t.Errorf("expected encap type %d, got %d", FOU_ENCAP_DIRECT, fou.EncapType)
|
||||
}
|
||||
|
||||
// deserialize a valid message(kernel >= 5.2)
|
||||
msg = []byte{3, 1, 0, 0, 5, 0, 2, 0, 2, 0, 0, 0, 6, 0, 1, 0, 43, 103, 0, 0, 6, 0, 10, 0, 86, 206, 0, 0, 5, 0, 3, 0, 0, 0, 0, 0, 5, 0, 4, 0, 2, 0, 0, 0, 8, 0, 11, 0, 0, 0, 0, 0, 8, 0, 6, 0, 1, 2, 3, 4, 8, 0, 8, 0, 5, 6, 7, 8}
|
||||
if fou, err := deserializeFouMsg(msg); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else {
|
||||
if fou.Family != FAMILY_V4 {
|
||||
t.Errorf("expected family %d, got %d", FAMILY_V4, fou.Family)
|
||||
}
|
||||
fou = deserializeFouMsg(msg)
|
||||
if fou.Family != FAMILY_V4 {
|
||||
t.Errorf("expected family %d, got %d", FAMILY_V4, fou.Family)
|
||||
}
|
||||
|
||||
if fou.Port != 11111 {
|
||||
t.Errorf("expected port 5555, got %d", fou.Port)
|
||||
}
|
||||
if fou.Port != 11111 {
|
||||
t.Errorf("expected port 5555, got %d", fou.Port)
|
||||
}
|
||||
|
||||
if fou.Protocol != 0 { // gue
|
||||
t.Errorf("expected protocol 0, got %d", fou.Protocol)
|
||||
}
|
||||
if fou.Protocol != 0 { // gue
|
||||
t.Errorf("expected protocol 0, got %d", fou.Protocol)
|
||||
}
|
||||
|
||||
if fou.IfIndex != 0 {
|
||||
t.Errorf("expected ifindex 0, got %d", fou.Protocol)
|
||||
}
|
||||
if fou.IfIndex != 0 {
|
||||
t.Errorf("expected ifindex 0, got %d", fou.Protocol)
|
||||
}
|
||||
|
||||
if fou.EncapType != FOU_ENCAP_GUE {
|
||||
t.Errorf("expected encap type %d, got %d", FOU_ENCAP_GUE, fou.EncapType)
|
||||
}
|
||||
if fou.EncapType != FOU_ENCAP_GUE {
|
||||
t.Errorf("expected encap type %d, got %d", FOU_ENCAP_GUE, fou.EncapType)
|
||||
}
|
||||
|
||||
if expected := net.IPv4(1, 2, 3, 4); !fou.Local.Equal(expected) {
|
||||
t.Errorf("expected local %v, got %v", expected, fou.Local)
|
||||
}
|
||||
if expected := net.IPv4(1, 2, 3, 4); !fou.Local.Equal(expected) {
|
||||
t.Errorf("expected local %v, got %v", expected, fou.Local)
|
||||
}
|
||||
|
||||
if expected := net.IPv4(5, 6, 7, 8); !fou.Peer.Equal(expected) {
|
||||
t.Errorf("expected peer %v, got %v", expected, fou.Peer)
|
||||
}
|
||||
if expected := net.IPv4(5, 6, 7, 8); !fou.Peer.Equal(expected) {
|
||||
t.Errorf("expected peer %v, got %v", expected, fou.Peer)
|
||||
}
|
||||
|
||||
if fou.PeerPort != 22222 {
|
||||
t.Errorf("expected peer port 0, got %d", fou.PeerPort)
|
||||
}
|
||||
if fou.PeerPort != 22222 {
|
||||
t.Errorf("expected peer port 0, got %d", fou.PeerPort)
|
||||
}
|
||||
|
||||
// unknown attribute should be skipped
|
||||
msg = []byte{3, 1, 0, 0, 5, 0, 112, 0, 2, 0, 0, 0, 5, 0, 2, 0, 2, 0, 0}
|
||||
if fou, err := deserializeFouMsg(msg); err != nil {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
} else if fou.Family != 2 {
|
||||
fou = deserializeFouMsg(msg)
|
||||
if fou.Family != 2 {
|
||||
t.Errorf("expected family 2, got %d", fou.Family)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user