From 03927e6188420fa7e993f43233cafeb81db3ce56 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Mon, 23 Sep 2024 19:10:50 +0200 Subject: [PATCH] Return HTTP response as second value from typed client functions Signed-off-by: Stefano Arlandini --- internal/test/helper.go | 2 +- opensearchapi/api_aliases.go | 21 +- opensearchapi/api_aliases_test.go | 19 +- opensearchapi/api_bulk.go | 27 +- opensearchapi/api_bulk_test.go | 18 +- opensearchapi/api_cat-aliases.go | 10 +- opensearchapi/api_cat-allocation.go | 8 - opensearchapi/api_cat-cluster_manager.go | 8 - opensearchapi/api_cat-count.go | 10 +- opensearchapi/api_cat-fielddata.go | 8 - opensearchapi/api_cat-health.go | 10 +- opensearchapi/api_cat-indices.go | 10 +- opensearchapi/api_cat-master.go | 10 +- opensearchapi/api_cat-nodeattrs.go | 8 - opensearchapi/api_cat-nodes.go | 10 +- opensearchapi/api_cat-pending_tasks.go | 8 - opensearchapi/api_cat-plugins.go | 10 +- opensearchapi/api_cat-recovery.go | 8 - opensearchapi/api_cat-repositories.go | 8 - opensearchapi/api_cat-segments.go | 8 - opensearchapi/api_cat-shards.go | 10 +- opensearchapi/api_cat-snapshots.go | 8 - opensearchapi/api_cat-tasks.go | 10 +- opensearchapi/api_cat-templates.go | 8 - opensearchapi/api_cat-thread_pool.go | 8 - opensearchapi/api_cat.go | 301 +++++++-------- opensearchapi/api_cat_test.go | 214 +++++------ .../api_cluster-allocation_explain.go | 6 - opensearchapi/api_cluster-decommission.go | 20 +- opensearchapi/api_cluster-health.go | 6 - opensearchapi/api_cluster-pending_tasks.go | 8 +- opensearchapi/api_cluster-remote_info.go | 6 - opensearchapi/api_cluster-reroute.go | 6 - opensearchapi/api_cluster-settings.go | 12 - opensearchapi/api_cluster-state.go | 6 - opensearchapi/api_cluster-stats.go | 6 - opensearchapi/api_cluster.go | 183 +++++---- opensearchapi/api_cluster_test.go | 82 +++-- .../api_component_template-create.go | 6 - .../api_component_template-delete.go | 6 - opensearchapi/api_component_template-get.go | 6 - opensearchapi/api_component_template.go | 45 ++- opensearchapi/api_component_template_test.go | 52 ++- opensearchapi/api_dangling-delete.go | 6 - opensearchapi/api_dangling-get.go | 6 - opensearchapi/api_dangling-import.go | 6 - opensearchapi/api_dangling.go | 46 ++- opensearchapi/api_dangling_test.go | 40 +- opensearchapi/api_datastream-create.go | 6 - opensearchapi/api_datastream-delete.go | 6 - opensearchapi/api_datastream-get.go | 6 - opensearchapi/api_datastream-stats.go | 6 - opensearchapi/api_datastream.go | 61 ++- opensearchapi/api_datastream_test.go | 34 +- opensearchapi/api_document-create.go | 6 - opensearchapi/api_document-delete.go | 6 - opensearchapi/api_document-delete_by_query.go | 6 - ...api_document-delete_by_query_rethrottle.go | 6 - opensearchapi/api_document-explain.go | 6 - opensearchapi/api_document-get.go | 6 - opensearchapi/api_document-source.go | 8 +- opensearchapi/api_document.go | 108 +++--- opensearchapi/api_document_test.go | 120 +++--- opensearchapi/api_index.go | 21 +- opensearchapi/api_index_template-create.go | 6 - opensearchapi/api_index_template-delete.go | 6 - opensearchapi/api_index_template-get.go | 6 - opensearchapi/api_index_template-simulate.go | 6 - .../api_index_template-simulate_index.go | 6 - opensearchapi/api_index_template.go | 78 ++-- opensearchapi/api_index_template_test.go | 58 ++- opensearchapi/api_index_test.go | 29 +- opensearchapi/api_indices-alias.go | 63 ++-- opensearchapi/api_indices-analyze.go | 6 - opensearchapi/api_indices-block.go | 6 - opensearchapi/api_indices-cache.go | 6 - opensearchapi/api_indices-clone.go | 6 - opensearchapi/api_indices-close.go | 6 - opensearchapi/api_indices-count.go | 8 +- opensearchapi/api_indices-create.go | 6 - opensearchapi/api_indices-delete.go | 6 - opensearchapi/api_indices-field_caps.go | 6 - opensearchapi/api_indices-flush.go | 6 - opensearchapi/api_indices-forcemerge.go | 6 - opensearchapi/api_indices-get.go | 6 - opensearchapi/api_indices-mapping.go | 63 ++-- opensearchapi/api_indices-open.go | 6 - opensearchapi/api_indices-recovery.go | 6 - opensearchapi/api_indices-refresh.go | 6 - opensearchapi/api_indices-resolve.go | 6 - opensearchapi/api_indices-rollover.go | 6 - opensearchapi/api_indices-segments.go | 6 - opensearchapi/api_indices-settings.go | 43 +-- opensearchapi/api_indices-shardstores.go | 6 - opensearchapi/api_indices-shrink.go | 6 - opensearchapi/api_indices-split.go | 6 - opensearchapi/api_indices-stats.go | 12 +- opensearchapi/api_indices-validate.go | 6 - opensearchapi/api_indices.go | 345 ++++++++--------- opensearchapi/api_indices_test.go | 348 ++++++++++-------- opensearchapi/api_info.go | 23 +- opensearchapi/api_info_test.go | 17 +- opensearchapi/api_ingest-create.go | 6 - opensearchapi/api_ingest-delete.go | 6 - opensearchapi/api_ingest-get.go | 6 - opensearchapi/api_ingest-grok.go | 6 - opensearchapi/api_ingest-simulate.go | 8 +- opensearchapi/api_ingest.go | 76 ++-- opensearchapi/api_ingest_test.go | 43 +-- opensearchapi/api_mget.go | 21 +- opensearchapi/api_mget_test.go | 14 +- opensearchapi/api_msearch-template.go | 21 +- opensearchapi/api_msearch-template_test.go | 14 +- opensearchapi/api_msearch.go | 21 +- opensearchapi/api_msearch_test.go | 14 +- opensearchapi/api_mtermvectors.go | 21 +- opensearchapi/api_mtermvectors_test.go | 16 +- opensearchapi/api_nodes-info.go | 6 - opensearchapi/api_nodes-reload_security.go | 6 - opensearchapi/api_nodes-stats.go | 6 - opensearchapi/api_nodes-usage.go | 6 - opensearchapi/api_nodes.go | 60 ++- opensearchapi/api_nodes_test.go | 75 ++-- opensearchapi/api_ping_test.go | 9 +- opensearchapi/api_point_in_time-create.go | 6 - opensearchapi/api_point_in_time-delete.go | 6 - opensearchapi/api_point_in_time-get.go | 6 - opensearchapi/api_point_in_time.go | 46 ++- opensearchapi/api_point_in_time_test.go | 32 +- opensearchapi/api_rank_eval.go | 21 +- opensearchapi/api_rank_eval_test.go | 14 +- opensearchapi/api_reindex.go | 21 +- opensearchapi/api_reindex_rethrottle.go | 21 +- opensearchapi/api_reindex_rethrottle_test.go | 14 +- opensearchapi/api_reindex_test.go | 17 +- opensearchapi/api_render_search_template.go | 21 +- .../api_render_search_template_test.go | 14 +- opensearchapi/api_script-context.go | 6 - opensearchapi/api_script-delete.go | 6 - opensearchapi/api_script-get.go | 6 - opensearchapi/api_script-language.go | 6 - opensearchapi/api_script-painless_execute.go | 8 +- opensearchapi/api_script-put.go | 6 - opensearchapi/api_script.go | 91 +++-- opensearchapi/api_script_test.go | 68 ++-- opensearchapi/api_scroll-delete.go | 6 - opensearchapi/api_scroll-get.go | 6 - opensearchapi/api_scroll.go | 31 +- opensearchapi/api_scroll_test.go | 26 +- opensearchapi/api_search-template.go | 21 +- opensearchapi/api_search-template_test.go | 14 +- opensearchapi/api_search.go | 21 +- opensearchapi/api_search_shards.go | 21 +- opensearchapi/api_search_shards_test.go | 19 +- opensearchapi/api_search_test.go | 37 +- opensearchapi/api_snapshot-clone.go | 6 - opensearchapi/api_snapshot-create.go | 6 - opensearchapi/api_snapshot-delete.go | 6 - opensearchapi/api_snapshot-get.go | 6 - opensearchapi/api_snapshot-restore.go | 6 - opensearchapi/api_snapshot-status.go | 6 - opensearchapi/api_snapshot.go | 95 +++-- .../api_snapshot_repository-cleanup.go | 6 - .../api_snapshot_repository-create.go | 6 - .../api_snapshot_repository-delete.go | 6 - opensearchapi/api_snapshot_repository-get.go | 6 - .../api_snapshot_repository-verify.go | 6 - opensearchapi/api_snapshot_repository.go | 76 ++-- opensearchapi/api_snapshot_test.go | 69 ++-- opensearchapi/api_tasks-cancel.go | 6 - opensearchapi/api_tasks-get.go | 6 - opensearchapi/api_tasks-list.go | 6 - opensearchapi/api_tasks.go | 46 ++- opensearchapi/api_tasks_test.go | 30 +- opensearchapi/api_template-create.go | 6 - opensearchapi/api_template-delete.go | 6 - opensearchapi/api_template-get.go | 6 - opensearchapi/api_template.go | 45 ++- opensearchapi/api_template_test.go | 60 ++- opensearchapi/api_termvectors.go | 21 +- opensearchapi/api_termvectors_test.go | 16 +- opensearchapi/api_update.go | 21 +- opensearchapi/api_update_by_query.go | 21 +- .../api_update_by_query_rethrottle.go | 21 +- .../api_update_by_query_rethrottle_test.go | 14 +- opensearchapi/api_update_by_query_test.go | 14 +- opensearchapi/api_update_test.go | 14 +- opensearchapi/inspect.go | 14 - opensearchapi/internal/test/helper.go | 25 +- opensearchutil/bulk_indexer.go | 2 +- 190 files changed, 1911 insertions(+), 2889 deletions(-) delete mode 100644 opensearchapi/inspect.go diff --git a/internal/test/helper.go b/internal/test/helper.go index 1cd2780f5..da237197d 100644 --- a/internal/test/helper.go +++ b/internal/test/helper.go @@ -93,7 +93,7 @@ func GetPassword() (string, error) { // GetVersion gets cluster info and returns version as int's func GetVersion(client *opensearchapi.Client) (int64, int64, int64, error) { - resp, err := client.Info(context.Background(), nil) + resp, _, err := client.Info(context.Background(), nil) if err != nil { return 0, 0, 0, err } diff --git a/opensearchapi/api_aliases.go b/opensearchapi/api_aliases.go index 5967894b6..f6f53bedf 100644 --- a/opensearchapi/api_aliases.go +++ b/opensearchapi/api_aliases.go @@ -15,16 +15,15 @@ import ( ) // Aliases executes an /_aliases request with the required AliasesReq -func (c Client) Aliases(ctx context.Context, req AliasesReq) (*AliasesResp, error) { - var ( - data AliasesResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Aliases(ctx context.Context, req AliasesReq) (*AliasesResp, *opensearch.Response, error) { + var data AliasesResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // AliasesReq represents possible options for the / request @@ -49,10 +48,4 @@ func (r AliasesReq) GetRequest() (*http.Request, error) { // AliasesResp represents the returned struct of the / response type AliasesResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r AliasesResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_aliases_test.go b/opensearchapi/api_aliases_test.go index f6da66664..daaaee184 100644 --- a/opensearchapi/api_aliases_test.go +++ b/opensearchapi/api_aliases_test.go @@ -29,30 +29,31 @@ func TestAliases(t *testing.T) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{index}}) }) - _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) + _, _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) require.Nil(t, err) t.Run("with request", func(t *testing.T) { - resp, err := client.Aliases( + resp, httpResp, err := client.Aliases( nil, opensearchapi.AliasesReq{ Body: strings.NewReader(`{"actions":[{"add":{"index":"test-aliases","alias":"logs"}},{"remove":{"index":"test-aliases","alias":"logs"}}]}`), }, ) require.Nil(t, err) - require.NotEmpty(t, resp) - require.NotEmpty(t, resp.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + require.NotNil(t, resp) + require.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) - t.Run("inspect", func(t *testing.T) { + t.Run("with failing request", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Aliases(nil, opensearchapi.AliasesReq{}) + res, httpResp, err := failingClient.Aliases(nil, opensearchapi.AliasesReq{}) require.NotNil(t, err) - require.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + require.NotNil(t, httpResp) + require.Nil(t, res) + osapitest.VerifyResponse(t, httpResp) }) }) } diff --git a/opensearchapi/api_bulk.go b/opensearchapi/api_bulk.go index 854c07fd9..ebb2681f4 100644 --- a/opensearchapi/api_bulk.go +++ b/opensearchapi/api_bulk.go @@ -16,16 +16,15 @@ import ( ) // Bulk executes a /_bulk request with the needed BulkReq -func (c Client) Bulk(ctx context.Context, req BulkReq) (*BulkResp, error) { - var ( - data BulkResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Bulk(ctx context.Context, req BulkReq) (*BulkResp, *opensearch.Response, error) { + var data BulkResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // BulkReq represents possible options for the /_bulk request @@ -60,10 +59,9 @@ func (r BulkReq) GetRequest() (*http.Request, error) { // BulkResp represents the returned struct of the /_bulk response type BulkResp struct { - Took int `json:"took"` - Errors bool `json:"errors"` - Items []map[string]BulkRespItem `json:"items"` - response *opensearch.Response + Took int `json:"took"` + Errors bool `json:"errors"` + Items []map[string]BulkRespItem `json:"items"` } // BulkRespItem represents an item of the BulkResp @@ -102,8 +100,3 @@ type BulkRespItem struct { } `json:"caused_by,omitempty"` } `json:"error,omitempty"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r BulkResp) Inspect() Inspect { - return Inspect{Response: r.response} -} diff --git a/opensearchapi/api_bulk_test.go b/opensearchapi/api_bulk_test.go index 67d929334..bb133b0c2 100644 --- a/opensearchapi/api_bulk_test.go +++ b/opensearchapi/api_bulk_test.go @@ -53,22 +53,24 @@ func TestBulkClient(t *testing.T) { for _, test := range tests { t.Run(test.Name, func(t *testing.T) { - res, err := client.Bulk( + res, httpResp, err := client.Bulk( nil, test.Request, ) require.Nil(t, err) - assert.NotEmpty(t, res) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + assert.NotNil(t, res) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, res, httpResp) }) } - t.Run("inspect", func(t *testing.T) { + t.Run("with failing request", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Bulk(nil, opensearchapi.BulkReq{Index: index}) - assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + res, httpResp, err := failingClient.Bulk(nil, opensearchapi.BulkReq{Index: index}) + require.NotNil(t, err) + require.NotNil(t, httpResp) + require.Nil(t, res) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_cat-aliases.go b/opensearchapi/api_cat-aliases.go index a4485a68c..e86537fbd 100644 --- a/opensearchapi/api_cat-aliases.go +++ b/opensearchapi/api_cat-aliases.go @@ -41,8 +41,7 @@ func (r CatAliasesReq) GetRequest() (*http.Request, error) { // CatAliasesResp represents the returned struct of the /_cat/aliases response type CatAliasesResp struct { - Aliases []CatAliasResp - response *opensearch.Response + Aliases []CatAliasResp } // CatAliasResp represents one index of the CatAliasesResp @@ -54,10 +53,3 @@ type CatAliasResp struct { RoutingSearch string `json:"routing.search"` IsWriteIndex string `json:"is_write_index"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatAliasesResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-allocation.go b/opensearchapi/api_cat-allocation.go index 899533fe6..c7878111f 100644 --- a/opensearchapi/api_cat-allocation.go +++ b/opensearchapi/api_cat-allocation.go @@ -42,7 +42,6 @@ func (r CatAllocationReq) GetRequest() (*http.Request, error) { // CatAllocationsResp represents the returned struct of the /_cat/allocation response type CatAllocationsResp struct { Allocations []CatAllocationResp - response *opensearch.Response } // CatAllocationResp represents one index of the CatAllocationResp @@ -58,10 +57,3 @@ type CatAllocationResp struct { IP *string `json:"ip"` Node string `json:"node"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatAllocationsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-cluster_manager.go b/opensearchapi/api_cat-cluster_manager.go index bf03671c2..08e7ab871 100644 --- a/opensearchapi/api_cat-cluster_manager.go +++ b/opensearchapi/api_cat-cluster_manager.go @@ -32,7 +32,6 @@ func (r CatClusterManagerReq) GetRequest() (*http.Request, error) { // CatClusterManagersResp represents the returned struct of the /_cat/cluster_manager response type CatClusterManagersResp struct { ClusterManagers []CatClusterManagerResp - response *opensearch.Response } // CatClusterManagerResp represents one index of the CatClusterManagerResp @@ -42,10 +41,3 @@ type CatClusterManagerResp struct { IP string `json:"ip"` Node string `json:"node"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatClusterManagersResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-count.go b/opensearchapi/api_cat-count.go index 083424581..0a29c5218 100644 --- a/opensearchapi/api_cat-count.go +++ b/opensearchapi/api_cat-count.go @@ -41,8 +41,7 @@ func (r CatCountReq) GetRequest() (*http.Request, error) { // CatCountsResp represents the returned struct of the /_cat/count response type CatCountsResp struct { - Counts []CatCountResp - response *opensearch.Response + Counts []CatCountResp } // CatCountResp represents one index of the CatCountResp @@ -51,10 +50,3 @@ type CatCountResp struct { Timestamp string `json:"timestamp"` Count int `json:"count,string"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatCountsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-fielddata.go b/opensearchapi/api_cat-fielddata.go index 7ddefd179..e27452a5d 100644 --- a/opensearchapi/api_cat-fielddata.go +++ b/opensearchapi/api_cat-fielddata.go @@ -42,7 +42,6 @@ func (r CatFieldDataReq) GetRequest() (*http.Request, error) { // CatFieldDataResp represents the returned struct of the /_cat/fielddata response type CatFieldDataResp struct { FieldData []CatFieldDataItemResp - response *opensearch.Response } // CatFieldDataItemResp represents one index of the CatFieldDataResp @@ -54,10 +53,3 @@ type CatFieldDataItemResp struct { Field string `json:"field"` Size string `json:"size"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatFieldDataResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-health.go b/opensearchapi/api_cat-health.go index 2ffe0f318..26966e5da 100644 --- a/opensearchapi/api_cat-health.go +++ b/opensearchapi/api_cat-health.go @@ -31,8 +31,7 @@ func (r CatHealthReq) GetRequest() (*http.Request, error) { // CatHealthResp represents the returned struct of the /_cat/health response type CatHealthResp struct { - Health []CatHealthItemResp - response *opensearch.Response + Health []CatHealthItemResp } // CatHealthItemResp represents one index of the CatHealthResp @@ -54,10 +53,3 @@ type CatHealthItemResp struct { MaxTaskWaitTime string `json:"max_task_wait_time"` ActiveShardsPercent string `json:"active_shards_percent"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatHealthResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-indices.go b/opensearchapi/api_cat-indices.go index 28ddc18ea..329d5ef34 100644 --- a/opensearchapi/api_cat-indices.go +++ b/opensearchapi/api_cat-indices.go @@ -41,8 +41,7 @@ func (r CatIndicesReq) GetRequest() (*http.Request, error) { // CatIndicesResp represents the returned struct of the /_cat/indices response type CatIndicesResp struct { - Indices []CatIndexResp - response *opensearch.Response + Indices []CatIndexResp } // CatIndexResp represents one index of the CatIndicesResp @@ -194,10 +193,3 @@ type CatIndexResp struct { PrimaryMemoryTotal string `json:"pri.memory.total"` SearchThrottled bool `json:"search.throttled,string"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatIndicesResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-master.go b/opensearchapi/api_cat-master.go index 0ff98fbfd..ccc8469d7 100644 --- a/opensearchapi/api_cat-master.go +++ b/opensearchapi/api_cat-master.go @@ -31,8 +31,7 @@ func (r CatMasterReq) GetRequest() (*http.Request, error) { // CatMasterResp represents the returned struct of the /_cat/master response type CatMasterResp struct { - Master []CatMasterItemResp - response *opensearch.Response + Master []CatMasterItemResp } // CatMasterItemResp represents one index of the CatMasterResp @@ -42,10 +41,3 @@ type CatMasterItemResp struct { IP string `json:"ip"` Node string `json:"node"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatMasterResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-nodeattrs.go b/opensearchapi/api_cat-nodeattrs.go index 378589358..9b013e07e 100644 --- a/opensearchapi/api_cat-nodeattrs.go +++ b/opensearchapi/api_cat-nodeattrs.go @@ -32,7 +32,6 @@ func (r CatNodeAttrsReq) GetRequest() (*http.Request, error) { // CatNodeAttrsResp represents the returned struct of the /_cat/nodeattrs response type CatNodeAttrsResp struct { NodeAttrs []CatNodeAttrsItemResp - response *opensearch.Response } // CatNodeAttrsItemResp represents one index of the CatNodeAttrsResp @@ -46,10 +45,3 @@ type CatNodeAttrsItemResp struct { Attr string `json:"attr"` Value string `json:"value"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatNodeAttrsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-nodes.go b/opensearchapi/api_cat-nodes.go index 207431c06..8f9e43392 100644 --- a/opensearchapi/api_cat-nodes.go +++ b/opensearchapi/api_cat-nodes.go @@ -31,8 +31,7 @@ func (r CatNodesReq) GetRequest() (*http.Request, error) { // CatNodesResp represents the returned struct of the /_cat/nodes response type CatNodesResp struct { - Nodes []CatNodesItemResp - response *opensearch.Response + Nodes []CatNodesItemResp } // CatNodesItemResp represents one index of the CatNodesResp @@ -137,10 +136,3 @@ type CatNodesItemResp struct { SuggestTime *string `json:"suggest.time"` SuggestTotal *int `json:"suggest.total,string"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatNodesResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-pending_tasks.go b/opensearchapi/api_cat-pending_tasks.go index 4c43cce8a..477b981f4 100644 --- a/opensearchapi/api_cat-pending_tasks.go +++ b/opensearchapi/api_cat-pending_tasks.go @@ -32,7 +32,6 @@ func (r CatPendingTasksReq) GetRequest() (*http.Request, error) { // CatPendingTasksResp represents the returned struct of the /_cat/pending_tasks response type CatPendingTasksResp struct { PendingTasks []CatPendingTaskResp - response *opensearch.Response } // CatPendingTaskResp represents one index of the CatPendingTasksResp @@ -42,10 +41,3 @@ type CatPendingTaskResp struct { Priority string `json:"priority"` Source string `json:"source"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatPendingTasksResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-plugins.go b/opensearchapi/api_cat-plugins.go index 08035c30d..0a531932d 100644 --- a/opensearchapi/api_cat-plugins.go +++ b/opensearchapi/api_cat-plugins.go @@ -31,8 +31,7 @@ func (r CatPluginsReq) GetRequest() (*http.Request, error) { // CatPluginsResp represents the returned struct of the /_cat/plugins response type CatPluginsResp struct { - Plugins []CatPluginResp - response *opensearch.Response + Plugins []CatPluginResp } // CatPluginResp represents one index of the CatPluginsResp @@ -43,10 +42,3 @@ type CatPluginResp struct { Version string `json:"version,omitempty"` Description string `json:"description,omitempty"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatPluginsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-recovery.go b/opensearchapi/api_cat-recovery.go index 10a82cebb..f94ac0f4f 100644 --- a/opensearchapi/api_cat-recovery.go +++ b/opensearchapi/api_cat-recovery.go @@ -42,7 +42,6 @@ func (r CatRecoveryReq) GetRequest() (*http.Request, error) { // CatRecoveryResp represents the returned struct of the /_cat/recovery response type CatRecoveryResp struct { Recovery []CatRecoveryItemResp - response *opensearch.Response } // CatRecoveryItemResp represents one index of the CatRecoveryResp @@ -74,10 +73,3 @@ type CatRecoveryItemResp struct { TranslogOpsRecovered int `json:"translog_ops_recovered,string"` TranslogOpsPercent string `json:"translog_ops_percent"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatRecoveryResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-repositories.go b/opensearchapi/api_cat-repositories.go index 35417890d..d257933ef 100644 --- a/opensearchapi/api_cat-repositories.go +++ b/opensearchapi/api_cat-repositories.go @@ -32,7 +32,6 @@ func (r CatRepositoriesReq) GetRequest() (*http.Request, error) { // CatRepositoriesResp represents the returned struct of the /_cat/repositories response type CatRepositoriesResp struct { Repositories []CatRepositorieResp - response *opensearch.Response } // CatRepositorieResp represents one index of the CatRepositoriesResp @@ -40,10 +39,3 @@ type CatRepositorieResp struct { ID string `json:"id"` Type string `json:"type"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatRepositoriesResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-segments.go b/opensearchapi/api_cat-segments.go index b4d6685a6..8ec71dcb1 100644 --- a/opensearchapi/api_cat-segments.go +++ b/opensearchapi/api_cat-segments.go @@ -42,7 +42,6 @@ func (r CatSegmentsReq) GetRequest() (*http.Request, error) { // CatSegmentsResp represents the returned struct of the /_cat/segments response type CatSegmentsResp struct { Segments []CatSegmentResp - response *opensearch.Response } // CatSegmentResp represents one index of the CatSegmentsResp @@ -63,10 +62,3 @@ type CatSegmentResp struct { Version string `json:"version"` Compound bool `json:"compound,string"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatSegmentsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-shards.go b/opensearchapi/api_cat-shards.go index bcbb1ef3e..b02dda483 100644 --- a/opensearchapi/api_cat-shards.go +++ b/opensearchapi/api_cat-shards.go @@ -41,8 +41,7 @@ func (r CatShardsReq) GetRequest() (*http.Request, error) { // CatShardsResp represents the returned struct of the /_cat/shards response type CatShardsResp struct { - Shards []CatShardResp - response *opensearch.Response + Shards []CatShardResp } // CatShardResp represents one index of the CatShardsResp @@ -128,10 +127,3 @@ type CatShardResp struct { PathState *string `json:"path.state"` DocsDeleted *int `json:"docs.deleted,string"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatShardsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-snapshots.go b/opensearchapi/api_cat-snapshots.go index 76c64854f..c56ea60a3 100644 --- a/opensearchapi/api_cat-snapshots.go +++ b/opensearchapi/api_cat-snapshots.go @@ -34,7 +34,6 @@ func (r CatSnapshotsReq) GetRequest() (*http.Request, error) { // CatSnapshotsResp represents the returned struct of the /_cat/snapshots response type CatSnapshotsResp struct { Snapshots []CatSnapshotResp - response *opensearch.Response } // CatSnapshotResp represents one index of the CatSnapshotsResp @@ -52,10 +51,3 @@ type CatSnapshotResp struct { TotalShards int `json:"total_shards,string"` Reason string `json:"reason"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatSnapshotsResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-tasks.go b/opensearchapi/api_cat-tasks.go index 5eecade16..4f216a857 100644 --- a/opensearchapi/api_cat-tasks.go +++ b/opensearchapi/api_cat-tasks.go @@ -31,8 +31,7 @@ func (r CatTasksReq) GetRequest() (*http.Request, error) { // CatTasksResp represents the returned struct of the /_cat/tasks response type CatTasksResp struct { - Tasks []CatTaskResp - response *opensearch.Response + Tasks []CatTaskResp } // CatTaskResp represents one index of the CatTasksResp @@ -53,10 +52,3 @@ type CatTaskResp struct { Version string `json:"version"` XOpaqueID string `json:"x_opaque_id"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatTasksResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-templates.go b/opensearchapi/api_cat-templates.go index 07b0db5f3..98bb171ca 100644 --- a/opensearchapi/api_cat-templates.go +++ b/opensearchapi/api_cat-templates.go @@ -42,7 +42,6 @@ func (r CatTemplatesReq) GetRequest() (*http.Request, error) { // CatTemplatesResp represents the returned struct of the /_cat/templates response type CatTemplatesResp struct { Templates []CatTemplateResp - response *opensearch.Response } // CatTemplateResp represents one index of the CatTemplatesResp @@ -53,10 +52,3 @@ type CatTemplateResp struct { Version *string `json:"version"` ComposedOf string `json:"composed_of"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatTemplatesResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat-thread_pool.go b/opensearchapi/api_cat-thread_pool.go index 37c29e5f0..9adecd077 100644 --- a/opensearchapi/api_cat-thread_pool.go +++ b/opensearchapi/api_cat-thread_pool.go @@ -42,7 +42,6 @@ func (r CatThreadPoolReq) GetRequest() (*http.Request, error) { // CatThreadPoolResp represents the returned struct of the /_cat/thread_pool response type CatThreadPoolResp struct { ThreadPool []CatThreadPoolItemResp - response *opensearch.Response } // CatThreadPoolItemResp represents one index of the CatThreadPoolResp @@ -69,10 +68,3 @@ type CatThreadPoolItemResp struct { KeepAlive *string `json:"keep_alive"` TotalWaitTime string `json:"total_wait_time"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r CatThreadPoolResp) Inspect() Inspect { - return Inspect{ - Response: r.response, - } -} diff --git a/opensearchapi/api_cat.go b/opensearchapi/api_cat.go index 7ddd0f4aa..5c97de2a6 100644 --- a/opensearchapi/api_cat.go +++ b/opensearchapi/api_cat.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type catClient struct { @@ -15,337 +16,317 @@ type catClient struct { } // Aliases executes a /_cat/aliases request with the optional CatAliasesReq -func (c catClient) Aliases(ctx context.Context, req *CatAliasesReq) (*CatAliasesResp, error) { +func (c catClient) Aliases(ctx context.Context, req *CatAliasesReq) (*CatAliasesResp, *opensearch.Response, error) { if req == nil { req = &CatAliasesReq{} } - var ( - data CatAliasesResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Aliases); err != nil { - return &data, err + var data CatAliasesResp + + resp, err := c.apiClient.do(ctx, req, &data.Aliases) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Allocation executes a /_cat/allocation request with the optional CatAllocationReq -func (c catClient) Allocation(ctx context.Context, req *CatAllocationReq) (*CatAllocationsResp, error) { +func (c catClient) Allocation(ctx context.Context, req *CatAllocationReq) (*CatAllocationsResp, *opensearch.Response, error) { if req == nil { req = &CatAllocationReq{} } - var ( - data CatAllocationsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Allocations); err != nil { - return &data, err + var data CatAllocationsResp + + resp, err := c.apiClient.do(ctx, req, &data.Allocations) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ClusterManager executes a /_cat/cluster_manager request with the optional CatClusterManagerReq -func (c catClient) ClusterManager(ctx context.Context, req *CatClusterManagerReq) (*CatClusterManagersResp, error) { +func (c catClient) ClusterManager(ctx context.Context, req *CatClusterManagerReq) (*CatClusterManagersResp, *opensearch.Response, error) { if req == nil { req = &CatClusterManagerReq{} } - var ( - data CatClusterManagersResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.ClusterManagers); err != nil { - return &data, err + var data CatClusterManagersResp + + resp, err := c.apiClient.do(ctx, req, &data.ClusterManagers) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Count executes a /_cat/count request with the optional CatCountReq -func (c catClient) Count(ctx context.Context, req *CatCountReq) (*CatCountsResp, error) { +func (c catClient) Count(ctx context.Context, req *CatCountReq) (*CatCountsResp, *opensearch.Response, error) { if req == nil { req = &CatCountReq{} } - var ( - data CatCountsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Counts); err != nil { - return &data, err + var data CatCountsResp + + resp, err := c.apiClient.do(ctx, req, &data.Counts) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // FieldData executes a /_cat/fielddata request with the optional CatFieldDataReq -func (c catClient) FieldData(ctx context.Context, req *CatFieldDataReq) (*CatFieldDataResp, error) { +func (c catClient) FieldData(ctx context.Context, req *CatFieldDataReq) (*CatFieldDataResp, *opensearch.Response, error) { if req == nil { req = &CatFieldDataReq{} } - var ( - data CatFieldDataResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.FieldData); err != nil { - return &data, err + var data CatFieldDataResp + + resp, err := c.apiClient.do(ctx, req, &data.FieldData) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Health executes a /_cat/health request with the optional CatHealthReq -func (c catClient) Health(ctx context.Context, req *CatHealthReq) (*CatHealthResp, error) { +func (c catClient) Health(ctx context.Context, req *CatHealthReq) (*CatHealthResp, *opensearch.Response, error) { if req == nil { req = &CatHealthReq{} } - var ( - data CatHealthResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Health); err != nil { - return &data, err + var data CatHealthResp + + resp, err := c.apiClient.do(ctx, req, &data.Health) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Indices executes a /_cat/indices request with the optional CatIndicesReq -func (c catClient) Indices(ctx context.Context, req *CatIndicesReq) (*CatIndicesResp, error) { +func (c catClient) Indices(ctx context.Context, req *CatIndicesReq) (*CatIndicesResp, *opensearch.Response, error) { if req == nil { req = &CatIndicesReq{} } - var ( - data CatIndicesResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err + var data CatIndicesResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Master executes a /_cat/master request with the optional CatMasterReq -func (c catClient) Master(ctx context.Context, req *CatMasterReq) (*CatMasterResp, error) { +func (c catClient) Master(ctx context.Context, req *CatMasterReq) (*CatMasterResp, *opensearch.Response, error) { if req == nil { req = &CatMasterReq{} } - var ( - data CatMasterResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Master); err != nil { - return &data, err + var data CatMasterResp + + resp, err := c.apiClient.do(ctx, req, &data.Master) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // NodeAttrs executes a /_cat/nodeattrs request with the optional CatNodeAttrsReq -func (c catClient) NodeAttrs(ctx context.Context, req *CatNodeAttrsReq) (*CatNodeAttrsResp, error) { +func (c catClient) NodeAttrs(ctx context.Context, req *CatNodeAttrsReq) (*CatNodeAttrsResp, *opensearch.Response, error) { if req == nil { req = &CatNodeAttrsReq{} } - var ( - data CatNodeAttrsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.NodeAttrs); err != nil { - return &data, err + var data CatNodeAttrsResp + + resp, err := c.apiClient.do(ctx, req, &data.NodeAttrs) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Nodes executes a /_cat/nodes request with the optional CatNodesReq -func (c catClient) Nodes(ctx context.Context, req *CatNodesReq) (*CatNodesResp, error) { +func (c catClient) Nodes(ctx context.Context, req *CatNodesReq) (*CatNodesResp, *opensearch.Response, error) { if req == nil { req = &CatNodesReq{} } - var ( - data CatNodesResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Nodes); err != nil { - return &data, err + var data CatNodesResp + + resp, err := c.apiClient.do(ctx, req, &data.Nodes) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // PendingTasks executes a /_cat/pending_tasks request with the optional CatPendingTasksReq -func (c catClient) PendingTasks(ctx context.Context, req *CatPendingTasksReq) (*CatPendingTasksResp, error) { +func (c catClient) PendingTasks(ctx context.Context, req *CatPendingTasksReq) (*CatPendingTasksResp, *opensearch.Response, error) { if req == nil { req = &CatPendingTasksReq{} } - var ( - data CatPendingTasksResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.PendingTasks); err != nil { - return &data, err + var data CatPendingTasksResp + + resp, err := c.apiClient.do(ctx, req, &data.PendingTasks) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Plugins executes a /_cat/plugins request with the optional CatPluginsReq -func (c catClient) Plugins(ctx context.Context, req *CatPluginsReq) (*CatPluginsResp, error) { +func (c catClient) Plugins(ctx context.Context, req *CatPluginsReq) (*CatPluginsResp, *opensearch.Response, error) { if req == nil { req = &CatPluginsReq{} } - var ( - data CatPluginsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Plugins); err != nil { - return &data, err + var data CatPluginsResp + + resp, err := c.apiClient.do(ctx, req, &data.Plugins) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Recovery executes a /_cat/recovery request with the optional CatRecoveryReq -func (c catClient) Recovery(ctx context.Context, req *CatRecoveryReq) (*CatRecoveryResp, error) { +func (c catClient) Recovery(ctx context.Context, req *CatRecoveryReq) (*CatRecoveryResp, *opensearch.Response, error) { if req == nil { req = &CatRecoveryReq{} } - var ( - data CatRecoveryResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Recovery); err != nil { - return &data, err + var data CatRecoveryResp + + resp, err := c.apiClient.do(ctx, req, &data.Recovery) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Repositories executes a /_cat/repositories request with the optional CatRepositoriesReq -func (c catClient) Repositories(ctx context.Context, req *CatRepositoriesReq) (*CatRepositoriesResp, error) { +func (c catClient) Repositories(ctx context.Context, req *CatRepositoriesReq) (*CatRepositoriesResp, *opensearch.Response, error) { if req == nil { req = &CatRepositoriesReq{} } - var ( - data CatRepositoriesResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Repositories); err != nil { - return &data, err + var data CatRepositoriesResp + + resp, err := c.apiClient.do(ctx, req, &data.Repositories) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Segments executes a /_cat/segments request with the optional CatSegmentsReq -func (c catClient) Segments(ctx context.Context, req *CatSegmentsReq) (*CatSegmentsResp, error) { +func (c catClient) Segments(ctx context.Context, req *CatSegmentsReq) (*CatSegmentsResp, *opensearch.Response, error) { if req == nil { req = &CatSegmentsReq{} } - var ( - data CatSegmentsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Segments); err != nil { - return &data, err + var data CatSegmentsResp + + resp, err := c.apiClient.do(ctx, req, &data.Segments) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Shards executes a /_cat/shards request with the optional CatShardsReq -func (c catClient) Shards(ctx context.Context, req *CatShardsReq) (*CatShardsResp, error) { +func (c catClient) Shards(ctx context.Context, req *CatShardsReq) (*CatShardsResp, *opensearch.Response, error) { if req == nil { req = &CatShardsReq{} } - var ( - data CatShardsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Shards); err != nil { - return &data, err + var data CatShardsResp + + resp, err := c.apiClient.do(ctx, req, &data.Shards) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Snapshots executes a /_cat/snapshots request with the required CatSnapshotsReq -func (c catClient) Snapshots(ctx context.Context, req CatSnapshotsReq) (*CatSnapshotsResp, error) { - var ( - data CatSnapshotsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Snapshots); err != nil { - return &data, err +func (c catClient) Snapshots(ctx context.Context, req CatSnapshotsReq) (*CatSnapshotsResp, *opensearch.Response, error) { + var data CatSnapshotsResp + + resp, err := c.apiClient.do(ctx, req, &data.Snapshots) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Tasks executes a /_cat/tasks request with the optional CatTasksReq -func (c catClient) Tasks(ctx context.Context, req *CatTasksReq) (*CatTasksResp, error) { +func (c catClient) Tasks(ctx context.Context, req *CatTasksReq) (*CatTasksResp, *opensearch.Response, error) { if req == nil { req = &CatTasksReq{} } - var ( - data CatTasksResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Tasks); err != nil { - return &data, err + var data CatTasksResp + + resp, err := c.apiClient.do(ctx, req, &data.Tasks) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Templates executes a /_cat/templates request with the optional CatTemplatesReq -func (c catClient) Templates(ctx context.Context, req *CatTemplatesReq) (*CatTemplatesResp, error) { +func (c catClient) Templates(ctx context.Context, req *CatTemplatesReq) (*CatTemplatesResp, *opensearch.Response, error) { if req == nil { req = &CatTemplatesReq{} } - var ( - data CatTemplatesResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Templates); err != nil { - return &data, err + var data CatTemplatesResp + + resp, err := c.apiClient.do(ctx, req, &data.Templates) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ThreadPool executes a /_cat/thread_pool request with the optional CatThreadPoolReq -func (c catClient) ThreadPool(ctx context.Context, req *CatThreadPoolReq) (*CatThreadPoolResp, error) { +func (c catClient) ThreadPool(ctx context.Context, req *CatThreadPoolReq) (*CatThreadPoolResp, *opensearch.Response, error) { if req == nil { req = &CatThreadPoolReq{} } - var ( - data CatThreadPoolResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.ThreadPool); err != nil { - return &data, err + var data CatThreadPoolResp + + resp, err := c.apiClient.do(ctx, req, &data.ThreadPool) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_cat_test.go b/opensearchapi/api_cat_test.go index d8b02ef7a..d4d8c42f5 100644 --- a/opensearchapi/api_cat_test.go +++ b/opensearchapi/api_cat_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -33,282 +34,282 @@ func TestCatClient(t *testing.T) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{index}}) }) - _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index, Body: strings.NewReader(`{"aliases":{"TEST_CAT_ALIAS":{}}}`)}) + _, _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index, Body: strings.NewReader(`{"aliases":{"TEST_CAT_ALIAS":{}}}`)}) require.Nil(t, err) type catTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := map[string][]catTests{ "Aliases": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Aliases(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Aliases(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Aliases(nil, &opensearchapi.CatAliasesReq{Aliases: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Aliases(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Aliases(nil, nil) }, }, }, "Allocation": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Allocation(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Allocation(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Allocation(nil, &opensearchapi.CatAllocationReq{NodeIDs: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Allocation(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Allocation(nil, nil) }, }, }, "ClusterManager": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.ClusterManager(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.ClusterManager(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.ClusterManager(nil, &opensearchapi.CatClusterManagerReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.ClusterManager(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.ClusterManager(nil, nil) }, }, }, "Count": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Count(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Count(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Count(nil, &opensearchapi.CatCountReq{Indices: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Count(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Count(nil, nil) }, }, }, "FieldData": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.FieldData(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.FieldData(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.FieldData(nil, &opensearchapi.CatFieldDataReq{FieldData: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.FieldData(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.FieldData(nil, nil) }, }, }, "Health": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Health(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Health(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Health(nil, &opensearchapi.CatHealthReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Health(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Health(nil, nil) }, }, }, "Indices": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Indices(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Indices(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Indices(nil, &opensearchapi.CatIndicesReq{Indices: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Indices(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Indices(nil, nil) }, }, }, "Master": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Master(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Master(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Master(nil, &opensearchapi.CatMasterReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Master(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Master(nil, nil) }, }, }, "NodeAttrs": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.NodeAttrs(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.NodeAttrs(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.NodeAttrs(nil, &opensearchapi.CatNodeAttrsReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.NodeAttrs(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.NodeAttrs(nil, nil) }, }, }, "Nodes": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Nodes(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Nodes(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Nodes(nil, &opensearchapi.CatNodesReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Nodes(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Nodes(nil, nil) }, }, }, "PendingTasks": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.PendingTasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.PendingTasks(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.PendingTasks(nil, &opensearchapi.CatPendingTasksReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.PendingTasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.PendingTasks(nil, nil) }, }, }, "Plugins": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Plugins(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Plugins(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Plugins(nil, &opensearchapi.CatPluginsReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Plugins(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Plugins(nil, nil) }, }, }, "Recovery": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Recovery(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Recovery(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Recovery(nil, &opensearchapi.CatRecoveryReq{Indices: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Recovery(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Recovery(nil, nil) }, }, }, "Repositories": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Repositories(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Repositories(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Repositories(nil, &opensearchapi.CatRepositoriesReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Repositories(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Repositories(nil, nil) }, }, }, "Segments": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Segments(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Segments(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Segments(nil, &opensearchapi.CatSegmentsReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Segments(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Segments(nil, nil) }, }, }, "Shards": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Shards(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Shards(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Shards(nil, &opensearchapi.CatShardsReq{Indices: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Shards(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Shards(nil, nil) }, }, }, /* Need to create snapshot + repo "Shards": []catTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Snapshots(nil, opensearchapi.CatSnapshotsReq{Repository: snapshotRepo}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Snapshots(nil, opensearchapi.CatSnapshotsReq{Repository: snapshotRepo}) }, }, @@ -317,49 +318,49 @@ func TestCatClient(t *testing.T) { "Tasks": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Tasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Tasks(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Tasks(nil, &opensearchapi.CatTasksReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Tasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Tasks(nil, nil) }, }, }, "Templates": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.Templates(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.Templates(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.Templates(nil, &opensearchapi.CatTemplatesReq{Templates: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.Templates(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.Templates(nil, nil) }, }, }, "ThreadPool": []catTests{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cat.ThreadPool(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cat.ThreadPool(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cat.ThreadPool(nil, &opensearchapi.CatThreadPoolReq{Pools: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cat.ThreadPool(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cat.ThreadPool(nil, nil) }, }, }, } @@ -370,15 +371,16 @@ func TestCatClient(t *testing.T) { } for _, testCase := range value { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { assert.Nil(t, err) - assert.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + assert.NotNil(t, resp) + assert.NotNil(t, httpResp) } }) } @@ -387,127 +389,127 @@ func TestCatClient(t *testing.T) { t.Run("ValidateResponse", func(t *testing.T) { t.Run("Aliases", func(t *testing.T) { - resp, err := client.Cat.Aliases(nil, nil) + resp, httpResp, err := client.Cat.Aliases(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Aliases, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Aliases, httpResp) }) t.Run("Allocation", func(t *testing.T) { - resp, err := client.Cat.Allocation(nil, nil) + resp, httpResp, err := client.Cat.Allocation(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Allocations, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Allocations, httpResp) }) t.Run("ClusterManager", func(t *testing.T) { ostest.SkipIfBelowVersion(t, client, 2, 0, "ClusterManager") - resp, err := client.Cat.ClusterManager(nil, nil) + resp, httpResp, err := client.Cat.ClusterManager(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.ClusterManagers, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.ClusterManagers, httpResp) }) t.Run("Count", func(t *testing.T) { - resp, err := client.Cat.Count(nil, nil) + resp, httpResp, err := client.Cat.Count(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Counts, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Counts, httpResp) }) t.Run("FieldData", func(t *testing.T) { - resp, err := client.Cat.FieldData(nil, nil) + resp, httpResp, err := client.Cat.FieldData(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.FieldData, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.FieldData, httpResp) }) t.Run("Health", func(t *testing.T) { - resp, err := client.Cat.Health(nil, nil) + resp, httpResp, err := client.Cat.Health(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Health, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Health, httpResp) }) t.Run("Indices", func(t *testing.T) { - resp, err := client.Cat.Indices(nil, &opensearchapi.CatIndicesReq{Params: opensearchapi.CatIndicesParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Indices(nil, &opensearchapi.CatIndicesReq{Params: opensearchapi.CatIndicesParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Master", func(t *testing.T) { - resp, err := client.Cat.Master(nil, nil) + resp, httpResp, err := client.Cat.Master(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Master, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Master, httpResp) }) t.Run("NodeAttrs", func(t *testing.T) { - resp, err := client.Cat.NodeAttrs(nil, &opensearchapi.CatNodeAttrsReq{Params: opensearchapi.CatNodeAttrsParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.NodeAttrs(nil, &opensearchapi.CatNodeAttrsReq{Params: opensearchapi.CatNodeAttrsParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.NodeAttrs, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.NodeAttrs, httpResp) }) t.Run("Nodes", func(t *testing.T) { - resp, err := client.Cat.Nodes(nil, &opensearchapi.CatNodesReq{Params: opensearchapi.CatNodesParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Nodes(nil, &opensearchapi.CatNodesReq{Params: opensearchapi.CatNodesParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Nodes, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Nodes, httpResp) }) t.Run("PendingTasks", func(t *testing.T) { - resp, err := client.Cat.PendingTasks(nil, nil) + resp, httpResp, err := client.Cat.PendingTasks(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.PendingTasks, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.PendingTasks, httpResp) }) t.Run("Plugins", func(t *testing.T) { - resp, err := client.Cat.Plugins(nil, nil) + resp, httpResp, err := client.Cat.Plugins(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Plugins, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Plugins, httpResp) }) t.Run("Recovery", func(t *testing.T) { - resp, err := client.Cat.Recovery(nil, &opensearchapi.CatRecoveryReq{Params: opensearchapi.CatRecoveryParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Recovery(nil, &opensearchapi.CatRecoveryReq{Params: opensearchapi.CatRecoveryParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Recovery, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Recovery, httpResp) }) t.Run("Repositories", func(t *testing.T) { - resp, err := client.Cat.Repositories(nil, nil) + resp, httpResp, err := client.Cat.Repositories(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Repositories, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Repositories, httpResp) }) t.Run("Segments", func(t *testing.T) { - resp, err := client.Cat.Segments(nil, &opensearchapi.CatSegmentsReq{Params: opensearchapi.CatSegmentsParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Segments(nil, &opensearchapi.CatSegmentsReq{Params: opensearchapi.CatSegmentsParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Segments, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Segments, httpResp) }) t.Run("Shards", func(t *testing.T) { - resp, err := client.Cat.Shards(nil, &opensearchapi.CatShardsReq{Params: opensearchapi.CatShardsParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Shards(nil, &opensearchapi.CatShardsReq{Params: opensearchapi.CatShardsParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Shards, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Shards, httpResp) }) /* Need to create Snapshot + Repo t.Run("Snapshots", func(t *testing.T) { - resp, err := client.Cat.Snapshots(nil, &opensearchapi.CatSnapshotsReq{Repository: snapshotRepo, Params: opensearchapi.CatSnapshotsParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Snapshots(nil, &opensearchapi.CatSnapshotsReq{Repository: snapshotRepo, Params: opensearchapi.CatSnapshotsParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Snapshots, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Snapshots, httpResp) }) */ t.Run("Tasks", func(t *testing.T) { - resp, err := client.Cat.Tasks(nil, &opensearchapi.CatTasksReq{Params: opensearchapi.CatTasksParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.Tasks(nil, &opensearchapi.CatTasksReq{Params: opensearchapi.CatTasksParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Tasks, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Tasks, httpResp) }) t.Run("Templates", func(t *testing.T) { - resp, err := client.Cat.Templates(nil, nil) + resp, httpResp, err := client.Cat.Templates(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Templates, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.Templates, httpResp) }) t.Run("ThreadPool", func(t *testing.T) { - resp, err := client.Cat.ThreadPool(nil, &opensearchapi.CatThreadPoolReq{Params: opensearchapi.CatThreadPoolParams{H: []string{"*"}}}) + resp, httpResp, err := client.Cat.ThreadPool(nil, &opensearchapi.CatThreadPoolReq{Params: opensearchapi.CatThreadPoolParams{H: []string{"*"}}}) assert.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.ThreadPool, resp.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp.ThreadPool, httpResp) }) }) } diff --git a/opensearchapi/api_cluster-allocation_explain.go b/opensearchapi/api_cluster-allocation_explain.go index b446fe473..e7a487456 100644 --- a/opensearchapi/api_cluster-allocation_explain.go +++ b/opensearchapi/api_cluster-allocation_explain.go @@ -71,12 +71,6 @@ type ClusterAllocationExplainResp struct { AllocateExplanation string `json:"allocate_explanation"` NodeAllocationDecisions []ClusterAllocationNodeDecisions `json:"node_allocation_decisions"` CanRebalanceClusterDecisions []ClusterAllocationExplainDeciders `json:"can_rebalance_cluster_decisions"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterAllocationExplainResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterAllocationCurrentNode is a sub type of ClusterAllocationExplainResp containing information of the node the shard is on diff --git a/opensearchapi/api_cluster-decommission.go b/opensearchapi/api_cluster-decommission.go index d0f99bb6f..03639fde6 100644 --- a/opensearchapi/api_cluster-decommission.go +++ b/opensearchapi/api_cluster-decommission.go @@ -43,12 +43,6 @@ func (r ClusterPutDecommissionReq) GetRequest() (*http.Request, error) { // ClusterPutDecommissionResp represents the returned struct of the /_cluster/decommission/awareness response type ClusterPutDecommissionResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterPutDecommissionResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterDeleteDecommissionReq represents possible options for the /_cluster/decommission/awareness request @@ -71,12 +65,6 @@ func (r ClusterDeleteDecommissionReq) GetRequest() (*http.Request, error) { // ClusterDeleteDecommissionResp represents the returned struct of the /_cluster/decommission/awareness response type ClusterDeleteDecommissionResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterDeleteDecommissionResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterGetDecommissionReq represents possible options for the /_cluster/decommission/awareness request @@ -106,11 +94,5 @@ func (r ClusterGetDecommissionReq) GetRequest() (*http.Request, error) { // ClusterGetDecommissionResp represents the returned struct of the /_cluster/decommission/awareness response type ClusterGetDecommissionResp struct { - Values map[string]string - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterGetDecommissionResp) Inspect() Inspect { - return Inspect{Response: r.response} + Values map[string]string } diff --git a/opensearchapi/api_cluster-health.go b/opensearchapi/api_cluster-health.go index aa8984132..04a06901d 100644 --- a/opensearchapi/api_cluster-health.go +++ b/opensearchapi/api_cluster-health.go @@ -60,10 +60,4 @@ type ClusterHealthResp struct { NumberOfInFlightFetch int `json:"number_of_in_flight_fetch"` TaskMaxWaitingInQueueMillis int `json:"task_max_waiting_in_queue_millis"` ActiveShardsPercentAsNumber float64 `json:"active_shards_percent_as_number"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterHealthResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_cluster-pending_tasks.go b/opensearchapi/api_cluster-pending_tasks.go index ba26216c3..960b1d5a8 100644 --- a/opensearchapi/api_cluster-pending_tasks.go +++ b/opensearchapi/api_cluster-pending_tasks.go @@ -31,13 +31,7 @@ func (r ClusterPendingTasksReq) GetRequest() (*http.Request, error) { // ClusterPendingTasksResp represents the returned struct of the ClusterPendingTasksReq response type ClusterPendingTasksResp struct { - Tasks []ClusterPendingTasksItem `json:"tasks"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterPendingTasksResp) Inspect() Inspect { - return Inspect{Response: r.response} + Tasks []ClusterPendingTasksItem `json:"tasks"` } // ClusterPendingTasksItem is a sub type if ClusterPendingTasksResp containing information about a task diff --git a/opensearchapi/api_cluster-remote_info.go b/opensearchapi/api_cluster-remote_info.go index af74f8d58..61eabbb08 100644 --- a/opensearchapi/api_cluster-remote_info.go +++ b/opensearchapi/api_cluster-remote_info.go @@ -32,12 +32,6 @@ func (r ClusterRemoteInfoReq) GetRequest() (*http.Request, error) { // ClusterRemoteInfoResp represents the returned struct of the ClusterRemoteInfoReq response type ClusterRemoteInfoResp struct { Clusters map[string]ClusterRemoteInfoDetails - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterRemoteInfoResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterRemoteInfoDetails is a sub type of ClusterRemoteInfoResp contains information about a remote connection diff --git a/opensearchapi/api_cluster-reroute.go b/opensearchapi/api_cluster-reroute.go index 113e12b11..23c16d5bb 100644 --- a/opensearchapi/api_cluster-reroute.go +++ b/opensearchapi/api_cluster-reroute.go @@ -37,12 +37,6 @@ func (r ClusterRerouteReq) GetRequest() (*http.Request, error) { type ClusterRerouteResp struct { Acknowledged bool `json:"acknowledged"` State ClusterRerouteState `json:"state"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterRerouteResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterRerouteState is a sub type of ClusterRerouteResp containing information about the cluster and cluster routing diff --git a/opensearchapi/api_cluster-settings.go b/opensearchapi/api_cluster-settings.go index dc1e5ee0a..0db9742e0 100644 --- a/opensearchapi/api_cluster-settings.go +++ b/opensearchapi/api_cluster-settings.go @@ -36,12 +36,6 @@ type ClusterGetSettingsResp struct { Persistent json.RawMessage `json:"persistent"` Transient json.RawMessage `json:"transient"` Defaults json.RawMessage `json:"defaults"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterGetSettingsResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterPutSettingsReq represents possible options for the /_cluster/settings request @@ -67,10 +61,4 @@ type ClusterPutSettingsResp struct { Acknowledged bool `json:"acknowledged"` Persistent json.RawMessage `json:"persistent"` Transient json.RawMessage `json:"transient"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterPutSettingsResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_cluster-state.go b/opensearchapi/api_cluster-state.go index 096f3fb07..636f5c29b 100644 --- a/opensearchapi/api_cluster-state.go +++ b/opensearchapi/api_cluster-state.go @@ -62,7 +62,6 @@ type ClusterStateResp struct { } `json:"blocks"` Nodes map[string]ClusterStateNodes `json:"nodes"` Metadata ClusterStateMetaData `json:"metadata"` - response *opensearch.Response RoutingTable struct { Indices map[string]struct { Shards map[string][]ClusterStateRoutingIndex `json:"shards"` @@ -83,11 +82,6 @@ type ClusterStateResp struct { } `json:"restore"` } -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterStateResp) Inspect() Inspect { - return Inspect{Response: r.response} -} - // ClusterStateBlocksIndex is a sub type of ClusterStateResp type ClusterStateBlocksIndex struct { Description string `json:"description"` diff --git a/opensearchapi/api_cluster-stats.go b/opensearchapi/api_cluster-stats.go index 0e171d546..541d35616 100644 --- a/opensearchapi/api_cluster-stats.go +++ b/opensearchapi/api_cluster-stats.go @@ -57,12 +57,6 @@ type ClusterStatsResp struct { Status string `json:"status"` Indices ClusterStatsIndices `json:"indices"` Nodes ClusterStatsNodes `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ClusterStatsResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ClusterStatsIndices is a sub type of ClusterStatsResp containing cluster information about indices diff --git a/opensearchapi/api_cluster.go b/opensearchapi/api_cluster.go index ae132d392..92c42cfc9 100644 --- a/opensearchapi/api_cluster.go +++ b/opensearchapi/api_cluster.go @@ -17,131 +17,123 @@ type clusterClient struct { } // AllocationExplain executes a /_cluster/allocation/explain request with the optional ClusterAllocationExplainReq -func (c clusterClient) AllocationExplain(ctx context.Context, req *ClusterAllocationExplainReq) (*ClusterAllocationExplainResp, error) { +func (c clusterClient) AllocationExplain(ctx context.Context, req *ClusterAllocationExplainReq) (*ClusterAllocationExplainResp, *opensearch.Response, error) { if req == nil { req = &ClusterAllocationExplainReq{} } - var ( - data ClusterAllocationExplainResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterAllocationExplainResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Health executes a /_cluster/health request with the optional ClusterHealthReq -func (c clusterClient) Health(ctx context.Context, req *ClusterHealthReq) (*ClusterHealthResp, error) { +func (c clusterClient) Health(ctx context.Context, req *ClusterHealthReq) (*ClusterHealthResp, *opensearch.Response, error) { if req == nil { req = &ClusterHealthReq{} } - var ( - data ClusterHealthResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterHealthResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // PendingTasks executes a /_cluster/pending_tasks request with the optional ClusterPendingTasksReq -func (c clusterClient) PendingTasks(ctx context.Context, req *ClusterPendingTasksReq) (*ClusterPendingTasksResp, error) { +func (c clusterClient) PendingTasks(ctx context.Context, req *ClusterPendingTasksReq) (*ClusterPendingTasksResp, *opensearch.Response, error) { if req == nil { req = &ClusterPendingTasksReq{} } - var ( - data ClusterPendingTasksResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterPendingTasksResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // GetSettings executes a /_cluster/settings request with the optional ClusterGetSettingsReq -func (c clusterClient) GetSettings(ctx context.Context, req *ClusterGetSettingsReq) (*ClusterGetSettingsResp, error) { +func (c clusterClient) GetSettings(ctx context.Context, req *ClusterGetSettingsReq) (*ClusterGetSettingsResp, *opensearch.Response, error) { if req == nil { req = &ClusterGetSettingsReq{} } - var ( - data ClusterGetSettingsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterGetSettingsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // PutSettings executes a /_cluster/settings request with the required ClusterPutSettingsReq -func (c clusterClient) PutSettings(ctx context.Context, req ClusterPutSettingsReq) (*ClusterPutSettingsResp, error) { - var ( - data ClusterPutSettingsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c clusterClient) PutSettings(ctx context.Context, req ClusterPutSettingsReq) (*ClusterPutSettingsResp, *opensearch.Response, error) { + var data ClusterPutSettingsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // State executes a /_cluster/state request with the optional ClusterStateReq -func (c clusterClient) State(ctx context.Context, req *ClusterStateReq) (*ClusterStateResp, error) { +func (c clusterClient) State(ctx context.Context, req *ClusterStateReq) (*ClusterStateResp, *opensearch.Response, error) { if req == nil { req = &ClusterStateReq{} } - var ( - data ClusterStateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterStateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Stats executes a /_cluster/stats request with the optional ClusterStatsReq -func (c clusterClient) Stats(ctx context.Context, req *ClusterStatsReq) (*ClusterStatsResp, error) { +func (c clusterClient) Stats(ctx context.Context, req *ClusterStatsReq) (*ClusterStatsResp, *opensearch.Response, error) { if req == nil { req = &ClusterStatsReq{} } - var ( - data ClusterStatsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterStatsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Reroute executes a /_cluster/reroute request with the required ClusterRerouteReq -func (c clusterClient) Reroute(ctx context.Context, req ClusterRerouteReq) (*ClusterRerouteResp, error) { - var ( - data ClusterRerouteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c clusterClient) Reroute(ctx context.Context, req ClusterRerouteReq) (*ClusterRerouteResp, *opensearch.Response, error) { + var data ClusterRerouteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // PostVotingConfigExclusions executes a /_cluster/voting_config_exclusions request with the optional ClusterPostVotingConfigExclusionsReq @@ -178,64 +170,57 @@ func (c clusterClient) DeleteVotingConfigExclusions( } // PutDecommission executes a /_cluster/decommission/awareness request with the optional ClusterPutDecommissionReq -func (c clusterClient) PutDecommission(ctx context.Context, req ClusterPutDecommissionReq) (*ClusterPutDecommissionResp, error) { - var ( - data ClusterPutDecommissionResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c clusterClient) PutDecommission(ctx context.Context, req ClusterPutDecommissionReq) (*ClusterPutDecommissionResp, *opensearch.Response, error) { + var data ClusterPutDecommissionResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // DeleteDecommission executes a /_cluster/decommission/awareness request with the optional ClusterDeleteDecommissionReq -func (c clusterClient) DeleteDecommission( - ctx context.Context, - req *ClusterDeleteDecommissionReq, -) (*ClusterDeleteDecommissionResp, error) { +func (c clusterClient) DeleteDecommission(ctx context.Context, req *ClusterDeleteDecommissionReq) (*ClusterDeleteDecommissionResp, *opensearch.Response, error) { if req == nil { req = &ClusterDeleteDecommissionReq{} } - var ( - data ClusterDeleteDecommissionResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ClusterDeleteDecommissionResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // GetDecommission executes a /_cluster/decommission/awareness request with the optional ClusterGetDecommissionReq -func (c clusterClient) GetDecommission(ctx context.Context, req ClusterGetDecommissionReq) (*ClusterGetDecommissionResp, error) { - var ( - data ClusterGetDecommissionResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Values); err != nil { - return &data, err +func (c clusterClient) GetDecommission(ctx context.Context, req ClusterGetDecommissionReq) (*ClusterGetDecommissionResp, *opensearch.Response, error) { + var data ClusterGetDecommissionResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // RemoteInfo executes a /_remote/info request with the optional ClusterRemoteInfoReq -func (c clusterClient) RemoteInfo(ctx context.Context, req *ClusterRemoteInfoReq) (*ClusterRemoteInfoResp, error) { +func (c clusterClient) RemoteInfo(ctx context.Context, req *ClusterRemoteInfoReq) (*ClusterRemoteInfoResp, *opensearch.Response, error) { if req == nil { req = &ClusterRemoteInfoReq{} } - var ( - data ClusterRemoteInfoResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Clusters); err != nil { - return &data, err + var data ClusterRemoteInfoResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_cluster_test.go b/opensearchapi/api_cluster_test.go index 831a1bd8a..9125303fe 100644 --- a/opensearchapi/api_cluster_test.go +++ b/opensearchapi/api_cluster_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -31,89 +32,89 @@ func TestClusterClient(t *testing.T) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{index}}) }) - _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) + _, _, err = client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) require.Nil(t, err) type clusterTest struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := map[string][]clusterTest{ "AllocationExplain": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.AllocationExplain(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.AllocationExplain(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.AllocationExplain(nil, &opensearchapi.ClusterAllocationExplainReq{Body: &opensearchapi.ClusterAllocationExplainBody{Index: index, Shard: 0, Primary: true}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.AllocationExplain(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.AllocationExplain(nil, nil) }, }, }, "Health": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.Health(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.Health(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.Health(nil, &opensearchapi.ClusterHealthReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.Health(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.Health(nil, nil) }, }, }, "PendingTasks": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.PendingTasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.PendingTasks(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.PendingTasks(nil, &opensearchapi.ClusterPendingTasksReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.PendingTasks(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.PendingTasks(nil, nil) }, }, }, "GetSettings": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.GetSettings(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.GetSettings(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.GetSettings(nil, &opensearchapi.ClusterGetSettingsReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.GetSettings(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.GetSettings(nil, nil) }, }, }, "PutSettings": []clusterTest{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.PutSettings(nil, opensearchapi.ClusterPutSettingsReq{Body: strings.NewReader(`{"transient":{"indices":{"recovery":{"max_bytes_per_sec":null}}}}`)}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.PutSettings(nil, opensearchapi.ClusterPutSettingsReq{}) }, }, @@ -121,13 +122,13 @@ func TestClusterClient(t *testing.T) { "Reroute": []clusterTest{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.Reroute(nil, opensearchapi.ClusterRerouteReq{Body: strings.NewReader(`{}`)}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.Reroute(nil, opensearchapi.ClusterRerouteReq{Body: strings.NewReader(`{}`)}) }, }, @@ -135,47 +136,47 @@ func TestClusterClient(t *testing.T) { "State": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.State(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.State(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.State(nil, &opensearchapi.ClusterStateReq{Metrics: []string{"_all"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.State(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.State(nil, nil) }, }, }, "Stats": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.Stats(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.Stats(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.Stats(nil, &opensearchapi.ClusterStatsReq{NodeFilters: []string{"data:true"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.Stats(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.Stats(nil, nil) }, }, }, "PutDecommission": []clusterTest{ /* Needs node awarness attr to work { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any,opensearch.Response, error) { return client.Cluster.PutDecommission(nil, opensearchapi.ClusterPutDecommissionReq{AwarenessAttrName: "test", AwarenessAttrValue: "test"}) }, }, */ { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.PutDecommission(nil, opensearchapi.ClusterPutDecommissionReq{AwarenessAttrName: "test", AwarenessAttrValue: "test"}) }, }, @@ -183,13 +184,13 @@ func TestClusterClient(t *testing.T) { "GetDecommission": []clusterTest{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.GetDecommission(nil, opensearchapi.ClusterGetDecommissionReq{AwarenessAttrName: "test"}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.GetDecommission(nil, opensearchapi.ClusterGetDecommissionReq{AwarenessAttrName: "test"}) }, }, @@ -197,33 +198,33 @@ func TestClusterClient(t *testing.T) { "DeleteDecommission": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.DeleteDecommission(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.DeleteDecommission(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.DeleteDecommission(nil, &opensearchapi.ClusterDeleteDecommissionReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.DeleteDecommission(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.DeleteDecommission(nil, nil) }, }, }, "RemoteInfo": []clusterTest{ { Name: "with nil request", - Results: func() (osapitest.Response, error) { return client.Cluster.RemoteInfo(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return client.Cluster.RemoteInfo(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Cluster.RemoteInfo(nil, &opensearchapi.ClusterRemoteInfoReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { return failingClient.Cluster.RemoteInfo(nil, nil) }, + Results: func() (any, *opensearch.Response, error) { return failingClient.Cluster.RemoteInfo(nil, nil) }, }, }, } @@ -234,16 +235,17 @@ func TestClusterClient(t *testing.T) { } for _, testCase := range value { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { assert.Nil(t, err) - assert.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + assert.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } }) } diff --git a/opensearchapi/api_component_template-create.go b/opensearchapi/api_component_template-create.go index 237395778..81d49bdb6 100644 --- a/opensearchapi/api_component_template-create.go +++ b/opensearchapi/api_component_template-create.go @@ -38,10 +38,4 @@ func (r ComponentTemplateCreateReq) GetRequest() (*http.Request, error) { // ComponentTemplateCreateResp represents the returned struct of the index create response type ComponentTemplateCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ComponentTemplateCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_component_template-delete.go b/opensearchapi/api_component_template-delete.go index ceb66bbb4..c673b01c3 100644 --- a/opensearchapi/api_component_template-delete.go +++ b/opensearchapi/api_component_template-delete.go @@ -35,10 +35,4 @@ func (r ComponentTemplateDeleteReq) GetRequest() (*http.Request, error) { // ComponentTemplateDeleteResp represents the returned struct of the _component_template delete response type ComponentTemplateDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ComponentTemplateDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_component_template-get.go b/opensearchapi/api_component_template-get.go index f9366bba9..acef04f33 100644 --- a/opensearchapi/api_component_template-get.go +++ b/opensearchapi/api_component_template-get.go @@ -44,12 +44,6 @@ func (r ComponentTemplateGetReq) GetRequest() (*http.Request, error) { // ComponentTemplateGetResp represents the returned struct of the index create response type ComponentTemplateGetResp struct { ComponentTemplates []ComponentTemplateGetDetails `json:"component_templates"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ComponentTemplateGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // ComponentTemplateGetDetails is a sub type of ComponentTemplateGetResp containing information about component template diff --git a/opensearchapi/api_component_template.go b/opensearchapi/api_component_template.go index 6760af192..c15d5d731 100644 --- a/opensearchapi/api_component_template.go +++ b/opensearchapi/api_component_template.go @@ -17,46 +17,43 @@ type componentTemplateClient struct { } // Create executes a creade componentTemplate request with the required ComponentTemplateCreateReq -func (c componentTemplateClient) Create(ctx context.Context, req ComponentTemplateCreateReq) (*ComponentTemplateCreateResp, error) { - var ( - data ComponentTemplateCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c componentTemplateClient) Create(ctx context.Context, req ComponentTemplateCreateReq) (*ComponentTemplateCreateResp, *opensearch.Response, error) { + var data ComponentTemplateCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete componentTemplate request with the required ComponentTemplateDeleteReq -func (c componentTemplateClient) Delete(ctx context.Context, req ComponentTemplateDeleteReq) (*ComponentTemplateDeleteResp, error) { - var ( - data ComponentTemplateDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c componentTemplateClient) Delete(ctx context.Context, req ComponentTemplateDeleteReq) (*ComponentTemplateDeleteResp, *opensearch.Response, error) { + var data ComponentTemplateDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get componentTemplate request with the optional ComponentTemplateGetReq -func (c componentTemplateClient) Get(ctx context.Context, req *ComponentTemplateGetReq) (*ComponentTemplateGetResp, error) { +func (c componentTemplateClient) Get(ctx context.Context, req *ComponentTemplateGetReq) (*ComponentTemplateGetResp, *opensearch.Response, error) { if req == nil { req = &ComponentTemplateGetReq{} } - var ( - data ComponentTemplateGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ComponentTemplateGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes a exists componentTemplate request with the required ComponentTemplatExistsReq diff --git a/opensearchapi/api_component_template_test.go b/opensearchapi/api_component_template_test.go index 295099038..e683d1d43 100644 --- a/opensearchapi/api_component_template_test.go +++ b/opensearchapi/api_component_template_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/opensearch-project/opensearch-go/v4" ostest "github.com/opensearch-project/opensearch-go/v4/internal/test" "github.com/opensearch-project/opensearch-go/v4/opensearchapi" osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test" @@ -30,7 +31,7 @@ func TestComponentTemplateClient(t *testing.T) { type componentTemplateTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -42,7 +43,7 @@ func TestComponentTemplateClient(t *testing.T) { Tests: []componentTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.ComponentTemplate.Create( nil, opensearchapi.ComponentTemplateCreateReq{ @@ -54,7 +55,7 @@ func TestComponentTemplateClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.ComponentTemplate.Create(nil, opensearchapi.ComponentTemplateCreateReq{ComponentTemplate: componentTemplate}) }, }, @@ -65,13 +66,13 @@ func TestComponentTemplateClient(t *testing.T) { Tests: []componentTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.ComponentTemplate.Get(nil, &opensearchapi.ComponentTemplateGetReq{ComponentTemplate: componentTemplate}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.ComponentTemplate.Get(nil, nil) }, }, @@ -82,24 +83,18 @@ func TestComponentTemplateClient(t *testing.T) { Tests: []componentTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.ComponentTemplate.Exists(nil, opensearchapi.ComponentTemplateExistsReq{ComponentTemplate: componentTemplate}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.ComponentTemplate.Exists(nil, opensearchapi.ComponentTemplateExistsReq{ComponentTemplate: componentTemplate}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.ComponentTemplate.Exists(nil, opensearchapi.ComponentTemplateExistsReq{ComponentTemplate: componentTemplate}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.ComponentTemplate.Exists(nil, opensearchapi.ComponentTemplateExistsReq{ComponentTemplate: componentTemplate}) + + return nil, httpResp, err }, }, }, @@ -109,13 +104,13 @@ func TestComponentTemplateClient(t *testing.T) { Tests: []componentTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.ComponentTemplate.Delete(nil, opensearchapi.ComponentTemplateDeleteReq{ComponentTemplate: componentTemplate}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.ComponentTemplate.Delete(nil, opensearchapi.ComponentTemplateDeleteReq{ComponentTemplate: componentTemplate}) }, }, @@ -126,18 +121,21 @@ func TestComponentTemplateClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) if value.Name != "Exists" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + require.NotNil(t, resp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) + } else { + assert.Nil(t, resp) } + assert.NotNil(t, httpResp) } }) } diff --git a/opensearchapi/api_dangling-delete.go b/opensearchapi/api_dangling-delete.go index 03ff832bf..8c2d4a705 100644 --- a/opensearchapi/api_dangling-delete.go +++ b/opensearchapi/api_dangling-delete.go @@ -35,10 +35,4 @@ func (r DanglingDeleteReq) GetRequest() (*http.Request, error) { // DanglingDeleteResp represents the returned struct of the delete dangling response type DanglingDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DanglingDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_dangling-get.go b/opensearchapi/api_dangling-get.go index 974d1f89b..1712bbb4a 100644 --- a/opensearchapi/api_dangling-get.go +++ b/opensearchapi/api_dangling-get.go @@ -52,10 +52,4 @@ type DanglingGetResp struct { CreationDateMillis int64 `json:"creation_date_millis"` NodeIds []string `json:"node_ids"` } `json:"dangling_indices"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DanglingGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_dangling-import.go b/opensearchapi/api_dangling-import.go index 83ad7ce6a..4dfcc6f41 100644 --- a/opensearchapi/api_dangling-import.go +++ b/opensearchapi/api_dangling-import.go @@ -35,10 +35,4 @@ func (r DanglingImportReq) GetRequest() (*http.Request, error) { // DanglingImportResp represents the returned struct of thedangling import response type DanglingImportResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DanglingImportResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_dangling.go b/opensearchapi/api_dangling.go index 60922fde2..73e71fd44 100644 --- a/opensearchapi/api_dangling.go +++ b/opensearchapi/api_dangling.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type danglingClient struct { @@ -15,44 +16,41 @@ type danglingClient struct { } // Delete executes a delete dangling request with the required DanglingDeleteReq -func (c danglingClient) Delete(ctx context.Context, req DanglingDeleteReq) (*DanglingDeleteResp, error) { - var ( - data DanglingDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c danglingClient) Delete(ctx context.Context, req DanglingDeleteReq) (*DanglingDeleteResp, *opensearch.Response, error) { + var data DanglingDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Import executes an import dangling request with the required DanglingImportReq -func (c danglingClient) Import(ctx context.Context, req DanglingImportReq) (*DanglingImportResp, error) { - var ( - data DanglingImportResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c danglingClient) Import(ctx context.Context, req DanglingImportReq) (*DanglingImportResp, *opensearch.Response, error) { + var data DanglingImportResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a /_dangling request with the optional DanglingGetReq -func (c danglingClient) Get(ctx context.Context, req *DanglingGetReq) (*DanglingGetResp, error) { +func (c danglingClient) Get(ctx context.Context, req *DanglingGetReq) (*DanglingGetResp, *opensearch.Response, error) { if req == nil { req = &DanglingGetReq{} } - var ( - data DanglingGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data DanglingGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_dangling_test.go b/opensearchapi/api_dangling_test.go index 095d63b4d..cd1bee0a3 100644 --- a/opensearchapi/api_dangling_test.go +++ b/opensearchapi/api_dangling_test.go @@ -78,7 +78,7 @@ func TestDanglingClient(t *testing.T) { type danglingTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -90,7 +90,7 @@ func TestDanglingClient(t *testing.T) { Tests: []danglingTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Dangling.Import( nil, opensearchapi.DanglingImportReq{ @@ -102,7 +102,7 @@ func TestDanglingClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Dangling.Import(nil, opensearchapi.DanglingImportReq{IndexUUID: "indexUUID"}) }, }, @@ -113,13 +113,13 @@ func TestDanglingClient(t *testing.T) { Tests: []danglingTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Dangling.Get(nil, &opensearchapi.DanglingGetReq{}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Dangling.Get(nil, nil) }, }, @@ -130,7 +130,7 @@ func TestDanglingClient(t *testing.T) { Tests: []danglingTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Dangling.Delete( nil, opensearchapi.DanglingDeleteReq{ @@ -142,7 +142,7 @@ func TestDanglingClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Dangling.Delete(nil, opensearchapi.DanglingDeleteReq{IndexUUID: "indexUUID"}) }, }, @@ -153,15 +153,16 @@ func TestDanglingClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) } }) } @@ -170,13 +171,14 @@ func TestDanglingClient(t *testing.T) { t.Run("ValidateResponse", func(t *testing.T) { t.Run("Get", func(t *testing.T) { - resp, err := client.Dangling.Get(nil, nil) + resp, httpResp, err := client.Dangling.Get(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Delete", func(t *testing.T) { - resp, err := client.Dangling.Delete( + resp, httpResp, err := client.Dangling.Delete( nil, opensearchapi.DanglingDeleteReq{ IndexUUID: "indexUUID", @@ -185,10 +187,11 @@ func TestDanglingClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Import", func(t *testing.T) { - resp, err := client.Dangling.Import( + resp, httpResp, err := client.Dangling.Import( nil, opensearchapi.DanglingImportReq{ IndexUUID: "indexUUID", @@ -197,7 +200,8 @@ func TestDanglingClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) }) } diff --git a/opensearchapi/api_datastream-create.go b/opensearchapi/api_datastream-create.go index 148dee149..8c93995c4 100644 --- a/opensearchapi/api_datastream-create.go +++ b/opensearchapi/api_datastream-create.go @@ -35,10 +35,4 @@ func (r DataStreamCreateReq) GetRequest() (*http.Request, error) { // DataStreamCreateResp represents the returned struct of the _data_stream create response type DataStreamCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DataStreamCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_datastream-delete.go b/opensearchapi/api_datastream-delete.go index 929b1f8ca..7ab90a36f 100644 --- a/opensearchapi/api_datastream-delete.go +++ b/opensearchapi/api_datastream-delete.go @@ -35,10 +35,4 @@ func (r DataStreamDeleteReq) GetRequest() (*http.Request, error) { // DataStreamDeleteResp represents the returned struct of the _data_stream delete response type DataStreamDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DataStreamDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_datastream-get.go b/opensearchapi/api_datastream-get.go index 20604aee6..86a720b99 100644 --- a/opensearchapi/api_datastream-get.go +++ b/opensearchapi/api_datastream-get.go @@ -45,12 +45,6 @@ func (r DataStreamGetReq) GetRequest() (*http.Request, error) { // DataStreamGetResp represents the returned struct of the _data_stream get response type DataStreamGetResp struct { DataStreams []DataStreamGetDetails `json:"data_streams"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DataStreamGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // DataStreamGetDetails is a sub type if DataStreamGetResp containing information about a data stream diff --git a/opensearchapi/api_datastream-stats.go b/opensearchapi/api_datastream-stats.go index d99f8dc89..37e0632f2 100644 --- a/opensearchapi/api_datastream-stats.go +++ b/opensearchapi/api_datastream-stats.go @@ -60,12 +60,6 @@ type DataStreamStatsResp struct { BackingIndices int `json:"backing_indices"` TotalStoreSizeBytes int64 `json:"total_store_size_bytes"` DataStreams []DataStreamStatsDetails `json:"data_streams"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DataStreamStatsResp) Inspect() Inspect { - return Inspect{Response: r.response} } // DataStreamStatsDetails is a sub type of DataStreamStatsResp containing information about a data stream diff --git a/opensearchapi/api_datastream.go b/opensearchapi/api_datastream.go index 2942d1d6b..3930f9fcb 100644 --- a/opensearchapi/api_datastream.go +++ b/opensearchapi/api_datastream.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type dataStreamClient struct { @@ -15,61 +16,57 @@ type dataStreamClient struct { } // Create executes a creade dataStream request with the required DataStreamCreateReq -func (c dataStreamClient) Create(ctx context.Context, req DataStreamCreateReq) (*DataStreamCreateResp, error) { - var ( - data DataStreamCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c dataStreamClient) Create(ctx context.Context, req DataStreamCreateReq) (*DataStreamCreateResp, *opensearch.Response, error) { + var data DataStreamCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete dataStream request with the required DataStreamDeleteReq -func (c dataStreamClient) Delete(ctx context.Context, req DataStreamDeleteReq) (*DataStreamDeleteResp, error) { - var ( - data DataStreamDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c dataStreamClient) Delete(ctx context.Context, req DataStreamDeleteReq) (*DataStreamDeleteResp, *opensearch.Response, error) { + var data DataStreamDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get dataStream request with the optional DataStreamGetReq -func (c dataStreamClient) Get(ctx context.Context, req *DataStreamGetReq) (*DataStreamGetResp, error) { +func (c dataStreamClient) Get(ctx context.Context, req *DataStreamGetReq) (*DataStreamGetResp, *opensearch.Response, error) { if req == nil { req = &DataStreamGetReq{} } - var ( - data DataStreamGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data DataStreamGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Stats executes a stats dataStream request with the optional DataStreamStatsReq -func (c dataStreamClient) Stats(ctx context.Context, req *DataStreamStatsReq) (*DataStreamStatsResp, error) { +func (c dataStreamClient) Stats(ctx context.Context, req *DataStreamStatsReq) (*DataStreamStatsResp, *opensearch.Response, error) { if req == nil { req = &DataStreamStatsReq{} } - var ( - data DataStreamStatsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data DataStreamStatsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_datastream_test.go b/opensearchapi/api_datastream_test.go index 599b7fd18..4949840e1 100644 --- a/opensearchapi/api_datastream_test.go +++ b/opensearchapi/api_datastream_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -28,7 +29,7 @@ func TestDataStreamClient(t *testing.T) { dataStream := "data-stream-test" - _, err = client.IndexTemplate.Create( + _, _, err = client.IndexTemplate.Create( nil, opensearchapi.IndexTemplateCreateReq{ IndexTemplate: dataStream, @@ -39,7 +40,7 @@ func TestDataStreamClient(t *testing.T) { type dataStreamTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -51,13 +52,13 @@ func TestDataStreamClient(t *testing.T) { Tests: []dataStreamTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.DataStream.Create(nil, opensearchapi.DataStreamCreateReq{DataStream: dataStream}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.DataStream.Create(nil, opensearchapi.DataStreamCreateReq{DataStream: dataStream}) }, }, @@ -68,13 +69,13 @@ func TestDataStreamClient(t *testing.T) { Tests: []dataStreamTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.DataStream.Get(nil, &opensearchapi.DataStreamGetReq{DataStreams: []string{dataStream}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.DataStream.Get(nil, nil) }, }, @@ -85,13 +86,13 @@ func TestDataStreamClient(t *testing.T) { Tests: []dataStreamTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.DataStream.Stats(nil, &opensearchapi.DataStreamStatsReq{DataStreams: []string{dataStream}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.DataStream.Stats(nil, nil) }, }, @@ -102,13 +103,13 @@ func TestDataStreamClient(t *testing.T) { Tests: []dataStreamTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.DataStream.Delete(nil, opensearchapi.DataStreamDeleteReq{DataStream: dataStream}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.DataStream.Delete(nil, opensearchapi.DataStreamDeleteReq{DataStream: dataStream}) }, }, @@ -119,16 +120,17 @@ func TestDataStreamClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } }) } diff --git a/opensearchapi/api_document-create.go b/opensearchapi/api_document-create.go index 10a7a4acb..7da3d6b70 100644 --- a/opensearchapi/api_document-create.go +++ b/opensearchapi/api_document-create.go @@ -57,10 +57,4 @@ type DocumentCreateResp struct { } `json:"_shards"` SeqNo int `json:"_seq_no"` PrimaryTerm int `json:"_primary_term"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_document-delete.go b/opensearchapi/api_document-delete.go index 7a282f86f..dcf6363cc 100644 --- a/opensearchapi/api_document-delete.go +++ b/opensearchapi/api_document-delete.go @@ -53,10 +53,4 @@ type DocumentDeleteResp struct { } `json:"_shards"` SeqNo int `json:"_seq_no"` PrimaryTerm int `json:"_primary_term"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_document-delete_by_query.go b/opensearchapi/api_document-delete_by_query.go index e936006e7..caf701ad5 100644 --- a/opensearchapi/api_document-delete_by_query.go +++ b/opensearchapi/api_document-delete_by_query.go @@ -55,10 +55,4 @@ type DocumentDeleteByQueryResp struct { ThrottledUntilMillis int `json:"throttled_until_millis"` Failures []json.RawMessage `json:"failures"` // Unknow struct, open an issue with an example response so we can add it Task string `json:"task,omitempty"` // Needed when wait_for_completion is set to false - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentDeleteByQueryResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_document-delete_by_query_rethrottle.go b/opensearchapi/api_document-delete_by_query_rethrottle.go index 5f741ef64..e51912d32 100644 --- a/opensearchapi/api_document-delete_by_query_rethrottle.go +++ b/opensearchapi/api_document-delete_by_query_rethrottle.go @@ -82,7 +82,6 @@ type DocumentDeleteByQueryRethrottleResp struct { } `json:"tasks"` } `json:"nodes"` NodeFailures []FailuresCause `json:"node_failures"` - response *opensearch.Response } // DocumentDeleteByQueryRethrottleResourceInfo is a sub type of DocumentDeleteByQueryRethrottleResp containing resource stats @@ -90,8 +89,3 @@ type DocumentDeleteByQueryRethrottleResourceInfo struct { CPUTimeInNanos int `json:"cpu_time_in_nanos"` MemoryInBytes int `json:"memory_in_bytes"` } - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentDeleteByQueryRethrottleResp) Inspect() Inspect { - return Inspect{Response: r.response} -} diff --git a/opensearchapi/api_document-explain.go b/opensearchapi/api_document-explain.go index 2610fe0db..3e56755bf 100644 --- a/opensearchapi/api_document-explain.go +++ b/opensearchapi/api_document-explain.go @@ -43,12 +43,6 @@ type DocumentExplainResp struct { Type string `json:"_type"` // Deprecated field Matched bool `json:"matched"` Explanation DocumentExplainDetails `json:"explanation"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentExplainResp) Inspect() Inspect { - return Inspect{Response: r.response} } // DocumentExplainDetails is a sub type of DocumentExplainResp containing information about why a query does what it does diff --git a/opensearchapi/api_document-get.go b/opensearchapi/api_document-get.go index 39862ad4c..0d5b606ac 100644 --- a/opensearchapi/api_document-get.go +++ b/opensearchapi/api_document-get.go @@ -45,10 +45,4 @@ type DocumentGetResp struct { Type string `json:"_type"` // Deprecated field Source json.RawMessage `json:"_source"` Fields json.RawMessage `json:"fields"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_document-source.go b/opensearchapi/api_document-source.go index c2c9bb5da..b6abe6a9e 100644 --- a/opensearchapi/api_document-source.go +++ b/opensearchapi/api_document-source.go @@ -36,11 +36,5 @@ func (r DocumentSourceReq) GetRequest() (*http.Request, error) { // DocumentSourceResp represents the returned struct of the //_source/ get response type DocumentSourceResp struct { - Source json.RawMessage - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r DocumentSourceResp) Inspect() Inspect { - return Inspect{Response: r.response} + Source json.RawMessage } diff --git a/opensearchapi/api_document.go b/opensearchapi/api_document.go index 082119dc5..1a3bdf989 100644 --- a/opensearchapi/api_document.go +++ b/opensearchapi/api_document.go @@ -16,58 +16,51 @@ type documentClient struct { } // Create executes a creade document request with the required DocumentCreateReq -func (c documentClient) Create(ctx context.Context, req DocumentCreateReq) (*DocumentCreateResp, error) { - var ( - data DocumentCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) Create(ctx context.Context, req DocumentCreateReq) (*DocumentCreateResp, *opensearch.Response, error) { + var data DocumentCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete document request with the required DocumentDeleteReq -func (c documentClient) Delete(ctx context.Context, req DocumentDeleteReq) (*DocumentDeleteResp, error) { - var ( - data DocumentDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) Delete(ctx context.Context, req DocumentDeleteReq) (*DocumentDeleteResp, *opensearch.Response, error) { + var data DocumentDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // DeleteByQuery executes a delete by query request with the required DocumentDeleteByQueryReq -func (c documentClient) DeleteByQuery(ctx context.Context, req DocumentDeleteByQueryReq) (*DocumentDeleteByQueryResp, error) { - var ( - data DocumentDeleteByQueryResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) DeleteByQuery(ctx context.Context, req DocumentDeleteByQueryReq) (*DocumentDeleteByQueryResp, *opensearch.Response, error) { + var data DocumentDeleteByQueryResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // DeleteByQueryRethrottle executes a delete by query rethrottle request with the optional DocumentDeleteByQueryRethrottleReq -func (c documentClient) DeleteByQueryRethrottle( - ctx context.Context, - req DocumentDeleteByQueryRethrottleReq, -) (*DocumentDeleteByQueryRethrottleResp, error) { - var ( - data DocumentDeleteByQueryRethrottleResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) DeleteByQueryRethrottle(ctx context.Context, req DocumentDeleteByQueryRethrottleReq) (*DocumentDeleteByQueryRethrottleResp, *opensearch.Response, error) { + var data DocumentDeleteByQueryRethrottleResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes a exists document request with the required DocumentExistsReq @@ -81,40 +74,37 @@ func (c documentClient) ExistsSource(ctx context.Context, req DocumentExistsSour } // Explain executes an explain document request with the required DocumentExplainReq -func (c documentClient) Explain(ctx context.Context, req DocumentExplainReq) (*DocumentExplainResp, error) { - var ( - data DocumentExplainResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) Explain(ctx context.Context, req DocumentExplainReq) (*DocumentExplainResp, *opensearch.Response, error) { + var data DocumentExplainResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a //_doc/ request with the required DocumentGetReq -func (c documentClient) Get(ctx context.Context, req DocumentGetReq) (*DocumentGetResp, error) { - var ( - data DocumentGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c documentClient) Get(ctx context.Context, req DocumentGetReq) (*DocumentGetResp, *opensearch.Response, error) { + var data DocumentGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Source executes a //_source/ request with the required DocumentSourceReq -func (c documentClient) Source(ctx context.Context, req DocumentSourceReq) (*DocumentSourceResp, error) { - var ( - data DocumentSourceResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Source); err != nil { - return &data, err +func (c documentClient) Source(ctx context.Context, req DocumentSourceReq) (*DocumentSourceResp, *opensearch.Response, error) { + var data DocumentSourceResp + + resp, err := c.apiClient.do(ctx, req, &data.Source) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_document_test.go b/opensearchapi/api_document_test.go index e639398ae..55a81f9da 100644 --- a/opensearchapi/api_document_test.go +++ b/opensearchapi/api_document_test.go @@ -10,6 +10,7 @@ package opensearchapi_test import ( "context" + "github.com/opensearch-project/opensearch-go/v4" "strconv" "strings" "testing" @@ -42,7 +43,7 @@ func TestDocumentClient(t *testing.T) { type documentTests struct { Name string IndexPrepare *docIndexPrep - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -54,7 +55,7 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.Create( nil, opensearchapi.DocumentCreateReq{ @@ -68,7 +69,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.Create( nil, opensearchapi.DocumentCreateReq{ @@ -86,24 +87,18 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Document.Exists(nil, opensearchapi.DocumentExistsReq{Index: index, DocumentID: documentID}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Document.Exists(nil, opensearchapi.DocumentExistsReq{Index: index, DocumentID: documentID}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Document.Exists(nil, opensearchapi.DocumentExistsReq{Index: index, DocumentID: documentID}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Document.Exists(nil, opensearchapi.DocumentExistsReq{Index: index, DocumentID: documentID}) + + return nil, httpResp, err }, }, }, @@ -113,24 +108,18 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Document.ExistsSource(nil, opensearchapi.DocumentExistsSourceReq{Index: index, DocumentID: documentID}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Document.ExistsSource(nil, opensearchapi.DocumentExistsSourceReq{Index: index, DocumentID: documentID}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Document.ExistsSource(nil, opensearchapi.DocumentExistsSourceReq{Index: index, DocumentID: documentID}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Document.ExistsSource(nil, opensearchapi.DocumentExistsSourceReq{Index: index, DocumentID: documentID}) + + return nil, httpResp, err }, }, }, @@ -140,7 +129,7 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.Get( nil, opensearchapi.DocumentGetReq{ @@ -152,7 +141,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.Get( nil, opensearchapi.DocumentGetReq{ @@ -169,7 +158,7 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.Explain( nil, opensearchapi.DocumentExplainReq{ @@ -182,7 +171,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.Explain( nil, opensearchapi.DocumentExplainReq{ @@ -200,7 +189,7 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.Source( nil, opensearchapi.DocumentSourceReq{ @@ -212,7 +201,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.Source( nil, opensearchapi.DocumentSourceReq{ @@ -229,7 +218,7 @@ func TestDocumentClient(t *testing.T) { Tests: []documentTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.Delete( nil, opensearchapi.DocumentDeleteReq{ @@ -241,7 +230,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.Delete( nil, opensearchapi.DocumentDeleteReq{ @@ -259,7 +248,7 @@ func TestDocumentClient(t *testing.T) { { Name: "with request", IndexPrepare: &docIndexPrep{DocCount: 100, Body: `{"title":"bar"}`}, - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Document.DeleteByQuery( nil, opensearchapi.DocumentDeleteByQueryReq{ @@ -271,7 +260,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.DeleteByQuery( nil, opensearchapi.DocumentDeleteByQueryReq{ @@ -289,8 +278,8 @@ func TestDocumentClient(t *testing.T) { { Name: "with request", IndexPrepare: &docIndexPrep{DocCount: 10000, Body: `{"title":"foo"}`}, - Results: func() (osapitest.Response, error) { - delResp, err := client.Document.DeleteByQuery( + Results: func() (any, *opensearch.Response, error) { + delResp, httpResp, err := client.Document.DeleteByQuery( nil, opensearchapi.DocumentDeleteByQueryReq{ Indices: []string{index}, @@ -299,7 +288,7 @@ func TestDocumentClient(t *testing.T) { }, ) if err != nil { - return delResp, err + return delResp, httpResp, err } return client.Document.DeleteByQueryRethrottle( nil, @@ -312,7 +301,7 @@ func TestDocumentClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Document.DeleteByQueryRethrottle( nil, opensearchapi.DocumentDeleteByQueryRethrottleReq{ @@ -353,17 +342,20 @@ func TestDocumentClient(t *testing.T) { } } t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - if !strings.Contains(value.Name, "Exists") && value.Name != "Source" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + assert.NotNil(t, httpResp) + if strings.Contains(value.Name, "Exists") { + require.Nil(t, resp) + } else if value.Name != "Source" { + require.NotNil(t, resp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) @@ -372,7 +364,7 @@ func TestDocumentClient(t *testing.T) { } t.Run("ValidateResponse", func(t *testing.T) { t.Run("Source", func(t *testing.T) { - _, err := client.Document.Create( + _, _, err := client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: index, @@ -381,7 +373,7 @@ func TestDocumentClient(t *testing.T) { }, ) require.Nil(t, err) - res, err := client.Document.Source( + resp, httpResp, err := client.Document.Source( nil, opensearchapi.DocumentSourceReq{ Index: index, @@ -389,12 +381,12 @@ func TestDocumentClient(t *testing.T) { }, ) require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res.Source, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Source, httpResp) }) t.Run("Fields", func(t *testing.T) { - _, err := client.Indices.Mapping.Put(nil, + _, _, err := client.Indices.Mapping.Put(nil, opensearchapi.MappingPutReq{ Indices: []string{index}, Body: strings.NewReader(`{ @@ -407,7 +399,7 @@ func TestDocumentClient(t *testing.T) { }`), }) require.Nil(t, err) - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: index, @@ -416,7 +408,7 @@ func TestDocumentClient(t *testing.T) { }, ) require.Nil(t, err) - res, err := client.Document.Get( + resp, httpResp, err := client.Document.Get( nil, opensearchapi.DocumentGetReq{ Index: index, @@ -427,10 +419,10 @@ func TestDocumentClient(t *testing.T) { }, ) require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) - assert.NotEmpty(t, res.Fields) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) + assert.NotEmpty(t, resp.Fields) }) }) } diff --git a/opensearchapi/api_index.go b/opensearchapi/api_index.go index d772a758f..8cc23c4c9 100644 --- a/opensearchapi/api_index.go +++ b/opensearchapi/api_index.go @@ -16,16 +16,15 @@ import ( ) // Index executes a /_doc request with the given IndexReq -func (c Client) Index(ctx context.Context, req IndexReq) (*IndexResp, error) { - var ( - data IndexResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Index(ctx context.Context, req IndexReq) (*IndexResp, *opensearch.Response, error) { + var data IndexResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // IndexReq represents possible options for the /_doc request @@ -72,10 +71,4 @@ type IndexResp struct { SeqNo int `json:"_seq_no"` PrimaryTerm int `json:"_primary_term"` Type string `json:"_type"` // Deprecated field - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_index_template-create.go b/opensearchapi/api_index_template-create.go index 1d6e35bf0..b2e4e5bfa 100644 --- a/opensearchapi/api_index_template-create.go +++ b/opensearchapi/api_index_template-create.go @@ -38,10 +38,4 @@ func (r IndexTemplateCreateReq) GetRequest() (*http.Request, error) { // IndexTemplateCreateResp represents the returned struct of the index create response type IndexTemplateCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexTemplateCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_index_template-delete.go b/opensearchapi/api_index_template-delete.go index 0c1011686..243df48dd 100644 --- a/opensearchapi/api_index_template-delete.go +++ b/opensearchapi/api_index_template-delete.go @@ -35,10 +35,4 @@ func (r IndexTemplateDeleteReq) GetRequest() (*http.Request, error) { // IndexTemplateDeleteResp represents the returned struct of the index create response type IndexTemplateDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexTemplateDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_index_template-get.go b/opensearchapi/api_index_template-get.go index db2bb89b9..b27f83b34 100644 --- a/opensearchapi/api_index_template-get.go +++ b/opensearchapi/api_index_template-get.go @@ -37,12 +37,6 @@ func (r IndexTemplateGetReq) GetRequest() (*http.Request, error) { // IndexTemplateGetResp represents the returned struct of the index create response type IndexTemplateGetResp struct { IndexTemplates []IndexTemplateGetDetails `json:"index_templates"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexTemplateGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // IndexTemplateGetDetails is a sub type of IndexTemplateGetResp containing information about an index template diff --git a/opensearchapi/api_index_template-simulate.go b/opensearchapi/api_index_template-simulate.go index 5cc253a4e..9e04bbb1a 100644 --- a/opensearchapi/api_index_template-simulate.go +++ b/opensearchapi/api_index_template-simulate.go @@ -47,10 +47,4 @@ type IndexTemplateSimulateResp struct { Name string `json:"name"` IndexPatterns []string `json:"index_patterns"` } `json:"overlapping"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexTemplateSimulateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_index_template-simulate_index.go b/opensearchapi/api_index_template-simulate_index.go index 3d59105fe..2638948c8 100644 --- a/opensearchapi/api_index_template-simulate_index.go +++ b/opensearchapi/api_index_template-simulate_index.go @@ -47,10 +47,4 @@ type IndexTemplateSimulateIndexResp struct { Name string `json:"name"` IndexPatterns []string `json:"index_patterns"` } `json:"overlapping"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndexTemplateSimulateIndexResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_index_template.go b/opensearchapi/api_index_template.go index a42c55340..8bd2e438b 100644 --- a/opensearchapi/api_index_template.go +++ b/opensearchapi/api_index_template.go @@ -17,46 +17,43 @@ type indexTemplateClient struct { } // Create executes a creade indexTemplate request with the required IndexTemplateCreateReq -func (c indexTemplateClient) Create(ctx context.Context, req IndexTemplateCreateReq) (*IndexTemplateCreateResp, error) { - var ( - data IndexTemplateCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indexTemplateClient) Create(ctx context.Context, req IndexTemplateCreateReq) (*IndexTemplateCreateResp, *opensearch.Response, error) { + var data IndexTemplateCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete indexTemplate request with the required IndexTemplateDeleteReq -func (c indexTemplateClient) Delete(ctx context.Context, req IndexTemplateDeleteReq) (*IndexTemplateDeleteResp, error) { - var ( - data IndexTemplateDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indexTemplateClient) Delete(ctx context.Context, req IndexTemplateDeleteReq) (*IndexTemplateDeleteResp, *opensearch.Response, error) { + var data IndexTemplateDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get indexTemplate request with the optional IndexTemplateGetReq -func (c indexTemplateClient) Get(ctx context.Context, req *IndexTemplateGetReq) (*IndexTemplateGetResp, error) { +func (c indexTemplateClient) Get(ctx context.Context, req *IndexTemplateGetReq) (*IndexTemplateGetResp, *opensearch.Response, error) { if req == nil { req = &IndexTemplateGetReq{} } - var ( - data IndexTemplateGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndexTemplateGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes a exists indexTemplate request with the required IndexTemplatExistsReq @@ -65,30 +62,25 @@ func (c indexTemplateClient) Exists(ctx context.Context, req IndexTemplateExists } // Simulate executes a _simulate indexTemplate request with the required IndexTemplateSimulateReq -func (c indexTemplateClient) Simulate(ctx context.Context, req IndexTemplateSimulateReq) (*IndexTemplateSimulateResp, error) { - var ( - data IndexTemplateSimulateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indexTemplateClient) Simulate(ctx context.Context, req IndexTemplateSimulateReq) (*IndexTemplateSimulateResp, *opensearch.Response, error) { + var data IndexTemplateSimulateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // SimulateIndex executes a _simulate_index indexTemplate request with the required IndexTemplateSimulateIndexReq -func (c indexTemplateClient) SimulateIndex( - ctx context.Context, - req IndexTemplateSimulateIndexReq, -) (*IndexTemplateSimulateIndexResp, error) { - var ( - data IndexTemplateSimulateIndexResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indexTemplateClient) SimulateIndex(ctx context.Context, req IndexTemplateSimulateIndexReq) (*IndexTemplateSimulateIndexResp, *opensearch.Response, error) { + var data IndexTemplateSimulateIndexResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_index_template_test.go b/opensearchapi/api_index_template_test.go index a2c58ed15..b261b079f 100644 --- a/opensearchapi/api_index_template_test.go +++ b/opensearchapi/api_index_template_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -30,7 +31,7 @@ func TestIndexTemplateClient(t *testing.T) { type indexTemplateTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -42,7 +43,7 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.IndexTemplate.Create( nil, opensearchapi.IndexTemplateCreateReq{ @@ -54,7 +55,7 @@ func TestIndexTemplateClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.IndexTemplate.Create(nil, opensearchapi.IndexTemplateCreateReq{IndexTemplate: indexTemplate}) }, }, @@ -65,13 +66,13 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.IndexTemplate.Get(nil, &opensearchapi.IndexTemplateGetReq{IndexTemplates: []string{indexTemplate}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.IndexTemplate.Get(nil, nil) }, }, @@ -82,24 +83,18 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.IndexTemplate.Exists(nil, opensearchapi.IndexTemplateExistsReq{IndexTemplate: indexTemplate}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.IndexTemplate.Exists(nil, opensearchapi.IndexTemplateExistsReq{IndexTemplate: indexTemplate}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.IndexTemplate.Exists(nil, opensearchapi.IndexTemplateExistsReq{IndexTemplate: indexTemplate}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.IndexTemplate.Exists(nil, opensearchapi.IndexTemplateExistsReq{IndexTemplate: indexTemplate}) + + return nil, httpResp, err }, }, }, @@ -109,7 +104,7 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.IndexTemplate.Simulate( nil, opensearchapi.IndexTemplateSimulateReq{ @@ -120,7 +115,7 @@ func TestIndexTemplateClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.IndexTemplate.Simulate(nil, opensearchapi.IndexTemplateSimulateReq{}) }, }, @@ -131,7 +126,7 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.IndexTemplate.SimulateIndex( nil, opensearchapi.IndexTemplateSimulateIndexReq{ @@ -142,7 +137,7 @@ func TestIndexTemplateClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.IndexTemplate.SimulateIndex(nil, opensearchapi.IndexTemplateSimulateIndexReq{}) }, }, @@ -153,13 +148,13 @@ func TestIndexTemplateClient(t *testing.T) { Tests: []indexTemplateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.IndexTemplate.Delete(nil, opensearchapi.IndexTemplateDeleteReq{IndexTemplate: indexTemplate}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.IndexTemplate.Delete(nil, opensearchapi.IndexTemplateDeleteReq{IndexTemplate: indexTemplate}) }, }, @@ -170,17 +165,18 @@ func TestIndexTemplateClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, httpResp) + assert.NotNil(t, httpResp) if value.Name != "Exists" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) diff --git a/opensearchapi/api_index_test.go b/opensearchapi/api_index_test.go index b06323aaf..caca3dd34 100644 --- a/opensearchapi/api_index_test.go +++ b/opensearchapi/api_index_test.go @@ -33,44 +33,46 @@ func TestIndexClient(t *testing.T) { }) t.Run("Request Empty", func(t *testing.T) { - resp, err := client.Index(nil, opensearchapi.IndexReq{}) + resp, httpResp, err := client.Index(nil, opensearchapi.IndexReq{}) assert.NotNil(t, err) var osError *opensearch.StringError require.True(t, errors.As(err, &osError)) assert.Equal(t, http.StatusMethodNotAllowed, osError.Status) assert.Contains(t, osError.Err, "Incorrect HTTP method for uri") - assert.NotNil(t, resp) - assert.NotNil(t, resp.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) }) t.Run("Request Index only", func(t *testing.T) { - resp, err := client.Index(nil, opensearchapi.IndexReq{Index: index}) + resp, httpResp, err := client.Index(nil, opensearchapi.IndexReq{Index: index}) assert.NotNil(t, err) var osError *opensearch.StructError require.True(t, errors.As(err, &osError)) assert.Equal(t, "parse_exception", osError.Err.Type) assert.Equal(t, "request body is required", osError.Err.Reason) - assert.NotNil(t, resp) - assert.NotNil(t, resp.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) }) t.Run("Request with DocID", func(t *testing.T) { for _, result := range []string{"created", "updated"} { body := strings.NewReader("{}") - resp, err := client.Index(nil, opensearchapi.IndexReq{Index: index, Body: body, DocumentID: "test"}) + resp, httpResp, err := client.Index(nil, opensearchapi.IndexReq{Index: index, Body: body, DocumentID: "test"}) require.Nil(t, err) require.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + require.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.Equal(t, result, resp.Result) } }) t.Run("Request without DocID", func(t *testing.T) { body := strings.NewReader("{}") - resp, err := client.Index(nil, opensearchapi.IndexReq{Index: index, Body: body}) + resp, httpResp, err := client.Index(nil, opensearchapi.IndexReq{Index: index, Body: body}) require.Nil(t, err) require.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + require.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.Equal(t, index, resp.Index) assert.Equal(t, "created", resp.Result) }) @@ -79,9 +81,10 @@ func TestIndexClient(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Index(nil, opensearchapi.IndexReq{Index: index}) + res, httpResp, err := failingClient.Index(nil, opensearchapi.IndexReq{Index: index}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_indices-alias.go b/opensearchapi/api_indices-alias.go index fbbafdc96..b129cd9d9 100644 --- a/opensearchapi/api_indices-alias.go +++ b/opensearchapi/api_indices-alias.go @@ -20,42 +20,39 @@ type aliasClient struct { } // Delete executes a delete alias request with the required AliasDeleteReq -func (c aliasClient) Delete(ctx context.Context, req AliasDeleteReq) (*AliasDeleteResp, error) { - var ( - data AliasDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c aliasClient) Delete(ctx context.Context, req AliasDeleteReq) (*AliasDeleteResp, *opensearch.Response, error) { + var data AliasDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get alias request with the required AliasGetReq -func (c aliasClient) Get(ctx context.Context, req AliasGetReq) (*AliasGetResp, error) { - var ( - data AliasGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err +func (c aliasClient) Get(ctx context.Context, req AliasGetReq) (*AliasGetResp, *opensearch.Response, error) { + var data AliasGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Put executes a put alias request with the required AliasPutReq -func (c aliasClient) Put(ctx context.Context, req AliasPutReq) (*AliasPutResp, error) { - var ( - data AliasPutResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c aliasClient) Put(ctx context.Context, req AliasPutReq) (*AliasPutResp, *opensearch.Response, error) { + var data AliasPutResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes an exists alias request with the required AliasExistsReq @@ -95,12 +92,6 @@ func (r AliasDeleteReq) GetRequest() (*http.Request, error) { // AliasDeleteResp represents the returned struct of the alias delete response type AliasDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r AliasDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } // AliasGetReq represents possible options for the alias get request @@ -137,12 +128,6 @@ type AliasGetResp struct { Indices map[string]struct { Aliases map[string]json.RawMessage `json:"aliases"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r AliasGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // AliasPutReq represents possible options for the alias put request @@ -176,12 +161,6 @@ func (r AliasPutReq) GetRequest() (*http.Request, error) { // AliasPutResp represents the returned struct of the alias put response type AliasPutResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r AliasPutResp) Inspect() Inspect { - return Inspect{Response: r.response} } // AliasExistsReq represents possible options for the alias exists request diff --git a/opensearchapi/api_indices-analyze.go b/opensearchapi/api_indices-analyze.go index 008fd96b7..ca402310b 100644 --- a/opensearchapi/api_indices-analyze.go +++ b/opensearchapi/api_indices-analyze.go @@ -70,12 +70,6 @@ type IndicesAnalyzeResp struct { Tokenfilters []IndicesAnalyzeTokenfilters `json:"tokenfilters"` Analyzer IndicesAnalyzeInfo `json:"analyzer"` } `json:"detail"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesAnalyzeResp) Inspect() Inspect { - return Inspect{Response: r.response} } // IndicesAnalyzeToken is a sut type of IndicesAnalyzeResp containing information about analyzer token diff --git a/opensearchapi/api_indices-block.go b/opensearchapi/api_indices-block.go index 0d54cea7b..85651c579 100644 --- a/opensearchapi/api_indices-block.go +++ b/opensearchapi/api_indices-block.go @@ -53,10 +53,4 @@ type IndicesBlockResp struct { Failures []FailuresShard `json:"failures"` } `json:"failed_shards"` } `json:"indices"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesBlockResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-cache.go b/opensearchapi/api_indices-cache.go index f29fa682b..ae1086786 100644 --- a/opensearchapi/api_indices-cache.go +++ b/opensearchapi/api_indices-cache.go @@ -50,10 +50,4 @@ type IndicesClearCacheResp struct { Failed int `json:"failed"` Failures []FailuresShard `json:"failures"` } `json:"_shards"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesClearCacheResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-clone.go b/opensearchapi/api_indices-clone.go index adaddb9f0..65fda891a 100644 --- a/opensearchapi/api_indices-clone.go +++ b/opensearchapi/api_indices-clone.go @@ -41,10 +41,4 @@ type IndicesCloneResp struct { Acknowledged bool `json:"acknowledged"` ShardsAcknowledged bool `json:"shards_acknowledged"` Index string `json:"index"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesCloneResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-close.go b/opensearchapi/api_indices-close.go index 4275278ae..313fbb21b 100644 --- a/opensearchapi/api_indices-close.go +++ b/opensearchapi/api_indices-close.go @@ -42,10 +42,4 @@ type IndicesCloseResp struct { Failures []FailuresShard `json:"failures"` } `json:"failed_shards"` } `json:"indices"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesCloseResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-count.go b/opensearchapi/api_indices-count.go index f8dc45395..a4223b3eb 100644 --- a/opensearchapi/api_indices-count.go +++ b/opensearchapi/api_indices-count.go @@ -52,11 +52,5 @@ type IndicesCountResp struct { Skipped int `json:"skipped"` Failed int `json:"failed"` } `json:"_shards"` - Count int `json:"count"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesCountResp) Inspect() Inspect { - return Inspect{Response: r.response} + Count int `json:"count"` } diff --git a/opensearchapi/api_indices-create.go b/opensearchapi/api_indices-create.go index cfd773d4c..a37028906 100644 --- a/opensearchapi/api_indices-create.go +++ b/opensearchapi/api_indices-create.go @@ -38,10 +38,4 @@ type IndicesCreateResp struct { Acknowledged bool `json:"acknowledged"` ShardsAcknowledged bool `json:"shards_acknowledged"` Index string `json:"index"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-delete.go b/opensearchapi/api_indices-delete.go index 57857d3fc..a184f4bd3 100644 --- a/opensearchapi/api_indices-delete.go +++ b/opensearchapi/api_indices-delete.go @@ -35,10 +35,4 @@ func (r IndicesDeleteReq) GetRequest() (*http.Request, error) { // IndicesDeleteResp represents the returned struct of the delete indices response type IndicesDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-field_caps.go b/opensearchapi/api_indices-field_caps.go index 3f4e29a77..3448bb3db 100644 --- a/opensearchapi/api_indices-field_caps.go +++ b/opensearchapi/api_indices-field_caps.go @@ -53,10 +53,4 @@ type IndicesFieldCapsResp struct { Aggregatable bool `json:"aggregatable"` Indices []string `json:"indices"` } `json:"fields"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesFieldCapsResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-flush.go b/opensearchapi/api_indices-flush.go index cf3bedff3..978c48e1d 100644 --- a/opensearchapi/api_indices-flush.go +++ b/opensearchapi/api_indices-flush.go @@ -49,10 +49,4 @@ type IndicesFlushResp struct { Failed int `json:"failed"` Failures []FailuresShard `json:"failures"` } `json:"_shards"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesFlushResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-forcemerge.go b/opensearchapi/api_indices-forcemerge.go index c8f367807..f1a764e98 100644 --- a/opensearchapi/api_indices-forcemerge.go +++ b/opensearchapi/api_indices-forcemerge.go @@ -49,10 +49,4 @@ type IndicesForcemergeResp struct { Failed int `json:"failed"` Failures []FailuresShard `json:"failures"` } `json:"_shards"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesForcemergeResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-get.go b/opensearchapi/api_indices-get.go index 8fdfd5318..b79693022 100644 --- a/opensearchapi/api_indices-get.go +++ b/opensearchapi/api_indices-get.go @@ -41,10 +41,4 @@ type IndicesGetResp struct { Mappings json.RawMessage `json:"mappings"` Settings json.RawMessage `json:"settings"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-mapping.go b/opensearchapi/api_indices-mapping.go index 4b10f8aab..3fb8d48e7 100644 --- a/opensearchapi/api_indices-mapping.go +++ b/opensearchapi/api_indices-mapping.go @@ -21,50 +21,47 @@ type mappingClient struct { } // Get executes a get mapping request with the required MappingGetReq -func (c mappingClient) Get(ctx context.Context, req *MappingGetReq) (*MappingGetResp, error) { +func (c mappingClient) Get(ctx context.Context, req *MappingGetReq) (*MappingGetResp, *opensearch.Response, error) { if req == nil { req = &MappingGetReq{} } - var ( - data MappingGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err + var data MappingGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Put executes a put mapping request with the required MappingPutReq -func (c mappingClient) Put(ctx context.Context, req MappingPutReq) (*MappingPutResp, error) { - var ( - data MappingPutResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c mappingClient) Put(ctx context.Context, req MappingPutReq) (*MappingPutResp, *opensearch.Response, error) { + var data MappingPutResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Field executes a field mapping request with the optional MappingFieldReq -func (c mappingClient) Field(ctx context.Context, req *MappingFieldReq) (*MappingFieldResp, error) { +func (c mappingClient) Field(ctx context.Context, req *MappingFieldReq) (*MappingFieldResp, *opensearch.Response, error) { if req == nil { req = &MappingFieldReq{} } - var ( - data MappingFieldResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err + var data MappingFieldResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // MappingGetReq represents possible options for the mapping get request @@ -100,12 +97,6 @@ type MappingGetResp struct { Indices map[string]struct { Mappings json.RawMessage `json:"mappings"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MappingGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // MappingPutReq represents possible options for the mapping put request @@ -139,12 +130,6 @@ func (r MappingPutReq) GetRequest() (*http.Request, error) { // MappingPutResp represents the returned struct of the mapping put response type MappingPutResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MappingPutResp) Inspect() Inspect { - return Inspect{Response: r.response} } // MappingFieldReq represents possible options for the mapping field request @@ -183,10 +168,4 @@ type MappingFieldResp struct { Indices map[string]struct { Mappings json.RawMessage `json:"mappings"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MappingFieldResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-open.go b/opensearchapi/api_indices-open.go index 28a3c81ce..e439a05a5 100644 --- a/opensearchapi/api_indices-open.go +++ b/opensearchapi/api_indices-open.go @@ -36,10 +36,4 @@ func (r IndicesOpenReq) GetRequest() (*http.Request, error) { type IndicesOpenResp struct { Acknowledged bool `json:"acknowledged"` ShardsAcknowledged bool `json:"shards_acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesOpenResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-recovery.go b/opensearchapi/api_indices-recovery.go index 68dfdcbc9..19cf3a75d 100644 --- a/opensearchapi/api_indices-recovery.go +++ b/opensearchapi/api_indices-recovery.go @@ -84,12 +84,6 @@ type IndicesRecoveryResp struct { } `json:"verify_index"` } `json:"shards"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesRecoveryResp) Inspect() Inspect { - return Inspect{Response: r.response} } // IndicesRecoveryNodeInfo is a sub type of IndicesRecoveryResp represeing Node information diff --git a/opensearchapi/api_indices-refresh.go b/opensearchapi/api_indices-refresh.go index d499175fe..166567590 100644 --- a/opensearchapi/api_indices-refresh.go +++ b/opensearchapi/api_indices-refresh.go @@ -48,10 +48,4 @@ type IndicesRefreshResp struct { Successful int `json:"successful"` Failed int `json:"failed"` } `json:"_shards"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesRefreshResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-resolve.go b/opensearchapi/api_indices-resolve.go index 882c6efb4..e794b0ecd 100644 --- a/opensearchapi/api_indices-resolve.go +++ b/opensearchapi/api_indices-resolve.go @@ -49,10 +49,4 @@ type IndicesResolveResp struct { BackingIndices []string `json:"backing_indices"` TimestampField string `json:"timestamp_field"` } `json:"data_streams"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesResolveResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-rollover.go b/opensearchapi/api_indices-rollover.go index 49bd02012..ae74714db 100644 --- a/opensearchapi/api_indices-rollover.go +++ b/opensearchapi/api_indices-rollover.go @@ -54,10 +54,4 @@ type IndicesRolloverResp struct { RolledOver bool `json:"rolled_over"` DryRun bool `json:"dry_run"` Conditions map[string]bool `json:"conditions"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesRolloverResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-segments.go b/opensearchapi/api_indices-segments.go index 4a4cc6256..e78d2aa27 100644 --- a/opensearchapi/api_indices-segments.go +++ b/opensearchapi/api_indices-segments.go @@ -52,12 +52,6 @@ type IndicesSegmentsResp struct { Indices map[string]struct { Shards map[string][]IndicesSegmentsShards `json:"shards"` } `json:"indices"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesSegmentsResp) Inspect() Inspect { - return Inspect{Response: r.response} } // IndicesSegmentsShards is a sub type of IndicesSegmentsResp containing information about a shard diff --git a/opensearchapi/api_indices-settings.go b/opensearchapi/api_indices-settings.go index 27b507fba..ba22777b5 100644 --- a/opensearchapi/api_indices-settings.go +++ b/opensearchapi/api_indices-settings.go @@ -21,32 +21,31 @@ type settingsClient struct { } // Get executes a get settings request with the required SettingsGetReq -func (c settingsClient) Get(ctx context.Context, req *SettingsGetReq) (*SettingsGetResp, error) { +func (c settingsClient) Get(ctx context.Context, req *SettingsGetReq) (*SettingsGetResp, *opensearch.Response, error) { if req == nil { req = &SettingsGetReq{} } - var ( - data SettingsGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err + + var data SettingsGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Put executes a put settings request with the required SettingsPutReq -func (c settingsClient) Put(ctx context.Context, req SettingsPutReq) (*SettingsPutResp, error) { - var ( - data SettingsPutResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c settingsClient) Put(ctx context.Context, req SettingsPutReq) (*SettingsPutResp, *opensearch.Response, error) { + var data SettingsPutResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // SettingsGetReq represents possible options for the settings get request @@ -88,12 +87,6 @@ type SettingsGetResp struct { Indices map[string]struct { Settings json.RawMessage `json:"settings"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SettingsGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // SettingsPutReq represents possible options for the settings put request @@ -127,10 +120,4 @@ func (r SettingsPutReq) GetRequest() (*http.Request, error) { // SettingsPutResp represents the returned struct of the settings put response type SettingsPutResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SettingsPutResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-shardstores.go b/opensearchapi/api_indices-shardstores.go index 91a7bd3f2..002907eb4 100644 --- a/opensearchapi/api_indices-shardstores.go +++ b/opensearchapi/api_indices-shardstores.go @@ -50,10 +50,4 @@ type IndicesShardStoresResp struct { } `json:"shards"` } `json:"indices"` Failures []FailuresShard `json:"failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesShardStoresResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-shrink.go b/opensearchapi/api_indices-shrink.go index 367bbd82e..3dedd543a 100644 --- a/opensearchapi/api_indices-shrink.go +++ b/opensearchapi/api_indices-shrink.go @@ -41,10 +41,4 @@ type IndicesShrinkResp struct { Acknowledged bool `json:"acknowledged"` ShardsAcknowledged bool `json:"shards_acknowledged"` Index string `json:"index"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesShrinkResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-split.go b/opensearchapi/api_indices-split.go index dba82ff8e..b1b21a2a9 100644 --- a/opensearchapi/api_indices-split.go +++ b/opensearchapi/api_indices-split.go @@ -41,10 +41,4 @@ type IndicesSplitResp struct { Acknowledged bool `json:"acknowledged"` ShardsAcknowledged bool `json:"shards_acknowledged"` Index string `json:"index"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesSplitResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices-stats.go b/opensearchapi/api_indices-stats.go index e5e4dff8a..d8b66ec6c 100644 --- a/opensearchapi/api_indices-stats.go +++ b/opensearchapi/api_indices-stats.go @@ -50,15 +50,9 @@ func (r IndicesStatsReq) GetRequest() (*http.Request, error) { // IndicesStatsResp represents the returned struct of the index shrink response type IndicesStatsResp struct { - Shards IndicesStatsShards `json:"_shards"` - All IndicesStatsAll `json:"_all"` - Indices IndicesStatsIndices `json:"indices"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesStatsResp) Inspect() Inspect { - return Inspect{Response: r.response} + Shards IndicesStatsShards `json:"_shards"` + All IndicesStatsAll `json:"_all"` + Indices IndicesStatsIndices `json:"indices"` } // IndicesStatsShards is a sub type of IndicesStatsResp containing information about how many shards got requested diff --git a/opensearchapi/api_indices-validate.go b/opensearchapi/api_indices-validate.go index 5ab44462b..54797f3f2 100644 --- a/opensearchapi/api_indices-validate.go +++ b/opensearchapi/api_indices-validate.go @@ -61,10 +61,4 @@ type IndicesValidateQueryResp struct { Explanation *string `json:"explanation"` Error *string `json:"error"` } `json:"explanations"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IndicesValidateQueryResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_indices.go b/opensearchapi/api_indices.go index bf332b04c..fe1520c57 100644 --- a/opensearchapi/api_indices.go +++ b/opensearchapi/api_indices.go @@ -20,29 +20,27 @@ type indicesClient struct { } // Delete executes a delete indices request with the required IndicesDeleteReq -func (c indicesClient) Delete(ctx context.Context, req IndicesDeleteReq) (*IndicesDeleteResp, error) { - var ( - data IndicesDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Delete(ctx context.Context, req IndicesDeleteReq) (*IndicesDeleteResp, *opensearch.Response, error) { + var data IndicesDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Create executes a creade indices request with the required IndicesCreateReq -func (c indicesClient) Create(ctx context.Context, req IndicesCreateReq) (*IndicesCreateResp, error) { - var ( - data IndicesCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Create(ctx context.Context, req IndicesCreateReq) (*IndicesCreateResp, *opensearch.Response, error) { + var data IndicesCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes a exists indices request with the required IndicesExistsReq @@ -51,310 +49,289 @@ func (c indicesClient) Exists(ctx context.Context, req IndicesExistsReq) (*opens } // Block executes a //_block request with the required IndicesBlockReq -func (c indicesClient) Block(ctx context.Context, req IndicesBlockReq) (*IndicesBlockResp, error) { - var ( - data IndicesBlockResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Block(ctx context.Context, req IndicesBlockReq) (*IndicesBlockResp, *opensearch.Response, error) { + var data IndicesBlockResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Analyze executes a //_analyze request with the required IndicesAnalyzeReq -func (c indicesClient) Analyze(ctx context.Context, req IndicesAnalyzeReq) (*IndicesAnalyzeResp, error) { - var ( - data IndicesAnalyzeResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Analyze(ctx context.Context, req IndicesAnalyzeReq) (*IndicesAnalyzeResp, *opensearch.Response, error) { + var data IndicesAnalyzeResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ClearCache executes a //_cache/clear request with the optional IndicesClearCacheReq -func (c indicesClient) ClearCache(ctx context.Context, req *IndicesClearCacheReq) (*IndicesClearCacheResp, error) { +func (c indicesClient) ClearCache(ctx context.Context, req *IndicesClearCacheReq) (*IndicesClearCacheResp, *opensearch.Response, error) { if req == nil { req = &IndicesClearCacheReq{} } - var ( - data IndicesClearCacheResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesClearCacheResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Clone executes a //_clone/ request with the required IndicesCloneReq -func (c indicesClient) Clone(ctx context.Context, req IndicesCloneReq) (*IndicesCloneResp, error) { - var ( - data IndicesCloneResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Clone(ctx context.Context, req IndicesCloneReq) (*IndicesCloneResp, *opensearch.Response, error) { + var data IndicesCloneResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Close executes a //_close request with the required IndicesCloseReq -func (c indicesClient) Close(ctx context.Context, req IndicesCloseReq) (*IndicesCloseResp, error) { - var ( - data IndicesCloseResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Close(ctx context.Context, req IndicesCloseReq) (*IndicesCloseResp, *opensearch.Response, error) { + var data IndicesCloseResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a / request with the required IndicesGetReq -func (c indicesClient) Get(ctx context.Context, req IndicesGetReq) (*IndicesGetResp, error) { - var ( - data IndicesGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err +func (c indicesClient) Get(ctx context.Context, req IndicesGetReq) (*IndicesGetResp, *opensearch.Response, error) { + var data IndicesGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Open executes a //_open request with the required IndicesOpenReq -func (c indicesClient) Open(ctx context.Context, req IndicesOpenReq) (*IndicesOpenResp, error) { - var ( - data IndicesOpenResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Open(ctx context.Context, req IndicesOpenReq) (*IndicesOpenResp, *opensearch.Response, error) { + var data IndicesOpenResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Shrink executes a //_shrink/ request with the required IndicesShrinkReq -func (c indicesClient) Shrink(ctx context.Context, req IndicesShrinkReq) (*IndicesShrinkResp, error) { - var ( - data IndicesShrinkResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Shrink(ctx context.Context, req IndicesShrinkReq) (*IndicesShrinkResp, *opensearch.Response, error) { + var data IndicesShrinkResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Split executes a //_split/ request with the required IndicesSplitReq -func (c indicesClient) Split(ctx context.Context, req IndicesSplitReq) (*IndicesSplitResp, error) { - var ( - data IndicesSplitResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Split(ctx context.Context, req IndicesSplitReq) (*IndicesSplitResp, *opensearch.Response, error) { + var data IndicesSplitResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Flush executes a //_flush request with the optional IndicesFlushReq -func (c indicesClient) Flush(ctx context.Context, req *IndicesFlushReq) (*IndicesFlushResp, error) { +func (c indicesClient) Flush(ctx context.Context, req *IndicesFlushReq) (*IndicesFlushResp, *opensearch.Response, error) { if req == nil { req = &IndicesFlushReq{} } - var ( - data IndicesFlushResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesFlushResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Forcemerge executes a //_forcemerge request with the optional IndicesForcemergeReq -func (c indicesClient) Forcemerge(ctx context.Context, req *IndicesForcemergeReq) (*IndicesForcemergeResp, error) { +func (c indicesClient) Forcemerge(ctx context.Context, req *IndicesForcemergeReq) (*IndicesForcemergeResp, *opensearch.Response, error) { if req == nil { req = &IndicesForcemergeReq{} } - var ( - data IndicesForcemergeResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesForcemergeResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Recovery executes a //_recovery request with the optional IndicesRecoveryReq -func (c indicesClient) Recovery(ctx context.Context, req *IndicesRecoveryReq) (*IndicesRecoveryResp, error) { +func (c indicesClient) Recovery(ctx context.Context, req *IndicesRecoveryReq) (*IndicesRecoveryResp, *opensearch.Response, error) { if req == nil { req = &IndicesRecoveryReq{} } - var ( - data IndicesRecoveryResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { - return &data, err + var data IndicesRecoveryResp + + resp, err := c.apiClient.do(ctx, req, &data.Indices) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Refresh executes a //_refresh request with the optional IndicesRefreshReq -func (c indicesClient) Refresh(ctx context.Context, req *IndicesRefreshReq) (*IndicesRefreshResp, error) { +func (c indicesClient) Refresh(ctx context.Context, req *IndicesRefreshReq) (*IndicesRefreshResp, *opensearch.Response, error) { if req == nil { req = &IndicesRefreshReq{} } - var ( - data IndicesRefreshResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesRefreshResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Rollover executes a //_rollover request with the required IndicesRolloverReq -func (c indicesClient) Rollover(ctx context.Context, req IndicesRolloverReq) (*IndicesRolloverResp, error) { - var ( - data IndicesRolloverResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Rollover(ctx context.Context, req IndicesRolloverReq) (*IndicesRolloverResp, *opensearch.Response, error) { + var data IndicesRolloverResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Segments executes a //_segments request with the optional IndicesSegmentsReq -func (c indicesClient) Segments(ctx context.Context, req *IndicesSegmentsReq) (*IndicesSegmentsResp, error) { +func (c indicesClient) Segments(ctx context.Context, req *IndicesSegmentsReq) (*IndicesSegmentsResp, *opensearch.Response, error) { if req == nil { req = &IndicesSegmentsReq{} } - var ( - data IndicesSegmentsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesSegmentsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ShardStores executes a //_shard_stores request with the optional IndicesShardStoresReq -func (c indicesClient) ShardStores(ctx context.Context, req *IndicesShardStoresReq) (*IndicesShardStoresResp, error) { +func (c indicesClient) ShardStores(ctx context.Context, req *IndicesShardStoresReq) (*IndicesShardStoresResp, *opensearch.Response, error) { if req == nil { req = &IndicesShardStoresReq{} } - var ( - data IndicesShardStoresResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesShardStoresResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Stats executes a //_stats request with the optional IndicesStatsReq -func (c indicesClient) Stats(ctx context.Context, req *IndicesStatsReq) (*IndicesStatsResp, error) { +func (c indicesClient) Stats(ctx context.Context, req *IndicesStatsReq) (*IndicesStatsResp, *opensearch.Response, error) { if req == nil { req = &IndicesStatsReq{} } - var ( - data IndicesStatsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesStatsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ValidateQuery executes a //_validate/query request with the required IndicesValidateQueryReq -func (c indicesClient) ValidateQuery(ctx context.Context, req IndicesValidateQueryReq) (*IndicesValidateQueryResp, error) { - var ( - data IndicesValidateQueryResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) ValidateQuery(ctx context.Context, req IndicesValidateQueryReq) (*IndicesValidateQueryResp, *opensearch.Response, error) { + var data IndicesValidateQueryResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Count executes a //_count request with the required IndicesCountReq -func (c indicesClient) Count(ctx context.Context, req *IndicesCountReq) (*IndicesCountResp, error) { +func (c indicesClient) Count(ctx context.Context, req *IndicesCountReq) (*IndicesCountResp, *opensearch.Response, error) { if req == nil { req = &IndicesCountReq{} } - var ( - data IndicesCountResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IndicesCountResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // FieldCaps executes a //_field_caps request with the required IndicesFieldCapsReq -func (c indicesClient) FieldCaps(ctx context.Context, req IndicesFieldCapsReq) (*IndicesFieldCapsResp, error) { - var ( - data IndicesFieldCapsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) FieldCaps(ctx context.Context, req IndicesFieldCapsReq) (*IndicesFieldCapsResp, *opensearch.Response, error) { + var data IndicesFieldCapsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Resolve executes a /_resolve/index/ request with the required IndicesResolveReq -func (c indicesClient) Resolve(ctx context.Context, req IndicesResolveReq) (*IndicesResolveResp, error) { - var ( - data IndicesResolveResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c indicesClient) Resolve(ctx context.Context, req IndicesResolveReq) (*IndicesResolveResp, *opensearch.Response, error) { + var data IndicesResolveResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_indices_test.go b/opensearchapi/api_indices_test.go index bf9e818d2..b5c8e3fcf 100644 --- a/opensearchapi/api_indices_test.go +++ b/opensearchapi/api_indices_test.go @@ -9,6 +9,8 @@ package opensearchapi_test import ( + "fmt" + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -33,7 +35,7 @@ func TestIndicesClient(t *testing.T) { indexRollover := "test-indices-rollover" alias := "test-indices-alias" testIndices := []string{index, indexClone, indexSplit, indexShrink, indexRollover} - _, err = client.Indices.Delete( + _, _, err = client.Indices.Delete( nil, opensearchapi.IndicesDeleteReq{ Indices: testIndices, @@ -44,7 +46,7 @@ func TestIndicesClient(t *testing.T) { type indicesTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -56,13 +58,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) }, }, @@ -73,24 +75,18 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Indices.Exists(nil, opensearchapi.IndicesExistsReq{Indices: []string{index}}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Indices.Exists(nil, opensearchapi.IndicesExistsReq{Indices: []string{index}}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Indices.Exists(nil, opensearchapi.IndicesExistsReq{Indices: []string{index}}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Indices.Exists(nil, opensearchapi.IndicesExistsReq{Indices: []string{index}}) + + return nil, httpResp, err }, }, }, @@ -100,13 +96,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Block(nil, opensearchapi.IndicesBlockReq{Indices: []string{index}, Block: "write"}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Block(nil, opensearchapi.IndicesBlockReq{Indices: []string{index}, Block: "write"}) }, }, @@ -117,13 +113,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Analyze(nil, opensearchapi.IndicesAnalyzeReq{Body: opensearchapi.IndicesAnalyzeBody{Text: []string{"test"}, Analyzer: "standard"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Analyze(nil, opensearchapi.IndicesAnalyzeReq{Body: opensearchapi.IndicesAnalyzeBody{Text: []string{"test"}, Analyzer: "standard"}}) }, }, @@ -134,19 +130,19 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.ClearCache(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.ClearCache(nil, &opensearchapi.IndicesClearCacheReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.ClearCache(nil, nil) }, }, @@ -157,13 +153,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Alias.Put(nil, opensearchapi.AliasPutReq{Indices: []string{index}, Alias: alias}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Alias.Put(nil, opensearchapi.AliasPutReq{Indices: []string{index}, Alias: alias}) }, }, @@ -174,13 +170,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Alias.Get(nil, opensearchapi.AliasGetReq{Indices: []string{index}, Alias: []string{alias}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Alias.Get(nil, opensearchapi.AliasGetReq{Indices: []string{index}, Alias: []string{alias}}) }, }, @@ -191,24 +187,18 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Indices.Alias.Exists(nil, opensearchapi.AliasExistsReq{Indices: []string{index}, Alias: []string{alias}}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Indices.Alias.Exists(nil, opensearchapi.AliasExistsReq{Indices: []string{index}, Alias: []string{alias}}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Indices.Alias.Exists(nil, opensearchapi.AliasExistsReq{Indices: []string{index}, Alias: []string{alias}}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Indices.Alias.Exists(nil, opensearchapi.AliasExistsReq{Indices: []string{index}, Alias: []string{alias}}) + + return nil, httpResp, err }, }, }, @@ -218,13 +208,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Rollover(nil, opensearchapi.IndicesRolloverReq{Alias: alias, Index: indexRollover}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Rollover(nil, opensearchapi.IndicesRolloverReq{Alias: alias, Index: indexRollover}) }, }, @@ -235,13 +225,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Alias.Delete(nil, opensearchapi.AliasDeleteReq{Indices: []string{indexRollover}, Alias: []string{alias}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Alias.Delete(nil, opensearchapi.AliasDeleteReq{Indices: []string{indexRollover}, Alias: []string{alias}}) }, }, @@ -252,13 +242,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Mapping.Put(nil, opensearchapi.MappingPutReq{Indices: []string{index}, Body: strings.NewReader(`{"properties":{"test":{"type":"text"}}}`)}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Mapping.Put(nil, opensearchapi.MappingPutReq{Indices: []string{index}, Body: strings.NewReader(`{"properties":{"test":{"type":"text"}}}`)}) }, }, @@ -269,13 +259,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Mapping.Get(nil, &opensearchapi.MappingGetReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Mapping.Get(nil, &opensearchapi.MappingGetReq{Indices: []string{index}}) }, }, @@ -286,13 +276,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Mapping.Field(nil, &opensearchapi.MappingFieldReq{Indices: []string{index}, Fields: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Mapping.Field(nil, &opensearchapi.MappingFieldReq{Indices: []string{index}, Fields: []string{"*"}}) }, }, @@ -303,13 +293,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Settings.Put(nil, opensearchapi.SettingsPutReq{Indices: []string{index}, Body: strings.NewReader(`{"number_of_replicas":0}`)}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Settings.Put(nil, opensearchapi.SettingsPutReq{Indices: []string{index}, Body: strings.NewReader(`{"number_of_replicas":1}`)}) }, }, @@ -320,13 +310,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Settings.Get(nil, &opensearchapi.SettingsGetReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Settings.Get(nil, &opensearchapi.SettingsGetReq{Indices: []string{index}}) }, }, @@ -337,13 +327,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Flush(nil, &opensearchapi.IndicesFlushReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Flush(nil, &opensearchapi.IndicesFlushReq{Indices: []string{index}}) }, }, @@ -354,13 +344,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Forcemerge(nil, &opensearchapi.IndicesForcemergeReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Forcemerge(nil, &opensearchapi.IndicesForcemergeReq{Indices: []string{index}}) }, }, @@ -371,13 +361,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Clone(nil, opensearchapi.IndicesCloneReq{Index: index, Target: indexClone}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Clone(nil, opensearchapi.IndicesCloneReq{Index: index, Target: indexClone}) }, }, @@ -388,7 +378,7 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Split( nil, opensearchapi.IndicesSplitReq{ @@ -401,7 +391,7 @@ func TestIndicesClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Split(nil, opensearchapi.IndicesSplitReq{Index: index, Target: indexSplit}) }, }, @@ -412,7 +402,7 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Shrink( nil, opensearchapi.IndicesShrinkReq{ @@ -425,7 +415,7 @@ func TestIndicesClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Shrink(nil, opensearchapi.IndicesShrinkReq{Index: index, Target: indexClone}) }, }, @@ -436,13 +426,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Get(nil, opensearchapi.IndicesGetReq{Indices: []string{index, indexClone}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Get(nil, opensearchapi.IndicesGetReq{Indices: []string{index, indexClone}}) }, }, @@ -453,13 +443,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Recovery(nil, &opensearchapi.IndicesRecoveryReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Recovery(nil, &opensearchapi.IndicesRecoveryReq{Indices: []string{index}}) }, }, @@ -470,13 +460,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Refresh(nil, &opensearchapi.IndicesRefreshReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Refresh(nil, &opensearchapi.IndicesRefreshReq{Indices: []string{index}}) }, }, @@ -487,13 +477,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Segments(nil, &opensearchapi.IndicesSegmentsReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Segments(nil, &opensearchapi.IndicesSegmentsReq{Indices: []string{index}}) }, }, @@ -504,13 +494,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.ShardStores(nil, &opensearchapi.IndicesShardStoresReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.ShardStores(nil, &opensearchapi.IndicesShardStoresReq{Indices: []string{index}}) }, }, @@ -521,13 +511,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Stats(nil, &opensearchapi.IndicesStatsReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Stats(nil, &opensearchapi.IndicesStatsReq{Indices: []string{index}}) }, }, @@ -538,13 +528,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.ValidateQuery(nil, opensearchapi.IndicesValidateQueryReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.ValidateQuery(nil, opensearchapi.IndicesValidateQueryReq{Indices: []string{index}}) }, }, @@ -555,7 +545,7 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Count( nil, &opensearchapi.IndicesCountReq{ @@ -567,7 +557,7 @@ func TestIndicesClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Count(nil, nil) }, }, @@ -578,7 +568,7 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.FieldCaps( nil, opensearchapi.IndicesFieldCapsReq{ @@ -590,7 +580,7 @@ func TestIndicesClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.FieldCaps( nil, opensearchapi.IndicesFieldCapsReq{ @@ -606,13 +596,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Resolve(nil, opensearchapi.IndicesResolveReq{Indices: []string{index}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Resolve(nil, opensearchapi.IndicesResolveReq{}) }, }, @@ -623,13 +613,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Close(nil, opensearchapi.IndicesCloseReq{Index: index}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Close(nil, opensearchapi.IndicesCloseReq{Index: index}) }, }, @@ -640,13 +630,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Open(nil, opensearchapi.IndicesOpenReq{Index: index}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Open(nil, opensearchapi.IndicesOpenReq{Index: index}) }, }, @@ -657,13 +647,13 @@ func TestIndicesClient(t *testing.T) { Tests: []indicesTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: testIndices}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: testIndices}) }, }, @@ -674,15 +664,20 @@ func TestIndicesClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + if value.Name != "Exists" && value.Name != "Alias Exists" { + fmt.Println(value.Name) + require.NotNil(t, resp) + } + require.NotNil(t, httpResp) + assert.NotNil(t, httpResp) } }) } @@ -690,7 +685,7 @@ func TestIndicesClient(t *testing.T) { } t.Run("ValidateResponse", func(t *testing.T) { - _, err = client.Indices.Delete( + _, _, err = client.Indices.Delete( nil, opensearchapi.IndicesDeleteReq{ Indices: testIndices, @@ -700,103 +695,119 @@ func TestIndicesClient(t *testing.T) { require.Nil(t, err) t.Run("Create", func(t *testing.T) { - resp, err := client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) + resp, httpResp, err := client.Indices.Create(nil, opensearchapi.IndicesCreateReq{Index: index}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Block", func(t *testing.T) { - resp, err := client.Indices.Block(nil, opensearchapi.IndicesBlockReq{Indices: []string{index}, Block: "write"}) + resp, httpResp, err := client.Indices.Block(nil, opensearchapi.IndicesBlockReq{Indices: []string{index}, Block: "write"}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Analyze", func(t *testing.T) { - resp, err := client.Indices.Analyze(nil, opensearchapi.IndicesAnalyzeReq{Body: opensearchapi.IndicesAnalyzeBody{Text: []string{"test"}, Analyzer: "standard", Explain: true}}) + resp, httpResp, err := client.Indices.Analyze(nil, opensearchapi.IndicesAnalyzeReq{Body: opensearchapi.IndicesAnalyzeBody{Text: []string{"test"}, Analyzer: "standard", Explain: true}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("ClearCache", func(t *testing.T) { - resp, err := client.Indices.ClearCache(nil, &opensearchapi.IndicesClearCacheReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.ClearCache(nil, &opensearchapi.IndicesClearCacheReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Alias Put", func(t *testing.T) { - resp, err := client.Indices.Alias.Put(nil, opensearchapi.AliasPutReq{Indices: []string{index}, Alias: alias}) + resp, httpResp, err := client.Indices.Alias.Put(nil, opensearchapi.AliasPutReq{Indices: []string{index}, Alias: alias}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Alias Get", func(t *testing.T) { - resp, err := client.Indices.Alias.Get(nil, opensearchapi.AliasGetReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Alias.Get(nil, opensearchapi.AliasGetReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Rollover", func(t *testing.T) { - resp, err := client.Indices.Rollover(nil, opensearchapi.IndicesRolloverReq{Alias: alias, Index: indexRollover}) + resp, httpResp, err := client.Indices.Rollover(nil, opensearchapi.IndicesRolloverReq{Alias: alias, Index: indexRollover}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Alias Delete", func(t *testing.T) { - resp, err := client.Indices.Alias.Delete(nil, opensearchapi.AliasDeleteReq{Indices: []string{indexRollover}, Alias: []string{alias}}) + resp, httpResp, err := client.Indices.Alias.Delete(nil, opensearchapi.AliasDeleteReq{Indices: []string{indexRollover}, Alias: []string{alias}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Mapping Put", func(t *testing.T) { - resp, err := client.Indices.Mapping.Put(nil, opensearchapi.MappingPutReq{Indices: []string{index}, Body: strings.NewReader(`{"properties":{"test":{"type":"text"}}}`)}) + resp, httpResp, err := client.Indices.Mapping.Put(nil, opensearchapi.MappingPutReq{Indices: []string{index}, Body: strings.NewReader(`{"properties":{"test":{"type":"text"}}}`)}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Mapping Get", func(t *testing.T) { - resp, err := client.Indices.Mapping.Get(nil, &opensearchapi.MappingGetReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Mapping.Get(nil, &opensearchapi.MappingGetReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Mapping Field", func(t *testing.T) { - resp, err := client.Indices.Mapping.Field(nil, &opensearchapi.MappingFieldReq{Fields: []string{"*"}}) + resp, httpResp, err := client.Indices.Mapping.Field(nil, &opensearchapi.MappingFieldReq{Fields: []string{"*"}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Settings Put", func(t *testing.T) { - resp, err := client.Indices.Settings.Put(nil, opensearchapi.SettingsPutReq{Indices: []string{index}, Body: strings.NewReader(`{"number_of_replicas":1}`)}) + resp, httpResp, err := client.Indices.Settings.Put(nil, opensearchapi.SettingsPutReq{Indices: []string{index}, Body: strings.NewReader(`{"number_of_replicas":1}`)}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Settings Get", func(t *testing.T) { - resp, err := client.Indices.Settings.Get(nil, &opensearchapi.SettingsGetReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Settings.Get(nil, &opensearchapi.SettingsGetReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Flush", func(t *testing.T) { - resp, err := client.Indices.Flush(nil, &opensearchapi.IndicesFlushReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Flush(nil, &opensearchapi.IndicesFlushReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Forcemerge", func(t *testing.T) { - resp, err := client.Indices.Forcemerge(nil, &opensearchapi.IndicesForcemergeReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Forcemerge(nil, &opensearchapi.IndicesForcemergeReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Clone", func(t *testing.T) { - resp, err := client.Indices.Clone(nil, opensearchapi.IndicesCloneReq{Index: index, Target: indexClone}) + resp, httpResp, err := client.Indices.Clone(nil, opensearchapi.IndicesCloneReq{Index: index, Target: indexClone}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Split", func(t *testing.T) { - resp, err := client.Indices.Split( + resp, httpResp, err := client.Indices.Split( nil, opensearchapi.IndicesSplitReq{ Index: index, @@ -806,10 +817,11 @@ func TestIndicesClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Shrink", func(t *testing.T) { - resp, err := client.Indices.Shrink( + resp, httpResp, err := client.Indices.Shrink( nil, opensearchapi.IndicesShrinkReq{ Index: indexSplit, @@ -819,46 +831,53 @@ func TestIndicesClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Get", func(t *testing.T) { - resp, err := client.Indices.Get(nil, opensearchapi.IndicesGetReq{Indices: []string{index, indexClone}}) + resp, httpResp, err := client.Indices.Get(nil, opensearchapi.IndicesGetReq{Indices: []string{index, indexClone}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Recovery", func(t *testing.T) { - resp, err := client.Indices.Recovery(nil, &opensearchapi.IndicesRecoveryReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Recovery(nil, &opensearchapi.IndicesRecoveryReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Indices, httpResp) }) t.Run("Refresh", func(t *testing.T) { - resp, err := client.Indices.Refresh(nil, &opensearchapi.IndicesRefreshReq{Indices: []string{index}}) + resp, httpResp, err := client.Indices.Refresh(nil, &opensearchapi.IndicesRefreshReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Segments", func(t *testing.T) { - resp, err := client.Indices.Segments(nil, nil) + resp, httpResp, err := client.Indices.Segments(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("ShardStores", func(t *testing.T) { - resp, err := client.Indices.ShardStores(nil, nil) + resp, httpResp, err := client.Indices.ShardStores(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Stats", func(t *testing.T) { - resp, err := client.Indices.Stats(nil, nil) + resp, httpResp, err := client.Indices.Stats(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("ValidateQuery", func(t *testing.T) { - resp, err := client.Indices.ValidateQuery( + resp, httpResp, err := client.Indices.ValidateQuery( nil, opensearchapi.IndicesValidateQueryReq{ Indices: []string{index}, @@ -869,16 +888,18 @@ func TestIndicesClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Count", func(t *testing.T) { - resp, err := client.Indices.Count(nil, nil) + resp, httpResp, err := client.Indices.Count(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("FieldCaps", func(t *testing.T) { - resp, err := client.Indices.FieldCaps( + resp, httpResp, err := client.Indices.FieldCaps( nil, opensearchapi.IndicesFieldCapsReq{ Params: opensearchapi.IndicesFieldCapsParams{Fields: []string{"*"}}, @@ -886,31 +907,36 @@ func TestIndicesClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Resolve", func(t *testing.T) { - resp, err := client.Indices.Resolve(nil, opensearchapi.IndicesResolveReq{Indices: []string{"*"}}) + resp, httpResp, err := client.Indices.Resolve(nil, opensearchapi.IndicesResolveReq{Indices: []string{"*"}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Close", func(t *testing.T) { - resp, err := client.Indices.Close(nil, opensearchapi.IndicesCloseReq{Index: index}) + resp, httpResp, err := client.Indices.Close(nil, opensearchapi.IndicesCloseReq{Index: index}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Open", func(t *testing.T) { - resp, err := client.Indices.Open(nil, opensearchapi.IndicesOpenReq{Index: index}) + resp, httpResp, err := client.Indices.Open(nil, opensearchapi.IndicesOpenReq{Index: index}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Delete", func(t *testing.T) { - resp, err := client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: testIndices}) + resp, httpResp, err := client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: testIndices}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) }) } diff --git a/opensearchapi/api_info.go b/opensearchapi/api_info.go index fc4ceb489..70483f28b 100644 --- a/opensearchapi/api_info.go +++ b/opensearchapi/api_info.go @@ -14,20 +14,19 @@ import ( ) // Info executes a / request with the optional InfoReq -func (c Client) Info(ctx context.Context, req *InfoReq) (*InfoResp, error) { +func (c Client) Info(ctx context.Context, req *InfoReq) (*InfoResp, *opensearch.Response, error) { if req == nil { req = &InfoReq{} } - var ( - data InfoResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err + var data InfoResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // InfoReq represents possible options for the / request @@ -63,11 +62,5 @@ type InfoResp struct { MinimumWireCompatibilityVersion string `json:"minimum_wire_compatibility_version"` MinimumIndexCompatibilityVersion string `json:"minimum_index_compatibility_version"` } `json:"version"` - Tagline string `json:"tagline"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r InfoResp) Inspect() Inspect { - return Inspect{Response: r.response} + Tagline string `json:"tagline"` } diff --git a/opensearchapi/api_info_test.go b/opensearchapi/api_info_test.go index b04eaba4a..c7cd17f8c 100644 --- a/opensearchapi/api_info_test.go +++ b/opensearchapi/api_info_test.go @@ -23,26 +23,29 @@ func TestInfo(t *testing.T) { client, err := ostest.NewClient() require.Nil(t, err) t.Run("with nil request", func(t *testing.T) { - resp, err := client.Info(nil, nil) + resp, httpResp, err := client.Info(nil, nil) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("with request", func(t *testing.T) { - resp, err := client.Info(nil, &opensearchapi.InfoReq{}) + resp, httpResp, err := client.Info(nil, &opensearchapi.InfoReq{}) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Info(nil, nil) + res, httpResp, err := failingClient.Info(nil, nil) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_ingest-create.go b/opensearchapi/api_ingest-create.go index f5d7adc10..2fb8adcca 100644 --- a/opensearchapi/api_ingest-create.go +++ b/opensearchapi/api_ingest-create.go @@ -38,10 +38,4 @@ func (r IngestCreateReq) GetRequest() (*http.Request, error) { // IngestCreateResp represents the returned struct of the index create response type IngestCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IngestCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_ingest-delete.go b/opensearchapi/api_ingest-delete.go index 4e798d802..8c8296c3e 100644 --- a/opensearchapi/api_ingest-delete.go +++ b/opensearchapi/api_ingest-delete.go @@ -35,10 +35,4 @@ func (r IngestDeleteReq) GetRequest() (*http.Request, error) { // IngestDeleteResp represents the returned struct of the index create response type IngestDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IngestDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_ingest-get.go b/opensearchapi/api_ingest-get.go index 5ba24e314..87faeec4c 100644 --- a/opensearchapi/api_ingest-get.go +++ b/opensearchapi/api_ingest-get.go @@ -40,10 +40,4 @@ type IngestGetResp struct { Description string `json:"description"` Processors []map[string]json.RawMessage `json:"processors"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IngestGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_ingest-grok.go b/opensearchapi/api_ingest-grok.go index a6cdc4b6e..62bea5790 100644 --- a/opensearchapi/api_ingest-grok.go +++ b/opensearchapi/api_ingest-grok.go @@ -32,10 +32,4 @@ func (r IngestGrokReq) GetRequest() (*http.Request, error) { // IngestGrokResp represents the returned struct of the index create response type IngestGrokResp struct { Patterns map[string]string `json:"patterns"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IngestGrokResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_ingest-simulate.go b/opensearchapi/api_ingest-simulate.go index 1aa81e387..f1b26cda4 100644 --- a/opensearchapi/api_ingest-simulate.go +++ b/opensearchapi/api_ingest-simulate.go @@ -46,11 +46,5 @@ func (r IngestSimulateReq) GetRequest() (*http.Request, error) { // IngestSimulateResp represents the returned struct of the index create response type IngestSimulateResp struct { - Docs []json.RawMessage `json:"docs"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r IngestSimulateResp) Inspect() Inspect { - return Inspect{Response: r.response} + Docs []json.RawMessage `json:"docs"` } diff --git a/opensearchapi/api_ingest.go b/opensearchapi/api_ingest.go index 4734a42ab..f36793669 100644 --- a/opensearchapi/api_ingest.go +++ b/opensearchapi/api_ingest.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type ingestClient struct { @@ -15,74 +16,69 @@ type ingestClient struct { } // Create executes a creade ingest request with the required IngestCreateReq -func (c ingestClient) Create(ctx context.Context, req IngestCreateReq) (*IngestCreateResp, error) { - var ( - data IngestCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c ingestClient) Create(ctx context.Context, req IngestCreateReq) (*IngestCreateResp, *opensearch.Response, error) { + var data IngestCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete ingest request with the required IngestDeleteReq -func (c ingestClient) Delete(ctx context.Context, req IngestDeleteReq) (*IngestDeleteResp, error) { - var ( - data IngestDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c ingestClient) Delete(ctx context.Context, req IngestDeleteReq) (*IngestDeleteResp, *opensearch.Response, error) { + var data IngestDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get ingest request with the optional IngestGetReq -func (c ingestClient) Get(ctx context.Context, req *IngestGetReq) (*IngestGetResp, error) { +func (c ingestClient) Get(ctx context.Context, req *IngestGetReq) (*IngestGetResp, *opensearch.Response, error) { if req == nil { req = &IngestGetReq{} } - var ( - data IngestGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Pipelines); err != nil { - return &data, err + var data IngestGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Pipelines) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Simulate executes a stats ingest request with the optional IngestSimulateReq -func (c ingestClient) Simulate(ctx context.Context, req IngestSimulateReq) (*IngestSimulateResp, error) { - var ( - data IngestSimulateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c ingestClient) Simulate(ctx context.Context, req IngestSimulateReq) (*IngestSimulateResp, *opensearch.Response, error) { + var data IngestSimulateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Grok executes a get ingest request with the optional IngestGrokReq -func (c ingestClient) Grok(ctx context.Context, req *IngestGrokReq) (*IngestGrokResp, error) { +func (c ingestClient) Grok(ctx context.Context, req *IngestGrokReq) (*IngestGrokResp, *opensearch.Response, error) { if req == nil { req = &IngestGrokReq{} } - var ( - data IngestGrokResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data IngestGrokResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_ingest_test.go b/opensearchapi/api_ingest_test.go index 6591a238d..b5da7a19c 100644 --- a/opensearchapi/api_ingest_test.go +++ b/opensearchapi/api_ingest_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -30,7 +31,7 @@ func TestIngestClient(t *testing.T) { type ingestTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -42,7 +43,7 @@ func TestIngestClient(t *testing.T) { Tests: []ingestTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Ingest.Create( nil, opensearchapi.IngestCreateReq{ @@ -54,7 +55,7 @@ func TestIngestClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Ingest.Create(nil, opensearchapi.IngestCreateReq{}) }, }, @@ -65,13 +66,13 @@ func TestIngestClient(t *testing.T) { Tests: []ingestTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Ingest.Get(nil, &opensearchapi.IngestGetReq{PipelineIDs: []string{ingest}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Ingest.Get(nil, nil) }, }, @@ -82,13 +83,13 @@ func TestIngestClient(t *testing.T) { Tests: []ingestTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Ingest.Grok(nil, nil) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Ingest.Grok(nil, nil) }, }, @@ -99,7 +100,7 @@ func TestIngestClient(t *testing.T) { Tests: []ingestTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Ingest.Simulate( nil, opensearchapi.IngestSimulateReq{ @@ -112,7 +113,7 @@ func TestIngestClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Ingest.Simulate(nil, opensearchapi.IngestSimulateReq{}) }, }, @@ -123,13 +124,13 @@ func TestIngestClient(t *testing.T) { Tests: []ingestTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Ingest.Delete(nil, opensearchapi.IngestDeleteReq{PipelineID: ingest}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Ingest.Delete(nil, opensearchapi.IngestDeleteReq{PipelineID: ingest}) }, }, @@ -140,17 +141,17 @@ func TestIngestClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) if value.Name != "Get" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) @@ -162,7 +163,7 @@ func TestIngestClient(t *testing.T) { t.Cleanup(func() { failingClient.Ingest.Delete(nil, opensearchapi.IngestDeleteReq{PipelineID: ingest}) }) - _, err := client.Ingest.Create( + _, _, err := client.Ingest.Create( nil, opensearchapi.IngestCreateReq{ PipelineID: ingest, @@ -171,11 +172,11 @@ func TestIngestClient(t *testing.T) { ) require.Nil(t, err) - resp, err := client.Ingest.Get(nil, nil) + resp, httpResp, err := client.Ingest.Get(nil, nil) require.Nil(t, err) require.NotNil(t, resp) - require.NotNil(t, resp.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, resp.Pipelines, resp.Inspect().Response) + require.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Pipelines, httpResp) }) }) } diff --git a/opensearchapi/api_mget.go b/opensearchapi/api_mget.go index 11a306725..585f1841d 100644 --- a/opensearchapi/api_mget.go +++ b/opensearchapi/api_mget.go @@ -17,16 +17,15 @@ import ( ) // MGet executes a /_mget request with the optional MGetReq -func (c Client) MGet(ctx context.Context, req MGetReq) (*MGetResp, error) { - var ( - data MGetResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) MGet(ctx context.Context, req MGetReq) (*MGetResp, *opensearch.Response, error) { + var data MGetResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // MGetReq represents possible options for the /_mget request @@ -69,10 +68,4 @@ type MGetResp struct { Type string `json:"_type"` Source json.RawMessage `json:"_source"` } `json:"docs"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_mget_test.go b/opensearchapi/api_mget_test.go index be640d633..5063ec649 100644 --- a/opensearchapi/api_mget_test.go +++ b/opensearchapi/api_mget_test.go @@ -31,7 +31,7 @@ func TestMGet(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestMGet(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.MGet( + resp, httpResp, err := client.MGet( nil, opensearchapi.MGetReq{ Index: testIndex, @@ -53,16 +53,18 @@ func TestMGet(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.MGet(nil, opensearchapi.MGetReq{}) + res, httpResp, err := failingClient.MGet(nil, opensearchapi.MGetReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_msearch-template.go b/opensearchapi/api_msearch-template.go index b6206ef03..d3da007ac 100644 --- a/opensearchapi/api_msearch-template.go +++ b/opensearchapi/api_msearch-template.go @@ -16,16 +16,15 @@ import ( ) // MSearchTemplate executes a /_msearch request with the optional MSearchTemplateReq -func (c Client) MSearchTemplate(ctx context.Context, req MSearchTemplateReq) (*MSearchTemplateResp, error) { - var ( - data MSearchTemplateResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) MSearchTemplate(ctx context.Context, req MSearchTemplateReq) (*MSearchTemplateResp, *opensearch.Response, error) { + var data MSearchTemplateResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // MSearchTemplateReq represents possible options for the /_msearch request @@ -74,10 +73,4 @@ type MSearchTemplateResp struct { } `json:"hits"` Status int `json:"status"` } `json:"responses"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MSearchTemplateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_msearch-template_test.go b/opensearchapi/api_msearch-template_test.go index 9d7927910..468c02ee7 100644 --- a/opensearchapi/api_msearch-template_test.go +++ b/opensearchapi/api_msearch-template_test.go @@ -31,7 +31,7 @@ func TestMSearchTemplate(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestMSearchTemplate(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.MSearchTemplate( + resp, httpResp, err := client.MSearchTemplate( nil, opensearchapi.MSearchTemplateReq{ Indices: []string{testIndex}, @@ -53,16 +53,18 @@ func TestMSearchTemplate(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.MSearchTemplate(nil, opensearchapi.MSearchTemplateReq{}) + res, httpResp, err := failingClient.MSearchTemplate(nil, opensearchapi.MSearchTemplateReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_msearch.go b/opensearchapi/api_msearch.go index d3591b91f..ed9ee98c1 100644 --- a/opensearchapi/api_msearch.go +++ b/opensearchapi/api_msearch.go @@ -16,16 +16,15 @@ import ( ) // MSearch executes a /_msearch request with the optional MSearchReq -func (c Client) MSearch(ctx context.Context, req MSearchReq) (*MSearchResp, error) { - var ( - data MSearchResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) MSearch(ctx context.Context, req MSearchReq) (*MSearchResp, *opensearch.Response, error) { + var data MSearchResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // MSearchReq represents possible options for the /_msearch request @@ -74,10 +73,4 @@ type MSearchResp struct { } `json:"hits"` Status int `json:"status"` } `json:"responses"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MSearchResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_msearch_test.go b/opensearchapi/api_msearch_test.go index 319c9b3cc..7e9c75f68 100644 --- a/opensearchapi/api_msearch_test.go +++ b/opensearchapi/api_msearch_test.go @@ -31,7 +31,7 @@ func TestMSearch(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestMSearch(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.MSearch( + resp, httpResp, err := client.MSearch( nil, opensearchapi.MSearchReq{ Indices: []string{testIndex}, @@ -53,16 +53,18 @@ func TestMSearch(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.MSearch(nil, opensearchapi.MSearchReq{}) + res, httpResp, err := failingClient.MSearch(nil, opensearchapi.MSearchReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_mtermvectors.go b/opensearchapi/api_mtermvectors.go index 7c30187f8..d5bf00fe6 100644 --- a/opensearchapi/api_mtermvectors.go +++ b/opensearchapi/api_mtermvectors.go @@ -17,16 +17,15 @@ import ( ) // MTermvectors executes a /_mtermvectors request with the required MTermvectorsReq -func (c Client) MTermvectors(ctx context.Context, req MTermvectorsReq) (*MTermvectorsResp, error) { - var ( - data MTermvectorsResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) MTermvectors(ctx context.Context, req MTermvectorsReq) (*MTermvectorsResp, *opensearch.Response, error) { + var data MTermvectorsResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // MTermvectorsReq represents possible options for the /_mtermvectors request @@ -68,10 +67,4 @@ type MTermvectorsResp struct { Type string `json:"_type"` // Deprecated field TermVectors json.RawMessage `json:"term_vectors"` } `json:"docs"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r MTermvectorsResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_mtermvectors_test.go b/opensearchapi/api_mtermvectors_test.go index c74f30230..4cf4905db 100644 --- a/opensearchapi/api_mtermvectors_test.go +++ b/opensearchapi/api_mtermvectors_test.go @@ -30,7 +30,7 @@ func TestMTermvectors(t *testing.T) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}}) }) - _, err = client.Indices.Create( + _, _, err = client.Indices.Create( nil, opensearchapi.IndicesCreateReq{ Index: testIndex, @@ -73,7 +73,7 @@ func TestMTermvectors(t *testing.T) { require.Nil(t, err) docs := []string{`{"fullname":"John Doe","text":"test test test "}`, `{"fullname":"Jane Doe","text":"Another test ..."}`} for i, doc := range docs { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -86,7 +86,7 @@ func TestMTermvectors(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.MTermvectors( + resp, httpResp, err := client.MTermvectors( nil, opensearchapi.MTermvectorsReq{ Index: testIndex, @@ -95,16 +95,18 @@ func TestMTermvectors(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.MTermvectors(nil, opensearchapi.MTermvectorsReq{}) + res, httpResp, err := failingClient.MTermvectors(nil, opensearchapi.MTermvectorsReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_nodes-info.go b/opensearchapi/api_nodes-info.go index 6207e91be..824d475a5 100644 --- a/opensearchapi/api_nodes-info.go +++ b/opensearchapi/api_nodes-info.go @@ -61,12 +61,6 @@ type NodesInfoResp struct { } `json:"_nodes"` ClusterName string `json:"cluster_name"` Nodes map[string]NodesInfo `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r NodesInfoResp) Inspect() Inspect { - return Inspect{Response: r.response} } // NodesInfo is a sub type of NodesInfoResp containing information about nodes and their stats diff --git a/opensearchapi/api_nodes-reload_security.go b/opensearchapi/api_nodes-reload_security.go index a3ca438d3..dde9e2b62 100644 --- a/opensearchapi/api_nodes-reload_security.go +++ b/opensearchapi/api_nodes-reload_security.go @@ -60,10 +60,4 @@ type NodesReloadSecurityResp struct { Nodes map[string]struct { Name string `json:"name"` } `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r NodesReloadSecurityResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_nodes-stats.go b/opensearchapi/api_nodes-stats.go index b37c87d01..fe8e65860 100644 --- a/opensearchapi/api_nodes-stats.go +++ b/opensearchapi/api_nodes-stats.go @@ -69,12 +69,6 @@ type NodesStatsResp struct { } `json:"_nodes"` ClusterName string `json:"cluster_name"` Nodes map[string]NodesStats `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r NodesStatsResp) Inspect() Inspect { - return Inspect{Response: r.response} } // NodesStats is a map item of NodesStatsResp representing all values of a node diff --git a/opensearchapi/api_nodes-usage.go b/opensearchapi/api_nodes-usage.go index 8f3a678fa..5c95f2af5 100644 --- a/opensearchapi/api_nodes-usage.go +++ b/opensearchapi/api_nodes-usage.go @@ -62,12 +62,6 @@ type NodesUsageResp struct { } `json:"_nodes"` ClusterName string `json:"cluster_name"` Nodes map[string]NodesUsage `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r NodesUsageResp) Inspect() Inspect { - return Inspect{Response: r.response} } // NodesUsage is a sub type of NodesUsageResp containing stats about rest api actions diff --git a/opensearchapi/api_nodes.go b/opensearchapi/api_nodes.go index 8de0fc75a..06c3ef0b0 100644 --- a/opensearchapi/api_nodes.go +++ b/opensearchapi/api_nodes.go @@ -17,37 +17,35 @@ type nodesClient struct { } // Stats executes a /_nodes/_stats request with the optional NodesStatsReq -func (c nodesClient) Stats(ctx context.Context, req *NodesStatsReq) (*NodesStatsResp, error) { +func (c nodesClient) Stats(ctx context.Context, req *NodesStatsReq) (*NodesStatsResp, *opensearch.Response, error) { if req == nil { req = &NodesStatsReq{} } - var ( - data NodesStatsResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data NodesStatsResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Info executes a /_nodes request with the optional NodesInfoReq -func (c nodesClient) Info(ctx context.Context, req *NodesInfoReq) (*NodesInfoResp, error) { +func (c nodesClient) Info(ctx context.Context, req *NodesInfoReq) (*NodesInfoResp, *opensearch.Response, error) { if req == nil { req = &NodesInfoReq{} } - var ( - data NodesInfoResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data NodesInfoResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // HotThreads executes a /_nodes/hot_threads request with the optional NodesHotThreadsReq @@ -59,35 +57,33 @@ func (c nodesClient) HotThreads(ctx context.Context, req *NodesHotThreadsReq) (* } // ReloadSecurity executes a /_nodes/reload_secure_settings request with the optional NodesReloadSecurityReq -func (c nodesClient) ReloadSecurity(ctx context.Context, req *NodesReloadSecurityReq) (*NodesReloadSecurityResp, error) { +func (c nodesClient) ReloadSecurity(ctx context.Context, req *NodesReloadSecurityReq) (*NodesReloadSecurityResp, *opensearch.Response, error) { if req == nil { req = &NodesReloadSecurityReq{} } - var ( - data NodesReloadSecurityResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data NodesReloadSecurityResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Usage executes a /_nodes/usage request with the optional NodesUsageReq -func (c nodesClient) Usage(ctx context.Context, req *NodesUsageReq) (*NodesUsageResp, error) { +func (c nodesClient) Usage(ctx context.Context, req *NodesUsageReq) (*NodesUsageResp, *opensearch.Response, error) { if req == nil { req = &NodesUsageReq{} } - var ( - data NodesUsageResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data NodesUsageResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_nodes_test.go b/opensearchapi/api_nodes_test.go index bba670d69..dfe0764fd 100644 --- a/opensearchapi/api_nodes_test.go +++ b/opensearchapi/api_nodes_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "testing" "github.com/stretchr/testify/assert" @@ -27,7 +28,7 @@ func TestNodes(t *testing.T) { type nodesTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -39,19 +40,19 @@ func TestNodes(t *testing.T) { Tests: []nodesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Stats(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Stats(nil, &opensearchapi.NodesStatsReq{NodeID: []string{"*"}, Metric: []string{"indices"}, IndexMetric: []string{"store"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Nodes.Stats(nil, nil) }, }, @@ -62,19 +63,19 @@ func TestNodes(t *testing.T) { Tests: []nodesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Info(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Info(nil, &opensearchapi.NodesInfoReq{NodeID: []string{"*"}, Metrics: []string{"settings", "os"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Nodes.Info(nil, nil) }, }, @@ -85,35 +86,26 @@ func TestNodes(t *testing.T) { Tests: []nodesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Nodes.HotThreads(nil, nil) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Nodes.HotThreads(nil, nil) + + return nil, httpResp, err }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Nodes.HotThreads(nil, &opensearchapi.NodesHotThreadsReq{NodeID: []string{"*"}}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Nodes.HotThreads(nil, &opensearchapi.NodesHotThreadsReq{NodeID: []string{"*"}}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Nodes.HotThreads(nil, nil) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Nodes.HotThreads(nil, nil) + + return nil, httpResp, err }, }, }, @@ -123,19 +115,19 @@ func TestNodes(t *testing.T) { Tests: []nodesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.ReloadSecurity(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.ReloadSecurity(nil, &opensearchapi.NodesReloadSecurityReq{NodeID: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Nodes.ReloadSecurity(nil, nil) }, }, @@ -146,19 +138,19 @@ func TestNodes(t *testing.T) { Tests: []nodesTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Usage(nil, nil) }, }, { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Nodes.Usage(nil, &opensearchapi.NodesUsageReq{NodeID: []string{"*"}, Metrics: []string{"*"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Nodes.Usage(nil, nil) }, }, @@ -169,17 +161,20 @@ func TestNodes(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) if value.Name != "HotThreads" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + require.NotNil(t, resp) + } + assert.NotNil(t, httpResp) + if value.Name != "HotThreads" { + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) diff --git a/opensearchapi/api_ping_test.go b/opensearchapi/api_ping_test.go index 74cb00fe1..af951b49e 100644 --- a/opensearchapi/api_ping_test.go +++ b/opensearchapi/api_ping_test.go @@ -39,12 +39,9 @@ func TestPing(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - var ( - resp osapitest.DummyInspect - ) - resp.Response, err = failingClient.Ping(nil, nil) + httpResp, err := failingClient.Ping(nil, nil) assert.NotNil(t, err) - assert.NotNil(t, resp) - osapitest.VerifyInspect(t, resp.Inspect()) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_point_in_time-create.go b/opensearchapi/api_point_in_time-create.go index 5903dd89c..ecea9fd74 100644 --- a/opensearchapi/api_point_in_time-create.go +++ b/opensearchapi/api_point_in_time-create.go @@ -52,10 +52,4 @@ type PointInTimeCreateResp struct { Failed int `json:"failed"` } `json:"_shards"` CreationTime int64 `json:"creation_time"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r PointInTimeCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_point_in_time-delete.go b/opensearchapi/api_point_in_time-delete.go index 6d6f82121..b82ddb566 100644 --- a/opensearchapi/api_point_in_time-delete.go +++ b/opensearchapi/api_point_in_time-delete.go @@ -55,10 +55,4 @@ type PointInTimeDeleteResp struct { PitID string `json:"pit_id"` Successful bool `json:"successful"` } `json:"pits"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r PointInTimeDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_point_in_time-get.go b/opensearchapi/api_point_in_time-get.go index 0fcf3982f..8b1a4545c 100644 --- a/opensearchapi/api_point_in_time-get.go +++ b/opensearchapi/api_point_in_time-get.go @@ -36,10 +36,4 @@ type PointInTimeGetResp struct { CreationTime int `json:"creation_time"` KeepAlive int64 `json:"keep_alive"` } `json:"pits"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r PointInTimeGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_point_in_time.go b/opensearchapi/api_point_in_time.go index bc1a80af7..52aeb0b05 100644 --- a/opensearchapi/api_point_in_time.go +++ b/opensearchapi/api_point_in_time.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type pointInTimeClient struct { @@ -15,44 +16,41 @@ type pointInTimeClient struct { } // Create executes a creade pointInTime request with the required PointInTimeCreateReq -func (c pointInTimeClient) Create(ctx context.Context, req PointInTimeCreateReq) (*PointInTimeCreateResp, error) { - var ( - data PointInTimeCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c pointInTimeClient) Create(ctx context.Context, req PointInTimeCreateReq) (*PointInTimeCreateResp, *opensearch.Response, error) { + var data PointInTimeCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete pointInTime request with the required PointInTimeDeleteReq -func (c pointInTimeClient) Delete(ctx context.Context, req PointInTimeDeleteReq) (*PointInTimeDeleteResp, error) { - var ( - data PointInTimeDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c pointInTimeClient) Delete(ctx context.Context, req PointInTimeDeleteReq) (*PointInTimeDeleteResp, *opensearch.Response, error) { + var data PointInTimeDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get pointInTime request with the optional PointInTimeGetReq -func (c pointInTimeClient) Get(ctx context.Context, req *PointInTimeGetReq) (*PointInTimeGetResp, error) { +func (c pointInTimeClient) Get(ctx context.Context, req *PointInTimeGetReq) (*PointInTimeGetResp, *opensearch.Response, error) { if req == nil { req = &PointInTimeGetReq{} } - var ( - data PointInTimeGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data PointInTimeGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_point_in_time_test.go b/opensearchapi/api_point_in_time_test.go index c642a8ffe..1fb96d40f 100644 --- a/opensearchapi/api_point_in_time_test.go +++ b/opensearchapi/api_point_in_time_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "testing" "time" @@ -31,7 +32,7 @@ func TestPointInTimeClient(t *testing.T) { type pointInTimeTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -43,9 +44,9 @@ func TestPointInTimeClient(t *testing.T) { Tests: []pointInTimeTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { keepAlive, _ := time.ParseDuration("5m") - resp, err := client.PointInTime.Create( + resp, httpResp, err := client.PointInTime.Create( nil, opensearchapi.PointInTimeCreateReq{ Indices: []string{"*"}, @@ -53,12 +54,12 @@ func TestPointInTimeClient(t *testing.T) { }, ) pitID = resp.PitID - return resp, err + return resp, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.PointInTime.Create(nil, opensearchapi.PointInTimeCreateReq{}) }, }, @@ -69,13 +70,13 @@ func TestPointInTimeClient(t *testing.T) { Tests: []pointInTimeTests{ { Name: "without request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.PointInTime.Get(nil, nil) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.PointInTime.Get(nil, nil) }, }, @@ -86,13 +87,13 @@ func TestPointInTimeClient(t *testing.T) { Tests: []pointInTimeTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.PointInTime.Delete(nil, opensearchapi.PointInTimeDeleteReq{PitID: []string{pitID}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.PointInTime.Delete(nil, opensearchapi.PointInTimeDeleteReq{}) }, }, @@ -103,16 +104,17 @@ func TestPointInTimeClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } }) } diff --git a/opensearchapi/api_rank_eval.go b/opensearchapi/api_rank_eval.go index 1aa1bc302..b1f58d269 100644 --- a/opensearchapi/api_rank_eval.go +++ b/opensearchapi/api_rank_eval.go @@ -17,16 +17,15 @@ import ( ) // RankEval executes a /_rank_eval request with the required RankEvalReq -func (c Client) RankEval(ctx context.Context, req RankEvalReq) (*RankEvalResp, error) { - var ( - data RankEvalResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) RankEval(ctx context.Context, req RankEvalReq) (*RankEvalResp, *opensearch.Response, error) { + var data RankEvalResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // RankEvalReq represents possible options for the /_rank_eval request @@ -63,10 +62,4 @@ type RankEvalResp struct { MetricScore float64 `json:"metric_score"` Details json.RawMessage `json:"details"` Failures json.RawMessage `json:"failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r RankEvalResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_rank_eval_test.go b/opensearchapi/api_rank_eval_test.go index dfed0fe04..5d70b7a18 100644 --- a/opensearchapi/api_rank_eval_test.go +++ b/opensearchapi/api_rank_eval_test.go @@ -31,7 +31,7 @@ func TestRankEval(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestRankEval(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.RankEval( + resp, httpResp, err := client.RankEval( nil, opensearchapi.RankEvalReq{ Indices: []string{testIndex}, @@ -53,16 +53,18 @@ func TestRankEval(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.RankEval(nil, opensearchapi.RankEvalReq{}) + res, httpResp, err := failingClient.RankEval(nil, opensearchapi.RankEvalReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_reindex.go b/opensearchapi/api_reindex.go index 05034e0be..4606cfd5b 100644 --- a/opensearchapi/api_reindex.go +++ b/opensearchapi/api_reindex.go @@ -16,16 +16,15 @@ import ( ) // Reindex executes a / request with the optional ReindexReq -func (c Client) Reindex(ctx context.Context, req ReindexReq) (*ReindexResp, error) { - var ( - data ReindexResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Reindex(ctx context.Context, req ReindexReq) (*ReindexResp, *opensearch.Response, error) { + var data ReindexResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ReindexReq represents possible options for the / request @@ -67,10 +66,4 @@ type ReindexResp struct { ThrottledUntilMillis int `json:"throttled_until_millis"` Failures []json.RawMessage `json:"failures"` Task string `json:"task"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ReindexResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_reindex_rethrottle.go b/opensearchapi/api_reindex_rethrottle.go index ec123ab9a..4de028d43 100644 --- a/opensearchapi/api_reindex_rethrottle.go +++ b/opensearchapi/api_reindex_rethrottle.go @@ -16,16 +16,15 @@ import ( ) // ReindexRethrottle executes a / request with the optional ReindexRethrottleReq -func (c Client) ReindexRethrottle(ctx context.Context, req ReindexRethrottleReq) (*ReindexRethrottleResp, error) { - var ( - data ReindexRethrottleResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) ReindexRethrottle(ctx context.Context, req ReindexRethrottleReq) (*ReindexRethrottleResp, *opensearch.Response, error) { + var data ReindexRethrottleResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // ReindexRethrottleReq represents possible options for the / request @@ -108,10 +107,4 @@ type ReindexRethrottleResp struct { } `json:"tasks"` } `json:"nodes"` NodeFailures []FailuresCause `json:"node_failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ReindexRethrottleResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_reindex_rethrottle_test.go b/opensearchapi/api_reindex_rethrottle_test.go index e6594d049..416d05274 100644 --- a/opensearchapi/api_reindex_rethrottle_test.go +++ b/opensearchapi/api_reindex_rethrottle_test.go @@ -70,7 +70,7 @@ func TestReindexRethrottle(t *testing.T) { t.Errorf("Unexpected error: %s", err) } - reindex, err := client.Reindex( + reindex, _, err := client.Reindex( nil, opensearchapi.ReindexReq{ Body: strings.NewReader(fmt.Sprintf(`{"source":{"index":"%s","size":1},"dest":{"index":"%s"}}`, sourceIndex, destIndex)), @@ -82,7 +82,7 @@ func TestReindexRethrottle(t *testing.T) { ) require.Nil(t, err) t.Run("with request", func(t *testing.T) { - resp, err := client.ReindexRethrottle( + resp, httpResp, err := client.ReindexRethrottle( nil, opensearchapi.ReindexRethrottleReq{ TaskID: reindex.Task, @@ -91,16 +91,18 @@ func TestReindexRethrottle(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.ReindexRethrottle(nil, opensearchapi.ReindexRethrottleReq{}) + resp, httpResp, err := failingClient.ReindexRethrottle(nil, opensearchapi.ReindexRethrottleReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_reindex_test.go b/opensearchapi/api_reindex_test.go index 8bf0ea5e3..45a577a3e 100644 --- a/opensearchapi/api_reindex_test.go +++ b/opensearchapi/api_reindex_test.go @@ -72,7 +72,7 @@ func TestReindex(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.Reindex( + resp, httpResp, err := client.Reindex( nil, opensearchapi.ReindexReq{ Body: strings.NewReader(fmt.Sprintf(`{"source":{"index":"%s"},"dest":{"index":"%s"}}`, sourceIndex, destIndex)), @@ -80,11 +80,12 @@ func TestReindex(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("with request but dont wait", func(t *testing.T) { - resp, err := client.Reindex( + resp, httpResp, err := client.Reindex( nil, opensearchapi.ReindexReq{ Body: strings.NewReader(fmt.Sprintf(`{"source":{"index":"%s"},"dest":{"index":"%s"}}`, sourceIndex, destIndex)), @@ -93,16 +94,18 @@ func TestReindex(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Reindex(nil, opensearchapi.ReindexReq{}) + res, httpResp, err := failingClient.Reindex(nil, opensearchapi.ReindexReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_render_search_template.go b/opensearchapi/api_render_search_template.go index b419221fb..6219c4433 100644 --- a/opensearchapi/api_render_search_template.go +++ b/opensearchapi/api_render_search_template.go @@ -17,16 +17,15 @@ import ( ) // RenderSearchTemplate executes a /_render/template request with the required RenderSearchTemplateReq -func (c Client) RenderSearchTemplate(ctx context.Context, req RenderSearchTemplateReq) (*RenderSearchTemplateResp, error) { - var ( - data RenderSearchTemplateResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) RenderSearchTemplate(ctx context.Context, req RenderSearchTemplateReq) (*RenderSearchTemplateResp, *opensearch.Response, error) { + var data RenderSearchTemplateResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // RenderSearchTemplateReq represents possible options for the /_render/template request @@ -60,10 +59,4 @@ func (r RenderSearchTemplateReq) GetRequest() (*http.Request, error) { // RenderSearchTemplateResp represents the returned struct of the /_render/template response type RenderSearchTemplateResp struct { TemplateOutput json.RawMessage `json:"template_output"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r RenderSearchTemplateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_render_search_template_test.go b/opensearchapi/api_render_search_template_test.go index 0aca1aae7..b9ac2e481 100644 --- a/opensearchapi/api_render_search_template_test.go +++ b/opensearchapi/api_render_search_template_test.go @@ -38,7 +38,7 @@ func TestRenderSearchTemplate(t *testing.T) { client.Script.Delete(nil, opensearchapi.ScriptDeleteReq{ScriptID: testScript}) }) - _, err = client.Script.Put( + _, _, err = client.Script.Put( nil, opensearchapi.ScriptPutReq{ ScriptID: testScript, @@ -48,7 +48,7 @@ func TestRenderSearchTemplate(t *testing.T) { require.Nil(t, err) t.Run("with request", func(t *testing.T) { - resp, err := client.RenderSearchTemplate( + resp, httpResp, err := client.RenderSearchTemplate( nil, opensearchapi.RenderSearchTemplateReq{ TemplateID: testScript, @@ -57,16 +57,18 @@ func TestRenderSearchTemplate(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.RenderSearchTemplate(nil, opensearchapi.RenderSearchTemplateReq{}) + res, httpResp, err := failingClient.RenderSearchTemplate(nil, opensearchapi.RenderSearchTemplateReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_script-context.go b/opensearchapi/api_script-context.go index 1e42f69fa..5dec1e485 100644 --- a/opensearchapi/api_script-context.go +++ b/opensearchapi/api_script-context.go @@ -42,10 +42,4 @@ type ScriptContextResp struct { } `json:"params"` } `json:"methods"` } `json:"contexts"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptContextResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_script-delete.go b/opensearchapi/api_script-delete.go index 3d033955c..60d1af9bb 100644 --- a/opensearchapi/api_script-delete.go +++ b/opensearchapi/api_script-delete.go @@ -35,10 +35,4 @@ func (r ScriptDeleteReq) GetRequest() (*http.Request, error) { // ScriptDeleteResp represents the returned struct of the delete script response type ScriptDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_script-get.go b/opensearchapi/api_script-get.go index fb2948ccb..1d29ebbaf 100644 --- a/opensearchapi/api_script-get.go +++ b/opensearchapi/api_script-get.go @@ -40,10 +40,4 @@ type ScriptGetResp struct { Lang string `json:"lang"` Source string `json:"source"` } `json:"script"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_script-language.go b/opensearchapi/api_script-language.go index 26cf2eb14..d9692472d 100644 --- a/opensearchapi/api_script-language.go +++ b/opensearchapi/api_script-language.go @@ -36,10 +36,4 @@ type ScriptLanguageResp struct { Language string `json:"language"` Contexts []string `json:"contexts"` } `json:"language_contexts"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptLanguageResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_script-painless_execute.go b/opensearchapi/api_script-painless_execute.go index 21c63d807..c82a0b6f4 100644 --- a/opensearchapi/api_script-painless_execute.go +++ b/opensearchapi/api_script-painless_execute.go @@ -35,11 +35,5 @@ func (r ScriptPainlessExecuteReq) GetRequest() (*http.Request, error) { // ScriptPainlessExecuteResp represents the returned struct of the delete script response type ScriptPainlessExecuteResp struct { - Result json.RawMessage `json:"result"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptPainlessExecuteResp) Inspect() Inspect { - return Inspect{Response: r.response} + Result json.RawMessage `json:"result"` } diff --git a/opensearchapi/api_script-put.go b/opensearchapi/api_script-put.go index 6af90dc66..db2176b17 100644 --- a/opensearchapi/api_script-put.go +++ b/opensearchapi/api_script-put.go @@ -48,10 +48,4 @@ func (r ScriptPutReq) GetRequest() (*http.Request, error) { // ScriptPutResp represents the returned struct of the put script response type ScriptPutResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScriptPutResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_script.go b/opensearchapi/api_script.go index 2e3e0b60f..daceed0ce 100644 --- a/opensearchapi/api_script.go +++ b/opensearchapi/api_script.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type scriptClient struct { @@ -15,87 +16,81 @@ type scriptClient struct { } // Delete executes a delete script request with the required ScriptDeleteReq -func (c scriptClient) Delete(ctx context.Context, req ScriptDeleteReq) (*ScriptDeleteResp, error) { - var ( - data ScriptDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scriptClient) Delete(ctx context.Context, req ScriptDeleteReq) (*ScriptDeleteResp, *opensearch.Response, error) { + var data ScriptDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Put executes an put script request with the required ScriptPutReq -func (c scriptClient) Put(ctx context.Context, req ScriptPutReq) (*ScriptPutResp, error) { - var ( - data ScriptPutResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scriptClient) Put(ctx context.Context, req ScriptPutReq) (*ScriptPutResp, *opensearch.Response, error) { + var data ScriptPutResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a /_script request with the required ScriptGetReq -func (c scriptClient) Get(ctx context.Context, req ScriptGetReq) (*ScriptGetResp, error) { - var ( - data ScriptGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scriptClient) Get(ctx context.Context, req ScriptGetReq) (*ScriptGetResp, *opensearch.Response, error) { + var data ScriptGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Context executes a /_script_context request with the optional ScriptContextReq -func (c scriptClient) Context(ctx context.Context, req *ScriptContextReq) (*ScriptContextResp, error) { +func (c scriptClient) Context(ctx context.Context, req *ScriptContextReq) (*ScriptContextResp, *opensearch.Response, error) { if req == nil { req = &ScriptContextReq{} } - var ( - data ScriptContextResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ScriptContextResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Language executes a /_script_context request with the optional ScriptLanguageReq -func (c scriptClient) Language(ctx context.Context, req *ScriptLanguageReq) (*ScriptLanguageResp, error) { +func (c scriptClient) Language(ctx context.Context, req *ScriptLanguageReq) (*ScriptLanguageResp, *opensearch.Response, error) { if req == nil { req = &ScriptLanguageReq{} } - var ( - data ScriptLanguageResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data ScriptLanguageResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // PainlessExecute executes a /_script request with the required ScriptPainlessExecuteReq -func (c scriptClient) PainlessExecute(ctx context.Context, req ScriptPainlessExecuteReq) (*ScriptPainlessExecuteResp, error) { - var ( - data ScriptPainlessExecuteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scriptClient) PainlessExecute(ctx context.Context, req ScriptPainlessExecuteReq) (*ScriptPainlessExecuteResp, *opensearch.Response, error) { + var data ScriptPainlessExecuteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_script_test.go b/opensearchapi/api_script_test.go index fdba066fc..17edbdc9f 100644 --- a/opensearchapi/api_script_test.go +++ b/opensearchapi/api_script_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "strings" "testing" @@ -30,7 +31,7 @@ func TestScriptClient(t *testing.T) { type scriptTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -42,7 +43,7 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.Put( nil, opensearchapi.ScriptPutReq{ @@ -54,7 +55,7 @@ func TestScriptClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.Put(nil, opensearchapi.ScriptPutReq{ScriptID: scriptID}) }, }, @@ -65,13 +66,13 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.Get(nil, opensearchapi.ScriptGetReq{ScriptID: scriptID}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.Get(nil, opensearchapi.ScriptGetReq{ScriptID: scriptID}) }, }, @@ -82,13 +83,13 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.Delete(nil, opensearchapi.ScriptDeleteReq{ScriptID: scriptID}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.Delete(nil, opensearchapi.ScriptDeleteReq{ScriptID: scriptID}) }, }, @@ -99,13 +100,13 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.Context(nil, nil) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.Context(nil, nil) }, }, @@ -116,13 +117,13 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.Language(nil, nil) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.Language(nil, nil) }, }, @@ -133,7 +134,7 @@ func TestScriptClient(t *testing.T) { Tests: []scriptTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Script.PainlessExecute( nil, opensearchapi.ScriptPainlessExecuteReq{Body: strings.NewReader(`{"script":{"source":"(params.x + params.y)/ 2","params":{"x":80,"y":100}}}`)}, @@ -142,7 +143,7 @@ func TestScriptClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Script.PainlessExecute( nil, opensearchapi.ScriptPainlessExecuteReq{Body: strings.NewReader(`{"script":{"source":"(params.x + params.y)/ 2","params":{"x":80,"y":100}}}`)}, @@ -159,15 +160,16 @@ func TestScriptClient(t *testing.T) { } for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) } }) } @@ -176,7 +178,7 @@ func TestScriptClient(t *testing.T) { t.Run("ValidateResponse", func(t *testing.T) { t.Run("Put", func(t *testing.T) { - resp, err := client.Script.Put( + resp, httpResp, err := client.Script.Put( nil, opensearchapi.ScriptPutReq{ ScriptID: scriptID, @@ -185,41 +187,47 @@ func TestScriptClient(t *testing.T) { ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Get", func(t *testing.T) { - resp, err := client.Script.Get(nil, opensearchapi.ScriptGetReq{ScriptID: scriptID}) + resp, httpResp, err := client.Script.Get(nil, opensearchapi.ScriptGetReq{ScriptID: scriptID}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Delete", func(t *testing.T) { - resp, err := client.Script.Delete(nil, opensearchapi.ScriptDeleteReq{ScriptID: scriptID}) + resp, httpResp, err := client.Script.Delete(nil, opensearchapi.ScriptDeleteReq{ScriptID: scriptID}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Context", func(t *testing.T) { - resp, err := client.Script.Context(nil, nil) + resp, httpResp, err := client.Script.Context(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("Language", func(t *testing.T) { ostest.SkipIfBelowVersion(t, client, 2, 4, "Language") - resp, err := client.Script.Language(nil, nil) + resp, httpResp, err := client.Script.Language(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("PainlessExecute", func(t *testing.T) { - resp, err := client.Script.PainlessExecute( + resp, httpResp, err := client.Script.PainlessExecute( nil, opensearchapi.ScriptPainlessExecuteReq{Body: strings.NewReader(`{"script":{"source":"(params.x + params.y)/ 2","params":{"x":80,"y":100}}}`)}, ) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) }) } diff --git a/opensearchapi/api_scroll-delete.go b/opensearchapi/api_scroll-delete.go index 62817053d..2b0e72f57 100644 --- a/opensearchapi/api_scroll-delete.go +++ b/opensearchapi/api_scroll-delete.go @@ -47,10 +47,4 @@ func (r ScrollDeleteReq) GetRequest() (*http.Request, error) { type ScrollDeleteResp struct { NumFreed int `json:"num_freed"` Succeeded bool `json:"succeeded"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScrollDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_scroll-get.go b/opensearchapi/api_scroll-get.go index 5a6ee7be4..057fff441 100644 --- a/opensearchapi/api_scroll-get.go +++ b/opensearchapi/api_scroll-get.go @@ -49,10 +49,4 @@ type ScrollGetResp struct { ScrollID *string `json:"_scroll_id,omitempty"` TerminatedEarly bool `json:"terminated_early"` MaxScore *float32 `json:"max_score"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r ScrollGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_scroll.go b/opensearchapi/api_scroll.go index f8c4ef17c..96973724b 100644 --- a/opensearchapi/api_scroll.go +++ b/opensearchapi/api_scroll.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type scrollClient struct { @@ -15,27 +16,25 @@ type scrollClient struct { } // Delete executes a delete scroll request with the required ScrollDeleteReq -func (c scrollClient) Delete(ctx context.Context, req ScrollDeleteReq) (*ScrollDeleteResp, error) { - var ( - data ScrollDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scrollClient) Delete(ctx context.Context, req ScrollDeleteReq) (*ScrollDeleteResp, *opensearch.Response, error) { + var data ScrollDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get scroll request with the required ScrollGetReq -func (c scrollClient) Get(ctx context.Context, req ScrollGetReq) (*ScrollGetResp, error) { - var ( - data ScrollGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c scrollClient) Get(ctx context.Context, req ScrollGetReq) (*ScrollGetResp, *opensearch.Response, error) { + var data ScrollGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_scroll_test.go b/opensearchapi/api_scroll_test.go index 190be8319..e2db06b00 100644 --- a/opensearchapi/api_scroll_test.go +++ b/opensearchapi/api_scroll_test.go @@ -9,6 +9,7 @@ package opensearchapi_test import ( + "github.com/opensearch-project/opensearch-go/v4" "testing" "time" @@ -26,7 +27,7 @@ func TestScrollClient(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.NoError(t, err) - search, err := client.Search( + search, _, err := client.Search( nil, &opensearchapi.SearchReq{ Indices: []string{"*"}, @@ -38,7 +39,7 @@ func TestScrollClient(t *testing.T) { type scrollTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -50,13 +51,13 @@ func TestScrollClient(t *testing.T) { Tests: []scrollTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Scroll.Get(nil, opensearchapi.ScrollGetReq{ScrollID: *search.ScrollID}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Scroll.Get(nil, opensearchapi.ScrollGetReq{}) }, }, @@ -67,13 +68,13 @@ func TestScrollClient(t *testing.T) { Tests: []scrollTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Scroll.Delete(nil, opensearchapi.ScrollDeleteReq{ScrollIDs: []string{"_all"}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Scroll.Delete(nil, opensearchapi.ScrollDeleteReq{}) }, }, @@ -84,16 +85,17 @@ func TestScrollClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.Error(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.NoError(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } }) } diff --git a/opensearchapi/api_search-template.go b/opensearchapi/api_search-template.go index f3c7715ec..117eea3ef 100644 --- a/opensearchapi/api_search-template.go +++ b/opensearchapi/api_search-template.go @@ -16,16 +16,15 @@ import ( ) // SearchTemplate executes a /_search request with the optional SearchTemplateReq -func (c Client) SearchTemplate(ctx context.Context, req SearchTemplateReq) (*SearchTemplateResp, error) { - var ( - data SearchTemplateResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) SearchTemplate(ctx context.Context, req SearchTemplateReq) (*SearchTemplateResp, *opensearch.Response, error) { + var data SearchTemplateResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // SearchTemplateReq represents possible options for the /_search request @@ -70,10 +69,4 @@ type SearchTemplateResp struct { MaxScore *float32 `json:"max_score"` Hits []SearchHit `json:"hits"` } `json:"hits"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SearchTemplateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_search-template_test.go b/opensearchapi/api_search-template_test.go index 9032b895d..03c408128 100644 --- a/opensearchapi/api_search-template_test.go +++ b/opensearchapi/api_search-template_test.go @@ -31,7 +31,7 @@ func TestSearchTemplate(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestSearchTemplate(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.SearchTemplate( + resp, httpResp, err := client.SearchTemplate( nil, opensearchapi.SearchTemplateReq{ Indices: []string{testIndex}, @@ -53,16 +53,18 @@ func TestSearchTemplate(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.SearchTemplate(nil, opensearchapi.SearchTemplateReq{}) + res, httpResp, err := failingClient.SearchTemplate(nil, opensearchapi.SearchTemplateReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_search.go b/opensearchapi/api_search.go index d207b985e..e58b9dd5f 100644 --- a/opensearchapi/api_search.go +++ b/opensearchapi/api_search.go @@ -18,20 +18,19 @@ import ( ) // Search executes a /_search request with the optional SearchReq -func (c Client) Search(ctx context.Context, req *SearchReq) (*SearchResp, error) { +func (c Client) Search(ctx context.Context, req *SearchReq) (*SearchResp, *opensearch.Response, error) { if req == nil { req = &SearchReq{} } - var ( - data SearchResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err + var data SearchResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // SearchReq represents possible options for the /_search request @@ -78,12 +77,6 @@ type SearchResp struct { Aggregations json.RawMessage `json:"aggregations"` ScrollID *string `json:"_scroll_id,omitempty"` Suggest map[string][]Suggest `json:"suggest,omitempty"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Response -func (r SearchResp) Inspect() Inspect { - return Inspect{Response: r.response} } // SearchHit is a sub type of SearchResp containing information of the search hit with an unparsed Source field diff --git a/opensearchapi/api_search_shards.go b/opensearchapi/api_search_shards.go index 28c2c8021..962a9185c 100644 --- a/opensearchapi/api_search_shards.go +++ b/opensearchapi/api_search_shards.go @@ -16,20 +16,19 @@ import ( ) // SearchShards executes a /_search request with the optional SearchShardsReq -func (c Client) SearchShards(ctx context.Context, req *SearchShardsReq) (*SearchShardsResp, error) { +func (c Client) SearchShards(ctx context.Context, req *SearchShardsReq) (*SearchShardsResp, *opensearch.Response, error) { if req == nil { req = &SearchShardsReq{} } - var ( - data SearchShardsResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err + var data SearchShardsResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // SearchShardsReq represents possible options for the /_search request @@ -90,10 +89,4 @@ type SearchShardsResp struct { ID string `json:"id"` } `json:"allocation_id"` } `json:"shards"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SearchShardsResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_search_shards_test.go b/opensearchapi/api_search_shards_test.go index 238c0e2e3..848e7ba1d 100644 --- a/opensearchapi/api_search_shards_test.go +++ b/opensearchapi/api_search_shards_test.go @@ -25,7 +25,7 @@ func TestSearchShards(t *testing.T) { index := "test-index-search-shards" - _, err = client.Indices.Create( + _, _, err = client.Indices.Create( nil, opensearchapi.IndicesCreateReq{ Index: index, @@ -37,26 +37,29 @@ func TestSearchShards(t *testing.T) { }) t.Run("with nil request", func(t *testing.T) { - resp, err := client.SearchShards(nil, nil) + resp, httpResp, err := client.SearchShards(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("with request", func(t *testing.T) { - resp, err := client.SearchShards(nil, &opensearchapi.SearchShardsReq{Indices: []string{index}}) + resp, httpResp, err := client.SearchShards(nil, &opensearchapi.SearchShardsReq{Indices: []string{index}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.SearchShards(nil, nil) + res, httpResp, err := failingClient.SearchShards(nil, nil) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_search_test.go b/opensearchapi/api_search_test.go index 4339971b7..aab041694 100644 --- a/opensearchapi/api_search_test.go +++ b/opensearchapi/api_search_test.go @@ -27,7 +27,7 @@ func TestSearch(t *testing.T) { index := "test-index-search" - _, err = client.Index( + _, _, err = client.Index( nil, opensearchapi.IndexReq{ DocumentID: "foo", @@ -42,18 +42,20 @@ func TestSearch(t *testing.T) { }) t.Run("with nil request", func(t *testing.T) { - resp, err := client.Search(nil, nil) + resp, httpResp, err := client.Search(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.NotEmpty(t, resp.Hits.Hits) }) t.Run("with request", func(t *testing.T) { - resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader("")}) + resp, httpResp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader("")}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.NotEmpty(t, resp.Hits.Hits) }) @@ -61,21 +63,22 @@ func TestSearch(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Search(nil, nil) + res, httpResp, err := failingClient.Search(nil, nil) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) t.Run("request with explain", func(t *testing.T) { - resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(""), Params: opensearchapi.SearchParams{Explain: opensearchapi.ToPointer(true)}}) + resp, _, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(""), Params: opensearchapi.SearchParams{Explain: opensearchapi.ToPointer(true)}}) require.Nil(t, err) assert.NotEmpty(t, resp.Hits.Hits) assert.NotNil(t, resp.Hits.Hits[0].Explanation) }) t.Run("request with retrieve specific fields", func(t *testing.T) { - resp, err := client.Search( + resp, _, err := client.Search( nil, &opensearchapi.SearchReq{ Indices: []string{index}, @@ -111,7 +114,7 @@ func TestSearch(t *testing.T) { assert.Equal(t, fmt.Sprintf("/%s/_search", index), httpReq.URL.Path) }) t.Run("request to retrieve response with routing key", func(t *testing.T) { - resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{ + resp, _, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{ "query": { "match": { "foo": "bar" @@ -131,7 +134,7 @@ func TestSearch(t *testing.T) { t.Run("with seq_no and primary_term", func(t *testing.T) { seqNoPrimaryTerm := true - resp, err := client.Search(nil, &opensearchapi.SearchReq{ + resp, httpResp, err := client.Search(nil, &opensearchapi.SearchReq{ Indices: []string{index}, Body: strings.NewReader(""), Params: opensearchapi.SearchParams{ @@ -140,7 +143,8 @@ func TestSearch(t *testing.T) { }) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.NotEmpty(t, resp.Hits.Hits) for _, hit := range resp.Hits.Hits { assert.NotNil(t, hit.SeqNo) @@ -150,7 +154,7 @@ func TestSearch(t *testing.T) { t.Run("without seq_no and primary_term", func(t *testing.T) { seqNoPrimaryTerm := false - resp, err := client.Search(nil, &opensearchapi.SearchReq{ + resp, httpResp, err := client.Search(nil, &opensearchapi.SearchReq{ Indices: []string{index}, Body: strings.NewReader(""), Params: opensearchapi.SearchParams{ @@ -159,7 +163,8 @@ func TestSearch(t *testing.T) { }) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) assert.NotEmpty(t, resp.Hits.Hits) for _, hit := range resp.Hits.Hits { assert.Nil(t, hit.SeqNo) @@ -168,7 +173,7 @@ func TestSearch(t *testing.T) { }) t.Run("request with suggest", func(t *testing.T) { - resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{ + resp, _, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{ "suggest": { "text": "bar", "my-suggest": { diff --git a/opensearchapi/api_snapshot-clone.go b/opensearchapi/api_snapshot-clone.go index c12a6ccc2..4b3a68088 100644 --- a/opensearchapi/api_snapshot-clone.go +++ b/opensearchapi/api_snapshot-clone.go @@ -40,10 +40,4 @@ func (r SnapshotCloneReq) GetRequest() (*http.Request, error) { // SnapshotCloneResp represents the returned struct of the index create response type SnapshotCloneResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotCloneResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot-create.go b/opensearchapi/api_snapshot-create.go index 986b2c2f1..4f0749e08 100644 --- a/opensearchapi/api_snapshot-create.go +++ b/opensearchapi/api_snapshot-create.go @@ -63,10 +63,4 @@ type SnapshotCreateResp struct { Successful int `json:"successful"` } `json:"shards"` } `json:"snapshot"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot-delete.go b/opensearchapi/api_snapshot-delete.go index 2f13553aa..3c299196e 100644 --- a/opensearchapi/api_snapshot-delete.go +++ b/opensearchapi/api_snapshot-delete.go @@ -37,10 +37,4 @@ func (r SnapshotDeleteReq) GetRequest() (*http.Request, error) { // SnapshotDeleteResp represents the returned struct of the index create response type SnapshotDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot-get.go b/opensearchapi/api_snapshot-get.go index 33925c555..f851307ed 100644 --- a/opensearchapi/api_snapshot-get.go +++ b/opensearchapi/api_snapshot-get.go @@ -41,12 +41,6 @@ func (r SnapshotGetReq) GetRequest() (*http.Request, error) { // SnapshotGetResp represents the returned struct of the index create response type SnapshotGetResp struct { Snapshots []SnapshotGet `json:"snapshots"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // SnapshotGet is a sub type of SnapshotGetResp represeting a single snapshot diff --git a/opensearchapi/api_snapshot-restore.go b/opensearchapi/api_snapshot-restore.go index 2264e4365..1124c5d7e 100644 --- a/opensearchapi/api_snapshot-restore.go +++ b/opensearchapi/api_snapshot-restore.go @@ -48,10 +48,4 @@ type SnapshotRestoreResp struct { Successful int `json:"successful"` } `json:"shards"` } `json:"snapshot"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRestoreResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot-status.go b/opensearchapi/api_snapshot-status.go index e63caeba0..a28d81124 100644 --- a/opensearchapi/api_snapshot-status.go +++ b/opensearchapi/api_snapshot-status.go @@ -54,12 +54,6 @@ type SnapshotStatusResp struct { } `json:"shards"` } `json:"indices"` } `json:"snapshots"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotStatusResp) Inspect() Inspect { - return Inspect{Response: r.response} } // SnapshotStatusShardsStats is a sub type of SnapshotStatusResp containing information about shard stats diff --git a/opensearchapi/api_snapshot.go b/opensearchapi/api_snapshot.go index 9fa754828..9d6cd56c8 100644 --- a/opensearchapi/api_snapshot.go +++ b/opensearchapi/api_snapshot.go @@ -6,7 +6,10 @@ package opensearchapi -import "context" +import ( + "context" + "github.com/opensearch-project/opensearch-go/v4" +) type snapshotClient struct { apiClient *Client @@ -14,79 +17,73 @@ type snapshotClient struct { } // Create executes a creade snapshot request with the required SnapshotCreateReq -func (c snapshotClient) Create(ctx context.Context, req SnapshotCreateReq) (*SnapshotCreateResp, error) { - var ( - data SnapshotCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Create(ctx context.Context, req SnapshotCreateReq) (*SnapshotCreateResp, *opensearch.Response, error) { + var data SnapshotCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete snapshot request with the required SnapshotDeleteReq -func (c snapshotClient) Delete(ctx context.Context, req SnapshotDeleteReq) (*SnapshotDeleteResp, error) { - var ( - data SnapshotDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Delete(ctx context.Context, req SnapshotDeleteReq) (*SnapshotDeleteResp, *opensearch.Response, error) { + var data SnapshotDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get snapshot request with the required SnapshotGetReq -func (c snapshotClient) Get(ctx context.Context, req SnapshotGetReq) (*SnapshotGetResp, error) { - var ( - data SnapshotGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Get(ctx context.Context, req SnapshotGetReq) (*SnapshotGetResp, *opensearch.Response, error) { + var data SnapshotGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Clone executes a snapshot clone request with the required SnapshotCloneReq -func (c snapshotClient) Clone(ctx context.Context, req SnapshotCloneReq) (*SnapshotCloneResp, error) { - var ( - data SnapshotCloneResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Clone(ctx context.Context, req SnapshotCloneReq) (*SnapshotCloneResp, *opensearch.Response, error) { + var data SnapshotCloneResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Restore executes a snapshot restore request with the required SnapshotRestoreReq -func (c snapshotClient) Restore(ctx context.Context, req SnapshotRestoreReq) (*SnapshotRestoreResp, error) { - var ( - data SnapshotRestoreResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Restore(ctx context.Context, req SnapshotRestoreReq) (*SnapshotRestoreResp, *opensearch.Response, error) { + var data SnapshotRestoreResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Status executes a snapshot status request with the required SnapshotStatusReq -func (c snapshotClient) Status(ctx context.Context, req SnapshotStatusReq) (*SnapshotStatusResp, error) { - var ( - data SnapshotStatusResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c snapshotClient) Status(ctx context.Context, req SnapshotStatusReq) (*SnapshotStatusResp, *opensearch.Response, error) { + var data SnapshotStatusResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_snapshot_repository-cleanup.go b/opensearchapi/api_snapshot_repository-cleanup.go index 072a9ca59..b25528dfe 100644 --- a/opensearchapi/api_snapshot_repository-cleanup.go +++ b/opensearchapi/api_snapshot_repository-cleanup.go @@ -38,10 +38,4 @@ type SnapshotRepositoryCleanupResp struct { DeletedBytes int `json:"deleted_bytes"` DeletedBlobs int `json:"deleted_blobs"` } `json:"results"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRepositoryCleanupResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot_repository-create.go b/opensearchapi/api_snapshot_repository-create.go index ba01e1161..d60115e6b 100644 --- a/opensearchapi/api_snapshot_repository-create.go +++ b/opensearchapi/api_snapshot_repository-create.go @@ -38,10 +38,4 @@ func (r SnapshotRepositoryCreateReq) GetRequest() (*http.Request, error) { // SnapshotRepositoryCreateResp represents the returned struct of the index create response type SnapshotRepositoryCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRepositoryCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot_repository-delete.go b/opensearchapi/api_snapshot_repository-delete.go index 4a51de58a..0dd831041 100644 --- a/opensearchapi/api_snapshot_repository-delete.go +++ b/opensearchapi/api_snapshot_repository-delete.go @@ -45,10 +45,4 @@ func (r SnapshotRepositoryDeleteReq) GetRequest() (*http.Request, error) { // SnapshotRepositoryDeleteResp represents the returned struct of the index create response type SnapshotRepositoryDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRepositoryDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot_repository-get.go b/opensearchapi/api_snapshot_repository-get.go index f04239600..54bf40f78 100644 --- a/opensearchapi/api_snapshot_repository-get.go +++ b/opensearchapi/api_snapshot_repository-get.go @@ -48,10 +48,4 @@ type SnapshotRepositoryGetResp struct { Type string `json:"type"` Settings map[string]string `json:"settings"` } - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRepositoryGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot_repository-verify.go b/opensearchapi/api_snapshot_repository-verify.go index 5542af7e3..8ee18eccd 100644 --- a/opensearchapi/api_snapshot_repository-verify.go +++ b/opensearchapi/api_snapshot_repository-verify.go @@ -37,10 +37,4 @@ type SnapshotRepositoryVerifyResp struct { Nodes map[string]struct { Name string `json:"name"` } `json:"nodes"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r SnapshotRepositoryVerifyResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_snapshot_repository.go b/opensearchapi/api_snapshot_repository.go index 9bd139a9c..bbe4a4692 100644 --- a/opensearchapi/api_snapshot_repository.go +++ b/opensearchapi/api_snapshot_repository.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type repositoryClient struct { @@ -15,69 +16,64 @@ type repositoryClient struct { } // Create executes a put repository request with the required SnapshotRepositoryCreateReq -func (c repositoryClient) Create(ctx context.Context, req SnapshotRepositoryCreateReq) (*SnapshotRepositoryCreateResp, error) { - var ( - data SnapshotRepositoryCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c repositoryClient) Create(ctx context.Context, req SnapshotRepositoryCreateReq) (*SnapshotRepositoryCreateResp, *opensearch.Response, error) { + var data SnapshotRepositoryCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete repository request with the required SnapshotRepositoryDeleteReq -func (c repositoryClient) Delete(ctx context.Context, req SnapshotRepositoryDeleteReq) (*SnapshotRepositoryDeleteResp, error) { - var ( - data SnapshotRepositoryDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c repositoryClient) Delete(ctx context.Context, req SnapshotRepositoryDeleteReq) (*SnapshotRepositoryDeleteResp, *opensearch.Response, error) { + var data SnapshotRepositoryDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get repository request with the optional SnapshotRepositoryGetReq -func (c repositoryClient) Get(ctx context.Context, req *SnapshotRepositoryGetReq) (*SnapshotRepositoryGetResp, error) { +func (c repositoryClient) Get(ctx context.Context, req *SnapshotRepositoryGetReq) (*SnapshotRepositoryGetResp, *opensearch.Response, error) { if req == nil { req = &SnapshotRepositoryGetReq{} } - var ( - data SnapshotRepositoryGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Repos); err != nil { - return &data, err + var data SnapshotRepositoryGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Repos) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Cleanup executes a cleanup repository request with the required SnapshotRepositoryCleanupReq -func (c repositoryClient) Cleanup(ctx context.Context, req SnapshotRepositoryCleanupReq) (*SnapshotRepositoryCleanupResp, error) { - var ( - data SnapshotRepositoryCleanupResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c repositoryClient) Cleanup(ctx context.Context, req SnapshotRepositoryCleanupReq) (*SnapshotRepositoryCleanupResp, *opensearch.Response, error) { + var data SnapshotRepositoryCleanupResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Verify executes a verify repository request with the required SnapshotRepositoryVerifyReq -func (c repositoryClient) Verify(ctx context.Context, req SnapshotRepositoryVerifyReq) (*SnapshotRepositoryVerifyResp, error) { - var ( - data SnapshotRepositoryVerifyResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c repositoryClient) Verify(ctx context.Context, req SnapshotRepositoryVerifyReq) (*SnapshotRepositoryVerifyResp, *opensearch.Response, error) { + var data SnapshotRepositoryVerifyResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_snapshot_test.go b/opensearchapi/api_snapshot_test.go index d90aade6e..6380a01cf 100644 --- a/opensearchapi/api_snapshot_test.go +++ b/opensearchapi/api_snapshot_test.go @@ -10,6 +10,7 @@ package opensearchapi_test import ( "fmt" + "github.com/opensearch-project/opensearch-go/v4" "strconv" "strings" "testing" @@ -38,7 +39,7 @@ func TestSnapshotClient(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -52,7 +53,7 @@ func TestSnapshotClient(t *testing.T) { type snapshotTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { Name string @@ -63,7 +64,7 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Repository.Create( nil, opensearchapi.SnapshotRepositoryCreateReq{ @@ -75,7 +76,7 @@ func TestSnapshotClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Repository.Create(nil, opensearchapi.SnapshotRepositoryCreateReq{}) }, }, @@ -86,13 +87,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Repository.Get(nil, &opensearchapi.SnapshotRepositoryGetReq{Repos: []string{testRepo}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Repository.Get(nil, nil) }, }, @@ -103,13 +104,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Repository.Cleanup(nil, opensearchapi.SnapshotRepositoryCleanupReq{Repo: testRepo}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Repository.Cleanup(nil, opensearchapi.SnapshotRepositoryCleanupReq{}) }, }, @@ -120,13 +121,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Repository.Verify(nil, opensearchapi.SnapshotRepositoryVerifyReq{Repo: testRepo}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Repository.Verify(nil, opensearchapi.SnapshotRepositoryVerifyReq{}) }, }, @@ -137,7 +138,7 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Create( nil, opensearchapi.SnapshotCreateReq{ @@ -151,7 +152,7 @@ func TestSnapshotClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Create(nil, opensearchapi.SnapshotCreateReq{}) }, }, @@ -162,7 +163,7 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Clone( nil, opensearchapi.SnapshotCloneReq{ @@ -176,7 +177,7 @@ func TestSnapshotClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Clone(nil, opensearchapi.SnapshotCloneReq{}) }, }, @@ -187,13 +188,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Get(nil, opensearchapi.SnapshotGetReq{Repo: testRepo, Snapshots: []string{testSnapshot, testCloneSnapshot}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Get(nil, opensearchapi.SnapshotGetReq{}) }, }, @@ -204,7 +205,7 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}}) return client.Snapshot.Restore( nil, @@ -217,7 +218,7 @@ func TestSnapshotClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Restore(nil, opensearchapi.SnapshotRestoreReq{}) }, }, @@ -228,13 +229,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Status(nil, opensearchapi.SnapshotStatusReq{Repo: testRepo, Snapshots: []string{testSnapshot, testCloneSnapshot}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Status(nil, opensearchapi.SnapshotStatusReq{}) }, }, @@ -245,13 +246,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Delete(nil, opensearchapi.SnapshotDeleteReq{Repo: testRepo, Snapshots: []string{testSnapshot, testCloneSnapshot}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Delete(nil, opensearchapi.SnapshotDeleteReq{}) }, }, @@ -262,13 +263,13 @@ func TestSnapshotClient(t *testing.T) { Tests: []snapshotTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Snapshot.Repository.Delete(nil, opensearchapi.SnapshotRepositoryDeleteReq{Repos: []string{testRepo}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Snapshot.Repository.Delete(nil, opensearchapi.SnapshotRepositoryDeleteReq{}) }, }, @@ -279,17 +280,18 @@ func TestSnapshotClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) if value.Name != "Repository Get" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) @@ -297,7 +299,7 @@ func TestSnapshotClient(t *testing.T) { }) } t.Run("ValidateResponse", func(t *testing.T) { - _, err := client.Snapshot.Repository.Create( + _, _, err := client.Snapshot.Repository.Create( nil, opensearchapi.SnapshotRepositoryCreateReq{ Repo: testRepo, @@ -310,10 +312,11 @@ func TestSnapshotClient(t *testing.T) { }) t.Run("Repository Get", func(t *testing.T) { - resp, err := client.Snapshot.Repository.Get(nil, &opensearchapi.SnapshotRepositoryGetReq{Repos: []string{testRepo}}) + resp, httpResp, err := client.Snapshot.Repository.Get(nil, &opensearchapi.SnapshotRepositoryGetReq{Repos: []string{testRepo}}) require.Nil(t, err) assert.NotNil(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp.Repos, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Repos, httpResp) }) }) } diff --git a/opensearchapi/api_tasks-cancel.go b/opensearchapi/api_tasks-cancel.go index 4c3d0596b..1b1736dd6 100644 --- a/opensearchapi/api_tasks-cancel.go +++ b/opensearchapi/api_tasks-cancel.go @@ -45,12 +45,6 @@ func (r TasksCancelReq) GetRequest() (*http.Request, error) { type TasksCancelResp struct { Nodes map[string]TaskCancel `json:"nodes"` NodeFailures []FailuresCause `json:"node_failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TasksCancelResp) Inspect() Inspect { - return Inspect{Response: r.response} } // TaskCancel is a sub type of TaskCancelResp containing information about a node the task was running on diff --git a/opensearchapi/api_tasks-get.go b/opensearchapi/api_tasks-get.go index 45411fac6..248aabcdc 100644 --- a/opensearchapi/api_tasks-get.go +++ b/opensearchapi/api_tasks-get.go @@ -70,12 +70,6 @@ type TasksGetResp struct { } `json:"thread_info"` } `json:"resource_stats"` } `json:"task"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TasksGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // TasksGetDetails is a sub type of TasksGetResp containing information about an index template diff --git a/opensearchapi/api_tasks-list.go b/opensearchapi/api_tasks-list.go index 0332f851f..1c4918b89 100644 --- a/opensearchapi/api_tasks-list.go +++ b/opensearchapi/api_tasks-list.go @@ -34,12 +34,6 @@ type TasksListResp struct { Nodes map[string]TasksListNodes `json:"nodes"` Tasks map[string]TasksListTask `json:"tasks"` // tasks is returned when group_by is set to none or parents NodeFailures []FailuresCause `json:"node_failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TasksListResp) Inspect() Inspect { - return Inspect{Response: r.response} } // TasksListNodes is a sub type of TaskListResp containing information about a node and the tasks running on it diff --git a/opensearchapi/api_tasks.go b/opensearchapi/api_tasks.go index bd31696f9..4bfe87263 100644 --- a/opensearchapi/api_tasks.go +++ b/opensearchapi/api_tasks.go @@ -8,6 +8,7 @@ package opensearchapi import ( "context" + "github.com/opensearch-project/opensearch-go/v4" ) type tasksClient struct { @@ -15,44 +16,41 @@ type tasksClient struct { } // Cancel executes a delete tasks request with the required TasksCancelReq -func (c tasksClient) Cancel(ctx context.Context, req TasksCancelReq) (*TasksCancelResp, error) { - var ( - data TasksCancelResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c tasksClient) Cancel(ctx context.Context, req TasksCancelReq) (*TasksCancelResp, *opensearch.Response, error) { + var data TasksCancelResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // List executes a get tasks request with the optional TasksListReq -func (c tasksClient) List(ctx context.Context, req *TasksListReq) (*TasksListResp, error) { +func (c tasksClient) List(ctx context.Context, req *TasksListReq) (*TasksListResp, *opensearch.Response, error) { if req == nil { req = &TasksListReq{} } - var ( - data TasksListResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err + var data TasksListResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get tasks request with the optional TasksGetReq -func (c tasksClient) Get(ctx context.Context, req TasksGetReq) (*TasksGetResp, error) { - var ( - data TasksGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c tasksClient) Get(ctx context.Context, req TasksGetReq) (*TasksGetResp, *opensearch.Response, error) { + var data TasksGetResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } diff --git a/opensearchapi/api_tasks_test.go b/opensearchapi/api_tasks_test.go index 1725c6ba2..5ba1c7125 100644 --- a/opensearchapi/api_tasks_test.go +++ b/opensearchapi/api_tasks_test.go @@ -11,6 +11,7 @@ package opensearchapi_test import ( "context" "fmt" + "github.com/opensearch-project/opensearch-go/v4" "strconv" "strings" "testing" @@ -74,7 +75,7 @@ func TestTasksClient(t *testing.T) { t.Errorf("Unexpected error: %s", err) } - respReindex, err := client.Reindex( + respReindex, _, err := client.Reindex( ctx, opensearchapi.ReindexReq{ Body: strings.NewReader(fmt.Sprintf(`{"source":{"index":"%s","size":1},"dest":{"index":"%s"}}`, sourceIndex, destIndex)), @@ -90,7 +91,7 @@ func TestTasksClient(t *testing.T) { type tasksTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -102,13 +103,13 @@ func TestTasksClient(t *testing.T) { Tests: []tasksTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Tasks.List(nil, nil) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Tasks.List(nil, nil) }, }, @@ -119,13 +120,13 @@ func TestTasksClient(t *testing.T) { Tests: []tasksTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Tasks.Get(nil, opensearchapi.TasksGetReq{TaskID: respReindex.Task}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Tasks.Get(nil, opensearchapi.TasksGetReq{}) }, }, @@ -136,13 +137,13 @@ func TestTasksClient(t *testing.T) { Tests: []tasksTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Tasks.Cancel(nil, opensearchapi.TasksCancelReq{TaskID: respReindex.Task}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Tasks.Cancel(nil, opensearchapi.TasksCancelReq{}) }, }, @@ -153,17 +154,18 @@ func TestTasksClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + require.NotNil(t, resp) + assert.NotNil(t, httpResp) if value.Name != "Get" && value.Name != "Exists" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) diff --git a/opensearchapi/api_template-create.go b/opensearchapi/api_template-create.go index fa974f0bc..304532abc 100644 --- a/opensearchapi/api_template-create.go +++ b/opensearchapi/api_template-create.go @@ -38,10 +38,4 @@ func (r TemplateCreateReq) GetRequest() (*http.Request, error) { // TemplateCreateResp represents the returned struct of the index create response type TemplateCreateResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TemplateCreateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_template-delete.go b/opensearchapi/api_template-delete.go index 5bc7f0b6d..e8f03c659 100644 --- a/opensearchapi/api_template-delete.go +++ b/opensearchapi/api_template-delete.go @@ -35,10 +35,4 @@ func (r TemplateDeleteReq) GetRequest() (*http.Request, error) { // TemplateDeleteResp represents the returned struct of the index create response type TemplateDeleteResp struct { Acknowledged bool `json:"acknowledged"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TemplateDeleteResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_template-get.go b/opensearchapi/api_template-get.go index 95b2d66a5..2f8853b6d 100644 --- a/opensearchapi/api_template-get.go +++ b/opensearchapi/api_template-get.go @@ -37,12 +37,6 @@ func (r TemplateGetReq) GetRequest() (*http.Request, error) { // TemplateGetResp represents the returned struct of the index create response type TemplateGetResp struct { Templates map[string]TemplateGetDetails - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TemplateGetResp) Inspect() Inspect { - return Inspect{Response: r.response} } // TemplateGetDetails is a sub type of TemplateGetResp containing information about an index template diff --git a/opensearchapi/api_template.go b/opensearchapi/api_template.go index be9f1b4ae..b0d7bb28f 100644 --- a/opensearchapi/api_template.go +++ b/opensearchapi/api_template.go @@ -18,48 +18,45 @@ type templateClient struct { // Create executes a creade template request with the required TemplateCreateReq // Deprecated: uses legacy API (/_template), correct API is /_index_template, use IndexTemplate.Create instread -func (c templateClient) Create(ctx context.Context, req TemplateCreateReq) (*TemplateCreateResp, error) { - var ( - data TemplateCreateResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c templateClient) Create(ctx context.Context, req TemplateCreateReq) (*TemplateCreateResp, *opensearch.Response, error) { + var data TemplateCreateResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Delete executes a delete template request with the required TemplateDeleteReq // Deprecated: uses legacy API (/_template), correct API is /_index_template, use IndexTemplate.Delete instread -func (c templateClient) Delete(ctx context.Context, req TemplateDeleteReq) (*TemplateDeleteResp, error) { - var ( - data TemplateDeleteResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { - return &data, err +func (c templateClient) Delete(ctx context.Context, req TemplateDeleteReq) (*TemplateDeleteResp, *opensearch.Response, error) { + var data TemplateDeleteResp + + resp, err := c.apiClient.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Get executes a get template request with the optional TemplateGetReq // Deprecated: uses legacy API (/_template), correct API is /_index_template, use IndexTemplate.Get instread -func (c templateClient) Get(ctx context.Context, req *TemplateGetReq) (*TemplateGetResp, error) { +func (c templateClient) Get(ctx context.Context, req *TemplateGetReq) (*TemplateGetResp, *opensearch.Response, error) { if req == nil { req = &TemplateGetReq{} } - var ( - data TemplateGetResp - err error - ) - if data.response, err = c.apiClient.do(ctx, req, &data.Templates); err != nil { - return &data, err + var data TemplateGetResp + + resp, err := c.apiClient.do(ctx, req, &data.Templates) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // Exists executes a exists template request with the required TemplatExistsReq diff --git a/opensearchapi/api_template_test.go b/opensearchapi/api_template_test.go index 1dade7853..6d10cb65b 100644 --- a/opensearchapi/api_template_test.go +++ b/opensearchapi/api_template_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/opensearch-project/opensearch-go/v4" ostest "github.com/opensearch-project/opensearch-go/v4/internal/test" "github.com/opensearch-project/opensearch-go/v4/opensearchapi" osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test" @@ -30,7 +31,7 @@ func TestTemplateClient(t *testing.T) { type templateTests struct { Name string - Results func() (osapitest.Response, error) + Results func() (any, *opensearch.Response, error) } testCases := []struct { @@ -42,7 +43,7 @@ func TestTemplateClient(t *testing.T) { Tests: []templateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Template.Create( nil, opensearchapi.TemplateCreateReq{ @@ -54,7 +55,7 @@ func TestTemplateClient(t *testing.T) { }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Template.Create(nil, opensearchapi.TemplateCreateReq{Template: template}) }, }, @@ -65,13 +66,13 @@ func TestTemplateClient(t *testing.T) { Tests: []templateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Template.Get(nil, &opensearchapi.TemplateGetReq{Templates: []string{template}}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Template.Get(nil, nil) }, }, @@ -82,24 +83,18 @@ func TestTemplateClient(t *testing.T) { Tests: []templateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = client.Template.Exists(nil, opensearchapi.TemplateExistsReq{Template: template}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := client.Template.Exists(nil, opensearchapi.TemplateExistsReq{Template: template}) + + return nil, httpResp, err }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { - var ( - resp osapitest.DummyInspect - err error - ) - resp.Response, err = failingClient.Template.Exists(nil, opensearchapi.TemplateExistsReq{Template: template}) - return resp, err + Results: func() (any, *opensearch.Response, error) { + httpResp, err := failingClient.Template.Exists(nil, opensearchapi.TemplateExistsReq{Template: template}) + + return nil, httpResp, err }, }, }, @@ -109,13 +104,13 @@ func TestTemplateClient(t *testing.T) { Tests: []templateTests{ { Name: "with request", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return client.Template.Delete(nil, opensearchapi.TemplateDeleteReq{Template: template}) }, }, { Name: "inspect", - Results: func() (osapitest.Response, error) { + Results: func() (any, *opensearch.Response, error) { return failingClient.Template.Delete(nil, opensearchapi.TemplateDeleteReq{Template: template}) }, }, @@ -126,17 +121,20 @@ func TestTemplateClient(t *testing.T) { t.Run(value.Name, func(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { - res, err := testCase.Results() + resp, httpResp, err := testCase.Results() if testCase.Name == "inspect" { assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, resp) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) } else { require.Nil(t, err) - require.NotNil(t, res) - assert.NotNil(t, res.Inspect().Response) + if value.Name != "Exists" { + require.NotNil(t, resp) + } + assert.NotNil(t, httpResp) if value.Name != "Get" && value.Name != "Exists" { - ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) } } }) @@ -145,7 +143,7 @@ func TestTemplateClient(t *testing.T) { } t.Run("ValidateResponse", func(t *testing.T) { t.Run("Get", func(t *testing.T) { - _, err := client.Template.Create( + _, _, err := client.Template.Create( nil, opensearchapi.TemplateCreateReq{ Template: template, @@ -153,11 +151,11 @@ func TestTemplateClient(t *testing.T) { }, ) require.Nil(t, err) - resp, err := client.Template.Get(nil, &opensearchapi.TemplateGetReq{Templates: []string{template}}) + resp, httpResp, err := client.Template.Get(nil, &opensearchapi.TemplateGetReq{Templates: []string{template}}) require.Nil(t, err) require.NotNil(t, resp) - require.NotNil(t, resp.Inspect().Response) - ostest.CompareRawJSONwithParsedJSON(t, resp.Templates, resp.Inspect().Response) + require.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp.Templates, httpResp) }) }) } diff --git a/opensearchapi/api_termvectors.go b/opensearchapi/api_termvectors.go index d25d4b367..de91abe0e 100644 --- a/opensearchapi/api_termvectors.go +++ b/opensearchapi/api_termvectors.go @@ -17,16 +17,15 @@ import ( ) // Termvectors executes a /_termvectors request with the required TermvectorsReq -func (c Client) Termvectors(ctx context.Context, req TermvectorsReq) (*TermvectorsResp, error) { - var ( - data TermvectorsResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Termvectors(ctx context.Context, req TermvectorsReq) (*TermvectorsResp, *opensearch.Response, error) { + var data TermvectorsResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // TermvectorsReq represents possible options for the /_termvectors request @@ -71,10 +70,4 @@ type TermvectorsResp struct { Took int `json:"took"` Type string `json:"_type"` // Deprecated field TermVectors json.RawMessage `json:"term_vectors"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r TermvectorsResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_termvectors_test.go b/opensearchapi/api_termvectors_test.go index 7a2e88d44..b9c67b779 100644 --- a/opensearchapi/api_termvectors_test.go +++ b/opensearchapi/api_termvectors_test.go @@ -30,7 +30,7 @@ func TestTermvectors(t *testing.T) { client.Indices.Delete(nil, opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}}) }) - _, err = client.Indices.Create( + _, _, err = client.Indices.Create( nil, opensearchapi.IndicesCreateReq{ Index: testIndex, @@ -73,7 +73,7 @@ func TestTermvectors(t *testing.T) { require.Nil(t, err) docs := []string{`{"fullname":"John Doe","text":"test test test "}`, `{"fullname":"Jane Doe","text":"Another test ..."}`} for i, doc := range docs { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -86,7 +86,7 @@ func TestTermvectors(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.Termvectors( + resp, httpResp, err := client.Termvectors( nil, opensearchapi.TermvectorsReq{ Index: testIndex, @@ -96,16 +96,18 @@ func TestTermvectors(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Termvectors(nil, opensearchapi.TermvectorsReq{}) + res, httpResp, err := failingClient.Termvectors(nil, opensearchapi.TermvectorsReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_update.go b/opensearchapi/api_update.go index 54ab8e1d8..1f3e18f4e 100644 --- a/opensearchapi/api_update.go +++ b/opensearchapi/api_update.go @@ -16,16 +16,15 @@ import ( ) // Update executes a /_update request with the optional UpdateReq -func (c Client) Update(ctx context.Context, req UpdateReq) (*UpdateResp, error) { - var ( - data UpdateResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) Update(ctx context.Context, req UpdateReq) (*UpdateResp, *opensearch.Response, error) { + var data UpdateResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // UpdateReq represents possible options for the /_update request @@ -64,10 +63,4 @@ type UpdateResp struct { SeqNo int `json:"_seq_no"` PrimaryTerm int `json:"_primary_term"` Type string `json:"_type"` // Deprecated field - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r UpdateResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_update_by_query.go b/opensearchapi/api_update_by_query.go index ff0b5b881..b83a35ff4 100644 --- a/opensearchapi/api_update_by_query.go +++ b/opensearchapi/api_update_by_query.go @@ -18,16 +18,15 @@ import ( ) // UpdateByQuery executes a /_update_by_query request with the optional UpdateByQueryReq -func (c Client) UpdateByQuery(ctx context.Context, req UpdateByQueryReq) (*UpdateByQueryResp, error) { - var ( - data UpdateByQueryResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) UpdateByQuery(ctx context.Context, req UpdateByQueryReq) (*UpdateByQueryResp, *opensearch.Response, error) { + var data UpdateByQueryResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // UpdateByQueryReq represents possible options for the /_update_by_query request @@ -71,10 +70,4 @@ type UpdateByQueryResp struct { Failures []json.RawMessage `json:"failures"` Type string `json:"_type"` // Deprecated field Task string `json:"task"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r UpdateByQueryResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_update_by_query_rethrottle.go b/opensearchapi/api_update_by_query_rethrottle.go index 5c72cf7b8..31b3309d2 100644 --- a/opensearchapi/api_update_by_query_rethrottle.go +++ b/opensearchapi/api_update_by_query_rethrottle.go @@ -16,16 +16,15 @@ import ( ) // UpdateByQueryRethrottle executes a / request with the optional UpdateByQueryRethrottleReq -func (c Client) UpdateByQueryRethrottle(ctx context.Context, req UpdateByQueryRethrottleReq) (*UpdateByQueryRethrottleResp, error) { - var ( - data UpdateByQueryRethrottleResp - err error - ) - if data.response, err = c.do(ctx, req, &data); err != nil { - return &data, err +func (c Client) UpdateByQueryRethrottle(ctx context.Context, req UpdateByQueryRethrottleReq) (*UpdateByQueryRethrottleResp, *opensearch.Response, error) { + var data UpdateByQueryRethrottleResp + + resp, err := c.do(ctx, req, &data) + if err != nil { + return nil, resp, err } - return &data, nil + return &data, resp, nil } // UpdateByQueryRethrottleReq represents possible options for the / request @@ -108,10 +107,4 @@ type UpdateByQueryRethrottleResp struct { } `json:"tasks"` } `json:"nodes"` NodeFailures []FailuresCause `json:"node_failures"` - response *opensearch.Response -} - -// Inspect returns the Inspect type containing the raw *opensearch.Reponse -func (r UpdateByQueryRethrottleResp) Inspect() Inspect { - return Inspect{Response: r.response} } diff --git a/opensearchapi/api_update_by_query_rethrottle_test.go b/opensearchapi/api_update_by_query_rethrottle_test.go index 93a942d5b..59566fcd8 100644 --- a/opensearchapi/api_update_by_query_rethrottle_test.go +++ b/opensearchapi/api_update_by_query_rethrottle_test.go @@ -65,7 +65,7 @@ func TestUpdateByQueryRethrottle(t *testing.T) { t.Errorf("Unexpected error: %s", err) } - updatebyquery, err := client.UpdateByQuery( + updatebyquery, _, err := client.UpdateByQuery( nil, opensearchapi.UpdateByQueryReq{ Indices: []string{testIndex}, @@ -78,7 +78,7 @@ func TestUpdateByQueryRethrottle(t *testing.T) { ) require.Nil(t, err) t.Run("with request", func(t *testing.T) { - resp, err := client.UpdateByQueryRethrottle( + resp, httpResp, err := client.UpdateByQueryRethrottle( nil, opensearchapi.UpdateByQueryRethrottleReq{ TaskID: updatebyquery.Task, @@ -87,16 +87,18 @@ func TestUpdateByQueryRethrottle(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.UpdateByQueryRethrottle(nil, opensearchapi.UpdateByQueryRethrottleReq{}) + res, httpResp, err := failingClient.UpdateByQueryRethrottle(nil, opensearchapi.UpdateByQueryRethrottleReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_update_by_query_test.go b/opensearchapi/api_update_by_query_test.go index 3d4d1f871..06e319d50 100644 --- a/opensearchapi/api_update_by_query_test.go +++ b/opensearchapi/api_update_by_query_test.go @@ -31,7 +31,7 @@ func TestUpdateByQuery(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestUpdateByQuery(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.UpdateByQuery( + resp, httpResp, err := client.UpdateByQuery( nil, opensearchapi.UpdateByQueryReq{ Indices: []string{testIndex}, @@ -53,16 +53,18 @@ func TestUpdateByQuery(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.UpdateByQuery(nil, opensearchapi.UpdateByQueryReq{}) + res, httpResp, err := failingClient.UpdateByQuery(nil, opensearchapi.UpdateByQueryReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/api_update_test.go b/opensearchapi/api_update_test.go index e75ac3b63..6e42e1260 100644 --- a/opensearchapi/api_update_test.go +++ b/opensearchapi/api_update_test.go @@ -31,7 +31,7 @@ func TestUpdate(t *testing.T) { }) for i := 1; i <= 2; i++ { - _, err = client.Document.Create( + _, _, err = client.Document.Create( nil, opensearchapi.DocumentCreateReq{ Index: testIndex, @@ -44,7 +44,7 @@ func TestUpdate(t *testing.T) { } t.Run("with request", func(t *testing.T) { - resp, err := client.Update( + resp, httpResp, err := client.Update( nil, opensearchapi.UpdateReq{ Index: testIndex, @@ -54,16 +54,18 @@ func TestUpdate(t *testing.T) { ) require.Nil(t, err) assert.NotEmpty(t, resp) - ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) + assert.NotNil(t, httpResp) + ostest.CompareRawJSONwithParsedJSON(t, resp, httpResp) }) t.Run("inspect", func(t *testing.T) { failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) - res, err := failingClient.Update(nil, opensearchapi.UpdateReq{}) + res, httpResp, err := failingClient.Update(nil, opensearchapi.UpdateReq{}) assert.NotNil(t, err) - assert.NotNil(t, res) - osapitest.VerifyInspect(t, res.Inspect()) + assert.Nil(t, res) + assert.NotNil(t, httpResp) + osapitest.VerifyResponse(t, httpResp) }) } diff --git a/opensearchapi/inspect.go b/opensearchapi/inspect.go deleted file mode 100644 index 47eabba1c..000000000 --- a/opensearchapi/inspect.go +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// -// The OpenSearch Contributors require contributions made to -// this file be licensed under the Apache-2.0 license or a -// compatible open source license. - -package opensearchapi - -import "github.com/opensearch-project/opensearch-go/v4" - -// Inspect represents the struct returned by Inspect() func, its main use is to return the opensearch.Response to the user -type Inspect struct { - Response *opensearch.Response -} diff --git a/opensearchapi/internal/test/helper.go b/opensearchapi/internal/test/helper.go index a671d169c..768682233 100644 --- a/opensearchapi/internal/test/helper.go +++ b/opensearchapi/internal/test/helper.go @@ -19,11 +19,6 @@ import ( "github.com/opensearch-project/opensearch-go/v4/opensearchapi" ) -// Response is a dummy interface to run tests with Inspect() -type Response interface { - Inspect() opensearchapi.Inspect -} - // CreateFailingClient returns an opensearchapi.Client that always return 400 with an empty object as body func CreateFailingClient() (*opensearchapi.Client, error) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -37,20 +32,10 @@ func CreateFailingClient() (*opensearchapi.Client, error) { return opensearchapi.NewClient(opensearchapi.Config{Client: opensearch.Config{Addresses: []string{ts.URL}}}) } -// VerifyInspect validates the returned opensearchapi.Inspect type -func VerifyInspect(t *testing.T, inspect opensearchapi.Inspect) { +// VerifyResponse validates the returned opensearchapi.Response type +func VerifyResponse(t *testing.T, response *opensearch.Response) { t.Helper() - assert.NotEmpty(t, inspect) - assert.Equal(t, http.StatusBadRequest, inspect.Response.StatusCode) - assert.NotEmpty(t, inspect.Response.Body) -} - -// DummyInspect is a struct to match the Response interface that is used for testing -type DummyInspect struct { - Response *opensearch.Response -} - -// Inspect is a fuction of DummyInspect use to match the Response interface -func (r DummyInspect) Inspect() opensearchapi.Inspect { - return opensearchapi.Inspect{Response: r.Response} + assert.NotNil(t, response) + assert.Equal(t, http.StatusBadRequest, response.StatusCode) + assert.NotEmpty(t, response.Body) } diff --git a/opensearchutil/bulk_indexer.go b/opensearchutil/bulk_indexer.go index 380ed70e4..45985ca73 100644 --- a/opensearchutil/bulk_indexer.go +++ b/opensearchutil/bulk_indexer.go @@ -501,7 +501,7 @@ func (w *worker) flush(ctx context.Context) error { Header: w.bi.config.Header, } - blk, err = w.bi.config.Client.Bulk(ctx, req) + blk, _, err = w.bi.config.Client.Bulk(ctx, req) if err != nil { atomic.AddUint64(&w.bi.stats.numFailed, uint64(len(w.items))) if w.bi.config.OnError != nil {