forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 5
/
warp10_test.go
105 lines (97 loc) · 2.62 KB
/
warp10_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package warp10
import (
"fmt"
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
type ErrorTest struct {
Message string
Expected string
}
func TestWriteWarp10(t *testing.T) {
w := Warp10{
Prefix: "unit.test",
WarpURL: "http://localhost:8090",
Token: "WRITE",
}
payload := w.GenWarp10Payload(testutil.MockMetrics())
require.Exactly(t, "1257894000000000// unit.testtest1.value{source=telegraf,tag1=value1} 1.000000\n", payload)
}
func TestHandleWarp10Error(t *testing.T) {
w := Warp10{
Prefix: "unit.test",
WarpURL: "http://localhost:8090",
Token: "WRITE",
}
tests := [...]*ErrorTest{
{
Message: `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 io.warp10.script.WarpScriptException: Invalid token.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /api/v0/update. Reason:
<pre> io.warp10.script.WarpScriptException: Invalid token.</pre></p>
</body>
</html>
`,
Expected: fmt.Sprintf("Invalid token"),
},
{
Message: `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 io.warp10.script.WarpScriptException: Token Expired.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /api/v0/update. Reason:
<pre> io.warp10.script.WarpScriptException: Token Expired.</pre></p>
</body>
</html>
`,
Expected: fmt.Sprintf("Token Expired"),
},
{
Message: `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 io.warp10.script.WarpScriptException: Token revoked.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /api/v0/update. Reason:
<pre> io.warp10.script.WarpScriptException: Token revoked.</pre></p>
</body>
</html>
`,
Expected: fmt.Sprintf("Token revoked"),
},
{
Message: `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 io.warp10.script.WarpScriptException: Write token missing.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /api/v0/update. Reason:
<pre> io.warp10.script.WarpScriptException: Write token missing.</pre></p>
</body>
</html>
`,
Expected: "Write token missing",
},
{
Message: `<title>Error 503: server unavailable</title>`,
Expected: "<title>Error 503: server unavailable</title>",
},
}
for _, handledError := range tests {
payload := w.HandleError(handledError.Message, 511)
require.Exactly(t, handledError.Expected, payload)
}
}