-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change hddtemp to always put temperature in temperature field (#1905)
Added unit tests for the changes Fixes #1904
- Loading branch information
Showing
6 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package hddtemp | ||
|
||
import ( | ||
"testing" | ||
|
||
hddtemp "github.com/influxdata/telegraf/plugins/inputs/hddtemp/go-hddtemp" | ||
"github.com/influxdata/telegraf/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockFetcher struct { | ||
} | ||
|
||
func (h *mockFetcher) Fetch(address string) ([]hddtemp.Disk, error) { | ||
return []hddtemp.Disk{ | ||
hddtemp.Disk{ | ||
DeviceName: "Disk1", | ||
Model: "Model1", | ||
Temperature: 13, | ||
Unit: "C", | ||
}, | ||
hddtemp.Disk{ | ||
DeviceName: "Disk2", | ||
Model: "Model2", | ||
Temperature: 14, | ||
Unit: "C", | ||
}, | ||
}, nil | ||
|
||
} | ||
func newMockFetcher() *mockFetcher { | ||
return &mockFetcher{} | ||
} | ||
|
||
func TestFetch(t *testing.T) { | ||
hddtemp := &HDDTemp{ | ||
fetcher: newMockFetcher(), | ||
Devices: []string{"*"}, | ||
} | ||
|
||
acc := &testutil.Accumulator{} | ||
err := hddtemp.Gather(acc) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, acc.NFields(), 2) | ||
|
||
var tests = []struct { | ||
fields map[string]interface{} | ||
tags map[string]string | ||
}{ | ||
{ | ||
map[string]interface{}{ | ||
"temperature": int32(13), | ||
}, | ||
map[string]string{ | ||
"device": "Disk1", | ||
"model": "Model1", | ||
"unit": "C", | ||
"status": "", | ||
}, | ||
}, | ||
{ | ||
map[string]interface{}{ | ||
"temperature": int32(14), | ||
}, | ||
map[string]string{ | ||
"device": "Disk2", | ||
"model": "Model2", | ||
"unit": "C", | ||
"status": "", | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
acc.AssertContainsTaggedFields(t, "hddtemp", test.fields, test.tags) | ||
} | ||
|
||
} |