From 38346fee752aaa9d408400d8be8fa28891d2dc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=AE=B6=E6=A6=9C?= <14038@chinasws.com> Date: Tue, 16 Nov 2021 06:55:29 +0800 Subject: [PATCH] adding testing case for net device that has colon in its name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴家榜 <14038@chinasws.com> --- net_dev_test.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/net_dev_test.go b/net_dev_test.go index c26c7b295..fb5390e10 100644 --- a/net_dev_test.go +++ b/net_dev_test.go @@ -14,21 +14,24 @@ package procfs import ( + "fmt" "testing" ) func TestNetDevParseLine(t *testing.T) { - const rawLine = ` eth0: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16` - - have, err := NetDev{}.parseLine(rawLine) - if err != nil { - t.Fatal(err) + tc := []string{"eth0", "eth0:1"} + for i := range tc { + rawLine := fmt.Sprintf(` %v: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16`, tc[i]) + have, err := NetDev{}.parseLine(rawLine) + if err != nil { + t.Fatal(err) + } + want := NetDevLine{tc[i], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + if want != *have { + t.Errorf("want %v, have %v", want, have) + } } - want := NetDevLine{"eth0", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - if want != *have { - t.Errorf("want %v, have %v", want, have) - } } func TestNetDev(t *testing.T) {