forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireboard_test.go
74 lines (64 loc) · 1.72 KB
/
fireboard_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package fireboard
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestFireboard(t *testing.T) {
// Create a test server with the const response JSON
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, response)
}))
defer ts.Close()
// Parse the URL of the test server, used to verify the expected host
u, err := url.Parse(ts.URL)
require.NoError(t, err)
// Create a new fb instance with our given test server
fireboard := NewFireboard()
fireboard.AuthToken = "b4bb6e6a7b6231acb9f71b304edb2274693d8849"
fireboard.URL = u.String()
// Create a test accumulator
acc := &testutil.Accumulator{}
// Gather data from the test server
err = fireboard.Gather(acc)
require.NoError(t, err)
// Expect the correct values for all known keys
expectFields := map[string]interface{}{
"temperature": float64(79.9),
}
// Expect the correct values for all tags
expectTags := map[string]string{
"title": "telegraf-FireBoard",
"uuid": "b55e766c-b308-49b5-93a4-df89fe31efd0",
"channel": strconv.FormatInt(1, 10),
"scale": "Fahrenheit",
}
acc.AssertContainsTaggedFields(t, "fireboard", expectFields, expectTags)
}
var response = `
[{
"id": 99999,
"title": "telegraf-FireBoard",
"created": "2019-03-23T16:48:32.152010Z",
"uuid": "b55e766c-b308-49b5-93a4-df89fe31efd0",
"hardware_id": "XXXXXXXXX",
"latest_temps": [
{
"temp": 79.9,
"channel": 1,
"degreetype": 2,
"created": "2019-06-25T06:07:10Z"
}
],
"last_templog": "2019-06-25T06:06:40Z",
"model": "FBX11E",
"channel_count": 6,
"degreetype": 2
}]
`