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:
Benny Siegert 2024-06-13 20:53:25 +02:00 committed by GitHub
parent dc185bc0f6
commit 80859a9f18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View File

@ -92,7 +92,10 @@ func checkMetric(exp, got *btrfsMetric) bool {
}
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}
stats, err := collector.fs.Stats()

View File

@ -320,7 +320,7 @@ node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
logger := log.NewLogfmtLogger(os.Stderr)
collector, err := NewDiskstatsCollector(logger)
if err != nil {
panic(err)
t.Fatal(err)
}
c, err := NewTestDiskStatsCollector(logger)
if err != nil {

View File

@ -257,12 +257,12 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
collector, err := makeEthtoolCollector(logger)
collector.ethtool = &EthtoolFixture{
fixturePath: "fixtures/ethtool/",
}
if err != nil {
return nil, err
}
collector.ethtool = &EthtoolFixture{
fixturePath: "fixtures/ethtool/",
}
return collector, nil
}
@ -373,7 +373,7 @@ node_network_supported_speed_bytes{device="eth0",duplex="half",mode="10baseT"} 1
logger := log.NewLogfmtLogger(os.Stderr)
collector, err := NewEthtoolTestCollector(logger)
if err != nil {
panic(err)
t.Fatal(err)
}
c, err := NewTestEthtoolCollector(logger)
if err != nil {