Support custom success codes in http input (#6549)
This commit is contained in:
committed by
Daniel Nelson
parent
3802c8b8cb
commit
a01d273c45
@@ -106,6 +106,30 @@ func TestInvalidStatusCode(t *testing.T) {
|
||||
require.Error(t, acc.GatherError(plugin.Gather))
|
||||
}
|
||||
|
||||
func TestSuccessStatusCodes(t *testing.T) {
|
||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}))
|
||||
defer fakeServer.Close()
|
||||
|
||||
url := fakeServer.URL + "/endpoint"
|
||||
plugin := &plugin.HTTP{
|
||||
URLs: []string{url},
|
||||
SuccessStatusCodes: []int{200, 202},
|
||||
}
|
||||
|
||||
metricName := "metricName"
|
||||
p, _ := parsers.NewParser(&parsers.Config{
|
||||
DataFormat: "json",
|
||||
MetricName: metricName,
|
||||
})
|
||||
plugin.SetParser(p)
|
||||
|
||||
var acc testutil.Accumulator
|
||||
plugin.Init()
|
||||
require.NoError(t, acc.GatherError(plugin.Gather))
|
||||
}
|
||||
|
||||
func TestMethod(t *testing.T) {
|
||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
|
||||
Reference in New Issue
Block a user