MCPcopy
hub / github.com/elastic/go-elasticsearch / TestBulkIndexer

Function TestBulkIndexer

esutil/bulk_indexer_internal_test.go:65–1659  ·  view source on GitHub ↗

nolint:gocyclo

(t *testing.T)

Source from the content-addressed store, hash-verified

63
64//nolint:gocyclo
65func TestBulkIndexer(t *testing.T) {
66 t.Run("Basic", func(t *testing.T) {
67 tests := []struct {
68 name string
69 makeClient func(cfg elasticsearch.Config) (esapi.Transport, error)
70 }{
71 {
72 name: "Client",
73 makeClient: func(cfg elasticsearch.Config) (esapi.Transport, error) {
74 return elasticsearch.NewClient(cfg)
75 },
76 },
77 {
78 name: "TypedClient",
79 makeClient: func(cfg elasticsearch.Config) (esapi.Transport, error) {
80 return elasticsearch.NewTypedClient(cfg)
81 },
82 },
83 }
84 for _, tt := range tests {
85 tt := tt
86
87 t.Run(tt.name, func(t *testing.T) {
88 var (
89 wg sync.WaitGroup
90
91 countReqs int
92 testfile string
93 numItems = 6
94 )
95
96 es, err := tt.makeClient(elasticsearch.Config{Transport: &mockTransport{
97 RoundTripFunc: func(*http.Request) (*http.Response, error) {
98 countReqs++
99 switch countReqs {
100 case 1:
101 testfile = "testdata/bulk_response_1a.json"
102 case 2:
103 testfile = "testdata/bulk_response_1b.json"
104 case 3:
105 testfile = "testdata/bulk_response_1c.json"
106 }
107 bodyContent, err := os.ReadFile(testfile)
108 if err != nil {
109 t.Fatalf("Unexpected error: %s", err)
110 }
111 return &http.Response{
112 Body: io.NopCloser(bytes.NewBuffer(bodyContent)),
113 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
114 }, nil
115 },
116 }})
117
118 if err != nil {
119 t.Errorf("Unexpected error: %s", err)
120 }
121
122 cfg := BulkIndexerConfig{

Callers

nothing calls this directly

Calls 15

AddMethod · 0.95
CloseMethod · 0.95
StatsMethod · 0.95
writeMetaMethod · 0.95
IntPtrFunction · 0.92
NewBulkIndexerFunction · 0.85
contextKeyTypeAlias · 0.85
IsMethod · 0.80
PrintfMethod · 0.80
DurationMethod · 0.80
marshallMetaMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected