collector: add bounds check and test for filesystem collector (#1133)

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher 2018-10-30 17:12:42 -04:00 committed by Ben Kochie
commit c0a55e3f80
2 changed files with 35 additions and 2 deletions

View file

@ -16,11 +16,32 @@
package collector
import (
"strings"
"testing"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func Test_parseFilesystemLabelsError(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 := parseFilesystemLabels(strings.NewReader(tt.in)); err == nil {
t.Fatal("expected an error, but none occurred")
}
})
}
}
func TestMountPointDetails(t *testing.T) {
if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "./fixtures/proc"}); err != nil {
t.Fatal(err)