Node_Exporter/collector/zfs_linux_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

// Copyright 2016 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package collector
import (
"os"
"testing"
)
func TestArcstatsParsing(t *testing.T) {
arcstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/arcstats")
if err != nil {
t.Fatal(err)
}
defer arcstatsFile.Close()
c := zfsCollector{}
if err != nil {
t.Fatal(err)
}
handlerCalled := false
err = c.parseArcstatsProcfsFile(arcstatsFile, func(s zfsSysctl, v zfsMetricValue) {
if s != zfsSysctl("kstat.zfs.misc.arcstats.hits") {
return
}
handlerCalled = true
if v != zfsMetricValue(8772612) {
t.Fatalf("Incorrect value parsed from procfs data")
}
})
if err != nil {
t.Fatal(err)
}
if !handlerCalled {
t.Fatal("Arcstats parsing handler was not called for some expected sysctls")
}
}