-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse kibana api response in search of errors
- Loading branch information
1 parent
489e9be
commit e54969f
Showing
2 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package kibana | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestErrorJson(t *testing.T) { | ||
// also common 200: {"objects":[{"id":"apm-*","type":"index-pattern","error":{"message":"[doc][index-pattern:test-*]: version conflict, document already exists (current version [1])"}}]} | ||
kibanaTs := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{"objects":[{"id":"test-*","type":"index-pattern","error":{"message":"action [indices:data/write/bulk[s]] is unauthorized for user [test]"}}]}`)) | ||
})) | ||
defer kibanaTs.Close() | ||
|
||
conn := Connection{ | ||
URL: kibanaTs.URL, | ||
http: http.DefaultClient, | ||
} | ||
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil) | ||
assert.Equal(t, http.StatusOK, code) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestErrorBadJson(t *testing.T) { | ||
kibanaTs := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{`)) | ||
})) | ||
defer kibanaTs.Close() | ||
|
||
conn := Connection{ | ||
URL: kibanaTs.URL, | ||
http: http.DefaultClient, | ||
} | ||
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil) | ||
assert.Equal(t, http.StatusOK, code) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestSuccess(t *testing.T) { | ||
kibanaTs := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{"objects":[{"id":"test-*","type":"index-pattern","updated_at":"2018-01-24T19:04:13.371Z","version":1}]}`)) | ||
})) | ||
defer kibanaTs.Close() | ||
|
||
conn := Connection{ | ||
URL: kibanaTs.URL, | ||
http: http.DefaultClient, | ||
} | ||
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil) | ||
assert.Equal(t, http.StatusOK, code) | ||
assert.NoError(t, err) | ||
} |