-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathelasticClientScroll_test.go
More file actions
39 lines (32 loc) · 950 Bytes
/
elasticClientScroll_test.go
File metadata and controls
39 lines (32 loc) · 950 Bytes
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
package client
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/elastic/go-elasticsearch/v7"
"github.com/multiversx/mx-chain-es-indexer-go/client/logging"
"github.com/stretchr/testify/require"
)
func TestElasticClient_DoCountRequest(t *testing.T) {
handler := http.NotFound
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler(w, r)
}))
defer ts.Close()
handler = func(w http.ResponseWriter, r *http.Request) {
jsonFile, err := os.Open("./testsData/response-count-request.json")
require.Nil(t, err)
byteValue, _ := io.ReadAll(jsonFile)
_, _ = w.Write(byteValue)
}
esClient, _ := NewElasticClient(elasticsearch.Config{
Addresses: []string{ts.URL},
Logger: &logging.CustomLogger{},
})
count, err := esClient.DoCountRequest(context.Background(), "tokens", []byte(`{}`))
require.Nil(t, err)
require.Equal(t, uint64(112671), count)
}