console: add an API to get the last received flow

This commit is contained in:
Vincent Bernat
2022-04-14 10:06:01 +02:00
parent 2bbeacec84
commit 4be33c70ba
12 changed files with 260 additions and 32 deletions

View File

@@ -7,6 +7,8 @@ import (
"strings"
"testing"
"akvorado/common/daemon"
"akvorado/common/helpers"
"akvorado/common/http"
"akvorado/common/reporter"
)
@@ -28,29 +30,31 @@ func TestServeDocs(t *testing.T) {
t.Run(fmt.Sprintf("%s-%s", name, tc.Path), func(t *testing.T) {
r := reporter.NewMock(t)
h := http.NewMock(t, r)
_, err := New(r, Configuration{
c, err := New(r, Configuration{
ServeLiveFS: live,
}, Dependencies{
HTTP: h,
Daemon: daemon.NewMock(t),
HTTP: h,
})
if err != nil {
t.Fatalf("New() error:\n%+v", err)
}
helpers.StartStop(t, c)
resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/docs/%s",
resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/console/docs/%s",
h.Address, tc.Path))
if err != nil {
t.Fatalf("GET /api/v0/docs/%s:\n%+v", tc.Path, err)
t.Fatalf("GET /api/v0/console/docs/%s:\n%+v", tc.Path, err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Errorf("GET /api/v0/docs/%s: got status code %d, not 200",
t.Errorf("GET /api/v0/console/docs/%s: got status code %d, not 200",
tc.Path, resp.StatusCode)
}
body, _ := ioutil.ReadAll(resp.Body)
if !strings.Contains(string(body), tc.Expect) {
t.Logf("Body:\n%s", string(body))
t.Errorf("GET /api/v0/docs/%s: does not contain %q",
t.Errorf("GET /api/v0/console/docs/%s: does not contain %q",
tc.Path, tc.Expect)
}
})