-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lonord
committed
Jun 19, 2018
1 parent
8c9f4fb
commit 7f575fe
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package netutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCal(t *testing.T) { | ||
s1, err := ReadDevStatus(func(p string) (string, error) { | ||
return data1, nil | ||
}) | ||
assert.NoError(t, err) | ||
s2, err := ReadDevStatus(func(p string) (string, error) { | ||
return data2, nil | ||
}) | ||
assert.NoError(t, err) | ||
map1 := convertToDevStatusMap(s1) | ||
map2 := convertToDevStatusMap(s2) | ||
speeds := cal(map1, map2, 1000) | ||
assert.Equal(t, len(speeds), 3) | ||
var speed NetSpeed | ||
for _, ss := range speeds { | ||
if ss.DevName == "br-lan" { | ||
speed = ss | ||
} | ||
} | ||
assert.Equal(t, speed.DevName, "br-lan") | ||
assert.Equal(t, speed.ReceiveSpeed, uint64(1000)) | ||
assert.Equal(t, speed.TransmitSpeed, uint64(2000)) | ||
} | ||
|
||
const data1 = `Inter-| Receive | Transmit | ||
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed | ||
br-lan: 88232992879 78760799 0 0 0 0 0 0 99798877563 67202989 0 0 0 0 0 0 | ||
wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
lo: 2312260588 3252792 0 0 0 0 0 0 2312260588 3252792 0 0 0 0 0 0 | ||
` | ||
|
||
const data2 = `Inter-| Receive | Transmit | ||
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed | ||
br-lan: 88232993879 78760799 0 0 0 0 0 0 99798879563 67202989 0 0 0 0 0 0 | ||
wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
lo: 2312260588 3252792 0 0 0 0 0 0 2312260588 3252792 0 0 0 0 0 0 | ||
` |