collector: add bounds check and test for tcpstat collector (#1134)
Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
parent
3d798aa4a1
commit
778124a56c
2 changed files with 25 additions and 0 deletions
|
|
@ -15,9 +15,30 @@ package collector
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_parseTCPStatsError(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
}{
|
||||
{
|
||||
name: "too few fields",
|
||||
in: "hello world",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if _, err := parseTCPStats(strings.NewReader(tt.in)); err == nil {
|
||||
t.Fatal("expected an error, but none occurred")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTCPStat(t *testing.T) {
|
||||
file, err := os.Open("fixtures/proc/net/tcpstat")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue