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

Function TestInstrumentation

elasticsearch_internal_test.go:1240–1471  ·  view source on GitHub ↗

nolint:gocyclo

(t *testing.T)

Source from the content-addressed store, hash-verified

1238
1239//nolint:gocyclo
1240func TestInstrumentation(t *testing.T) {
1241 successTp := func(_ *http.Request) (*http.Response, error) {
1242 h := http.Header{}
1243 h.Add("X-Elastic-Product", "Elasticsearch")
1244 h.Add("X-Found-Handling-Cluster", "foo-bar-cluster-id")
1245 h.Add("X-Found-Handling-Instance", "0123456789")
1246 return &http.Response{
1247 StatusCode: http.StatusOK,
1248 Header: h,
1249 Body: io.NopCloser(strings.NewReader(`{}`)),
1250 }, nil
1251 }
1252
1253 errorTp := func(_ *http.Request) (*http.Response, error) {
1254 h := http.Header{}
1255 h.Add("X-Elastic-Product", "Elasticsearch")
1256 h.Add("X-Found-Handling-Cluster", "foo-bar-cluster-id")
1257 h.Add("X-Found-Handling-Instance", "0123456789")
1258 return &http.Response{
1259 StatusCode: http.StatusNotFound,
1260 Header: h,
1261 Body: io.NopCloser(strings.NewReader(`{
1262 "error": {
1263 "root_cause": [
1264 {
1265 "type": "index_not_found_exception",
1266 "reason": "no such index [foo]",
1267 "resource.type": "index_or_alias",
1268 "resource.id": "foo",
1269 "index_uuid": "_na_",
1270 "index": "foo"
1271 }
1272 ],
1273 "type": "index_not_found_exception",
1274 "reason": "no such index [foo]",
1275 "resource.type": "index_or_alias",
1276 "resource.id": "foo",
1277 "index_uuid": "_na_",
1278 "index": "foo"
1279 },
1280 "status": 404
1281}`)),
1282 }, nil
1283 }
1284
1285 reason := "index_not_found_exception"
1286
1287 type args struct {
1288 roundTripFunc func(request *http.Request) (*http.Response, error)
1289 instrumentation *FakeInstrumentation
1290 }
1291 tests := []struct {
1292 name string
1293 args args
1294 want *FakeInstrumentation
1295 }{
1296 {
1297 name: "with query",

Callers

nothing calls this directly

Calls 15

NewMatchAllQueryFunction · 0.92
NewFakeInstrumentationFunction · 0.85
NewTypedFunction · 0.85
WithTransportOptionsFunction · 0.85
WithInstrumentationFunction · 0.85
IsMethod · 0.80
AddMethod · 0.65
DoMethod · 0.65
NewFunction · 0.50
RunMethod · 0.45
QueryMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected