4 Star 1 Fork 0

Gitee 极速下载/netlink

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/vishvananda/netlink
克隆/下载
socket_linux_test.go 2.68 KB
一键复制 编辑 原始数据 按行查看 历史
package netlink
import (
"reflect"
"syscall"
"testing"
)
func TestAttrsToInetDiagTCPInfoResp(t *testing.T) {
tests := []struct {
name string
attrs []syscall.NetlinkRouteAttr
expected *InetDiagTCPInfoResp
wantFail bool
}{
{
name: "Empty",
attrs: []syscall.NetlinkRouteAttr{},
expected: &InetDiagTCPInfoResp{},
},
{
name: "BBRInfo Only",
attrs: []syscall.NetlinkRouteAttr{
{
Attr: syscall.RtAttr{
Len: 20,
Type: INET_DIAG_BBRINFO,
},
Value: []byte{
100, 0, 0, 0, 0, 0, 0, 0,
111, 0, 0, 0,
222, 0, 0, 0,
123, 0, 0, 0,
},
},
},
expected: &InetDiagTCPInfoResp{
TCPBBRInfo: &TCPBBRInfo{
BBRBW: 100,
BBRMinRTT: 111,
BBRPacingGain: 222,
BBRCwndGain: 123,
},
},
},
{
name: "TCPInfo Only",
attrs: []syscall.NetlinkRouteAttr{
{
Attr: syscall.RtAttr{
Len: 232,
Type: INET_DIAG_INFO,
},
Value: tcpInfoData,
},
},
expected: &InetDiagTCPInfoResp{
TCPInfo: tcpInfo,
},
},
{
name: "TCPInfo + TCPBBR",
attrs: []syscall.NetlinkRouteAttr{
{
Attr: syscall.RtAttr{
Len: 232,
Type: INET_DIAG_INFO,
},
Value: tcpInfoData,
},
{
Attr: syscall.RtAttr{
Len: 20,
Type: INET_DIAG_BBRINFO,
},
Value: []byte{
100, 0, 0, 0, 0, 0, 0, 0,
111, 0, 0, 0,
222, 0, 0, 0,
123, 0, 0, 0,
},
},
},
expected: &InetDiagTCPInfoResp{
TCPInfo: tcpInfo,
TCPBBRInfo: &TCPBBRInfo{
BBRBW: 100,
BBRMinRTT: 111,
BBRPacingGain: 222,
BBRCwndGain: 123,
},
},
},
{
name: "TCPBBR + TCPInfo (reverse)",
attrs: []syscall.NetlinkRouteAttr{
{
Attr: syscall.RtAttr{
Len: 20,
Type: INET_DIAG_BBRINFO,
},
Value: []byte{
100, 0, 0, 0, 0, 0, 0, 0,
111, 0, 0, 0,
222, 0, 0, 0,
123, 0, 0, 0,
},
},
{
Attr: syscall.RtAttr{
Len: 232,
Type: INET_DIAG_INFO,
},
Value: tcpInfoData,
},
},
expected: &InetDiagTCPInfoResp{
TCPInfo: tcpInfo,
TCPBBRInfo: &TCPBBRInfo{
BBRBW: 100,
BBRMinRTT: 111,
BBRPacingGain: 222,
BBRCwndGain: 123,
},
},
},
}
for _, test := range tests {
res, err := attrsToInetDiagTCPInfoResp(test.attrs, nil)
if err != nil && !test.wantFail {
t.Errorf("Unexpected failure for test %q", test.name)
continue
}
if err == nil && test.wantFail {
t.Errorf("Unexpected success for test %q", test.name)
continue
}
if !reflect.DeepEqual(test.expected, res) {
t.Errorf("Unexpected failure for test %q", test.name)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/netlink.git
[email protected]:mirrors/netlink.git
mirrors
netlink
netlink
main

搜索帮助