mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-03 15:31:05 +01:00
Do not panic as much in Linux collector tests (#3050)
Running "go test" in the collector directory, without the fixtures available, results in multiple panics, including `SIGSEGV`. Most of these are due to incorrect error handling. This cleans them up. Signed-off-by: Benny Siegert <bsiegert@gmail.com>
This commit is contained in:
parent
dc185bc0f6
commit
80859a9f18
@ -92,7 +92,10 @@ func checkMetric(exp, got *btrfsMetric) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBtrfs(t *testing.T) {
|
func TestBtrfs(t *testing.T) {
|
||||||
fs, _ := btrfs.NewFS("fixtures/sys")
|
fs, err := btrfs.NewFS("fixtures/sys")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
collector := &btrfsCollector{fs: fs}
|
collector := &btrfsCollector{fs: fs}
|
||||||
|
|
||||||
stats, err := collector.fs.Stats()
|
stats, err := collector.fs.Stats()
|
||||||
|
@ -320,7 +320,7 @@ node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
|
|||||||
logger := log.NewLogfmtLogger(os.Stderr)
|
logger := log.NewLogfmtLogger(os.Stderr)
|
||||||
collector, err := NewDiskstatsCollector(logger)
|
collector, err := NewDiskstatsCollector(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
c, err := NewTestDiskStatsCollector(logger)
|
c, err := NewTestDiskStatsCollector(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -257,12 +257,12 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
|
|||||||
|
|
||||||
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
|
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
|
||||||
collector, err := makeEthtoolCollector(logger)
|
collector, err := makeEthtoolCollector(logger)
|
||||||
collector.ethtool = &EthtoolFixture{
|
|
||||||
fixturePath: "fixtures/ethtool/",
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
collector.ethtool = &EthtoolFixture{
|
||||||
|
fixturePath: "fixtures/ethtool/",
|
||||||
|
}
|
||||||
return collector, nil
|
return collector, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ node_network_supported_speed_bytes{device="eth0",duplex="half",mode="10baseT"} 1
|
|||||||
logger := log.NewLogfmtLogger(os.Stderr)
|
logger := log.NewLogfmtLogger(os.Stderr)
|
||||||
collector, err := NewEthtoolTestCollector(logger)
|
collector, err := NewEthtoolTestCollector(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
c, err := NewTestEthtoolCollector(logger)
|
c, err := NewTestEthtoolCollector(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user