diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index b35a4b3c..b778b122 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -62,11 +62,11 @@ search_post_1: |- get_task_1: |- client.GetTask(1); get_all_tasks_1: |- - client.GetTasks(); + client.GetTasks(nil); get_task_by_index_1: |- client.Index("movies").GetTask(1) get_all_tasks_by_index_1: |- - client.Index("movies").GetTasks() + client.Index("movies").GetTasks(nil) get_one_key_1: |- client.GetKey("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4") get_keys_1: |- diff --git a/README.md b/README.md index 619b5f62..5fad705f 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,11 @@ func main() { os.Exit(1) } - fmt.Println(task.taskID) + fmt.Println(task.taskUID) } ``` -With the `taskID`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task endpoint](https://docs.meilisearch.com/learn/advanced/asynchronous_operations.html#task-status). +With the `taskUID`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task endpoint](https://docs.meilisearch.com/learn/advanced/asynchronous_operations.html#task-status). #### Basic Search diff --git a/client.go b/client.go index 02cd4442..e58ce4fa 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" "github.com/golang-jwt/jwt" @@ -51,9 +52,9 @@ type ClientInterface interface { GetVersion() (resp *Version, err error) Health() (*Health, error) IsHealthy() bool - GetTask(taskID int64) (resp *Task, err error) - GetTasks() (resp *ResultTask, err error) - WaitForTask(task *Task, options ...WaitParams) (*Task, error) + GetTask(taskUID int64) (resp *Task, err error) + GetTasks(param *TasksQuery) (resp *TaskResult, err error) + WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) GenerateTenantToken(searchRules map[string]interface{}, options *TenantTokenOptions) (resp string, err error) } @@ -257,10 +258,10 @@ func (c *Client) GetDumpStatus(dumpUID string) (resp *Dump, err error) { return resp, nil } -func (c *Client) GetTask(taskID int64) (resp *Task, err error) { +func (c *Client) GetTask(taskUID int64) (resp *Task, err error) { resp = &Task{} req := internalRequest{ - endpoint: "/tasks/" + strconv.FormatInt(taskID, 10), + endpoint: "/tasks/" + strconv.FormatInt(taskUID, 10), method: http.MethodGet, withRequest: nil, withResponse: resp, @@ -273,16 +274,32 @@ func (c *Client) GetTask(taskID int64) (resp *Task, err error) { return resp, nil } -func (c *Client) GetTasks() (resp *ResultTask, err error) { - resp = &ResultTask{} +func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) { + resp = &TaskResult{} req := internalRequest{ endpoint: "/tasks", method: http.MethodGet, withRequest: nil, withResponse: &resp, + withQueryParams: map[string]string{}, acceptedStatusCodes: []int{http.StatusOK}, functionName: "GetTasks", } + if param != nil && param.Limit != 0 { + req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10) + } + if param != nil && param.From != 0 { + req.withQueryParams["from"] = strconv.FormatInt(param.From, 10) + } + if param != nil && param.Status != "" { + req.withQueryParams["status"] = param.Status + } + if param != nil && param.Type != "" { + req.withQueryParams["type"] = param.Type + } + if param != nil && len(param.IndexUID) != 0 { + req.withQueryParams["indexUid"] = strings.Join(param.IndexUID, ",") + } if err := c.executeRequest(req); err != nil { return nil, err } @@ -295,7 +312,7 @@ func (c *Client) GetTasks() (resp *ResultTask, err error) { // the TaskStatus. // If no ctx and interval are provided WaitForTask will check each 50ms the // status of a task. -func (c *Client) WaitForTask(task *Task, options ...WaitParams) (*Task, error) { +func (c *Client) WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) { if options == nil { ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*5) defer cancelFunc() @@ -310,7 +327,7 @@ func (c *Client) WaitForTask(task *Task, options ...WaitParams) (*Task, error) { if err := options[0].Context.Err(); err != nil { return nil, err } - getTask, err := c.GetTask(task.UID) + getTask, err := c.GetTask(taskUID) if err != nil { return nil, err } diff --git a/client_index_test.go b/client_index_test.go index 6d5c6941..00818cf7 100644 --- a/client_index_test.go +++ b/client_index_test.go @@ -107,7 +107,7 @@ func TestClient_CreateIndex(t *testing.T) { // Make sure that timestamps are also retrieved require.NotZero(t, gotResp.EnqueuedAt) - _, err := c.WaitForTask(gotResp) + _, err := c.WaitForTask(gotResp.TaskUID) require.NoError(t, err) index, err := c.GetIndex(tt.args.config.Uid) diff --git a/client_test.go b/client_test.go index 92feb0bc..6b5e5ce4 100644 --- a/client_test.go +++ b/client_test.go @@ -596,7 +596,7 @@ func TestClient_GetTask(t *testing.T) { type args struct { UID string client *Client - taskID int64 + taskUID int64 document []docTest } tests := []struct { @@ -606,9 +606,9 @@ func TestClient_GetTask(t *testing.T) { { name: "TestBasicGetTask", args: args{ - UID: "TestBasicGetTask", - client: defaultClient, - taskID: 0, + UID: "TestBasicGetTask", + client: defaultClient, + taskUID: 0, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, @@ -617,9 +617,9 @@ func TestClient_GetTask(t *testing.T) { { name: "TestGetTaskWithCustomClient", args: args{ - UID: "TestGetTaskWithCustomClient", - client: customClient, - taskID: 1, + UID: "TestGetTaskWithCustomClient", + client: customClient, + taskUID: 1, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, @@ -628,9 +628,9 @@ func TestClient_GetTask(t *testing.T) { { name: "TestGetTask", args: args{ - UID: "TestGetTask", - client: defaultClient, - taskID: 2, + UID: "TestGetTask", + client: defaultClient, + taskUID: 2, document: []docTest{ {ID: "456", Name: "Le Petit Prince"}, {ID: "1", Name: "Alice In Wonderland"}, @@ -650,14 +650,14 @@ func TestClient_GetTask(t *testing.T) { task, err := i.AddDocuments(tt.args.document) require.NoError(t, err) - _, err = c.WaitForTask(task) + _, err = c.WaitForTask(task.TaskUID) require.NoError(t, err) - gotResp, err := c.GetTask(task.UID) + gotResp, err := c.GetTask(task.TaskUID) require.NoError(t, err) require.NotNil(t, gotResp) require.NotNil(t, gotResp.Details) - require.GreaterOrEqual(t, gotResp.UID, tt.args.taskID) + require.GreaterOrEqual(t, gotResp.UID, tt.args.taskUID) require.Equal(t, tt.args.UID, gotResp.IndexUID) require.Equal(t, TaskStatusSucceeded, gotResp.Status) require.Equal(t, len(tt.args.document), gotResp.Details.ReceivedDocuments) @@ -676,6 +676,7 @@ func TestClient_GetTasks(t *testing.T) { UID string client *Client document []docTest + query *TasksQuery } tests := []struct { name string @@ -689,6 +690,7 @@ func TestClient_GetTasks(t *testing.T) { document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, + query: nil, }, }, { @@ -699,6 +701,61 @@ func TestClient_GetTasks(t *testing.T) { document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, + query: nil, + }, + }, + { + name: "TestGetTasksWithLimit", + args: args{ + UID: "indexUID", + client: defaultClient, + document: []docTest{ + {ID: "123", Name: "Pride and Prejudice"}, + }, + query: &TasksQuery{ + Limit: 1, + }, + }, + }, + { + name: "TestGetTasksWithLimit", + args: args{ + UID: "indexUID", + client: defaultClient, + document: []docTest{ + {ID: "123", Name: "Pride and Prejudice"}, + }, + query: &TasksQuery{ + Limit: 1, + }, + }, + }, + { + name: "TestGetTasksWithFrom", + args: args{ + UID: "indexUID", + client: defaultClient, + document: []docTest{ + {ID: "123", Name: "Pride and Prejudice"}, + }, + query: &TasksQuery{ + From: 0, + }, + }, + }, + { + name: "TestGetTasksWithParameters", + args: args{ + UID: "indexUID", + client: defaultClient, + document: []docTest{ + {ID: "123", Name: "Pride and Prejudice"}, + }, + query: &TasksQuery{ + Limit: 1, + From: 0, + IndexUID: []string{"indexUID"}, + }, }, }, } @@ -711,14 +768,24 @@ func TestClient_GetTasks(t *testing.T) { task, err := i.AddDocuments(tt.args.document) require.NoError(t, err) - _, err = c.WaitForTask(task) + _, err = c.WaitForTask(task.TaskUID) require.NoError(t, err) - gotResp, err := i.GetTasks() + gotResp, err := i.GetTasks(tt.args.query) require.NoError(t, err) require.NotNil(t, (*gotResp).Results[0].Status) require.NotZero(t, (*gotResp).Results[0].UID) require.NotNil(t, (*gotResp).Results[0].Type) + if tt.args.query != nil { + if tt.args.query.Limit != 0 { + require.Equal(t, tt.args.query.Limit, (*gotResp).Limit) + } else { + require.Equal(t, int64(20), (*gotResp).Limit) + } + if tt.args.query.From != 0 { + require.Equal(t, tt.args.query.From, (*gotResp).From) + } + } }) } } @@ -727,7 +794,7 @@ func TestClient_DefaultWaitForTask(t *testing.T) { type args struct { UID string client *Client - taskID *Task + taskUID *Task document []docTest } tests := []struct { @@ -740,7 +807,7 @@ func TestClient_DefaultWaitForTask(t *testing.T) { args: args{ UID: "TestDefaultWaitForTask", client: defaultClient, - taskID: &Task{ + taskUID: &Task{ UID: 0, }, document: []docTest{ @@ -756,7 +823,7 @@ func TestClient_DefaultWaitForTask(t *testing.T) { args: args{ UID: "TestDefaultWaitForTaskWithCustomClient", client: customClient, - taskID: &Task{ + taskUID: &Task{ UID: 0, }, document: []docTest{ @@ -776,7 +843,7 @@ func TestClient_DefaultWaitForTask(t *testing.T) { task, err := c.Index(tt.args.UID).AddDocuments(tt.args.document) require.NoError(t, err) - gotTask, err := c.WaitForTask(task) + gotTask, err := c.WaitForTask(task.TaskUID) require.NoError(t, err) require.Equal(t, tt.want, gotTask.Status) }) @@ -789,7 +856,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { client *Client interval time.Duration timeout time.Duration - taskID *Task + taskUID *Task document []docTest } tests := []struct { @@ -804,7 +871,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { client: defaultClient, interval: time.Millisecond * 50, timeout: time.Second * 5, - taskID: &Task{ + taskUID: &Task{ UID: 0, }, document: []docTest{ @@ -822,7 +889,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { client: customClient, interval: time.Millisecond * 50, timeout: time.Second * 5, - taskID: &Task{ + taskUID: &Task{ UID: 0, }, document: []docTest{ @@ -840,7 +907,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { client: defaultClient, interval: time.Millisecond * 10, timeout: time.Second * 5, - taskID: &Task{ + taskUID: &Task{ UID: 1, }, document: []docTest{ @@ -858,7 +925,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { client: defaultClient, interval: time.Millisecond * 50, timeout: time.Millisecond * 10, - taskID: &Task{ + taskUID: &Task{ UID: 1, }, document: []docTest{ @@ -881,7 +948,7 @@ func TestClient_WaitForTaskWithContext(t *testing.T) { ctx, cancelFunc := context.WithTimeout(context.Background(), tt.args.timeout) defer cancelFunc() - gotTask, err := c.WaitForTask(task, WaitParams{Context: ctx, Interval: tt.args.interval}) + gotTask, err := c.WaitForTask(task.TaskUID, WaitParams{Context: ctx, Interval: tt.args.interval}) if tt.args.timeout < tt.args.interval { require.Error(t, err) } else { diff --git a/index.go b/index.go index 353a78b3..ab52f807 100644 --- a/index.go +++ b/index.go @@ -38,8 +38,8 @@ type IndexInterface interface { DeleteAllDocuments() (resp *Task, err error) Search(query string, request *SearchRequest) (*SearchResponse, error) - GetTask(taskID int64) (resp *Task, err error) - GetTasks() (resp *ResultTask, err error) + GetTask(taskUID int64) (resp *Task, err error) + GetTasks(param *TasksQuery) (resp *TaskResult, err error) GetSettings() (resp *Settings, err error) UpdateSettings(request *Settings) (resp *Task, err error) @@ -66,7 +66,7 @@ type IndexInterface interface { UpdateFilterableAttributes(request *[]string) (resp *Task, err error) ResetFilterableAttributes() (resp *Task, err error) - WaitForTask(task *Task, options ...WaitParams) (*Task, error) + WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) } var _ IndexInterface = &Index{} @@ -158,32 +158,39 @@ func (i Index) GetStats() (resp *StatsIndex, err error) { return resp, nil } -func (i Index) GetTask(taskID int64) (resp *Task, err error) { - resp = &Task{} - req := internalRequest{ - endpoint: "/indexes/" + i.UID + "/tasks/" + strconv.FormatInt(taskID, 10), - method: http.MethodGet, - withRequest: nil, - withResponse: resp, - acceptedStatusCodes: []int{http.StatusOK}, - functionName: "GetTask", - } - if err := i.client.executeRequest(req); err != nil { - return nil, err - } - return resp, nil +func (i Index) GetTask(taskUID int64) (resp *Task, err error) { + return i.client.GetTask(taskUID) } -func (i Index) GetTasks() (resp *ResultTask, err error) { - resp = &ResultTask{} +func (i Index) GetTasks(param *TasksQuery) (resp *TaskResult, err error) { + resp = &TaskResult{} req := internalRequest{ - endpoint: "/indexes/" + i.UID + "/tasks", + endpoint: "/tasks?indexUid=" + i.UID, method: http.MethodGet, withRequest: nil, withResponse: &resp, + withQueryParams: map[string]string{}, acceptedStatusCodes: []int{http.StatusOK}, functionName: "GetTasks", } + if param != nil && param.Limit != 0 { + req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10) + } + if param != nil && param.From != 0 { + req.withQueryParams["from"] = strconv.FormatInt(param.From, 10) + } + if param != nil && param.Status != "" { + req.withQueryParams["status"] = param.Status + } + if param != nil && param.Type != "" { + req.withQueryParams["type"] = param.Type + } + if param != nil && len(param.IndexUID) != 0 { + param.IndexUID = append(param.IndexUID, i.UID) + req.withQueryParams["indexUid"] = strings.Join(param.IndexUID, ",") + } else { + req.withQueryParams["indexUid"] = i.UID + } if err := i.client.executeRequest(req); err != nil { return nil, err } @@ -195,6 +202,6 @@ func (i Index) GetTasks() (resp *ResultTask, err error) { // the TaskStatus. // If no ctx and interval are provided WaitForTask will check each 50ms the // status of a task. -func (i Index) WaitForTask(task *Task, options ...WaitParams) (*Task, error) { - return i.client.WaitForTask(task, options...) +func (i Index) WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) { + return i.client.WaitForTask(taskUID, options...) } diff --git a/index_documents_test.go b/index_documents_test.go index 2cb1aad0..06bed64b 100644 --- a/index_documents_test.go +++ b/index_documents_test.go @@ -303,14 +303,14 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { }, wantResp: []Task{ { - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, }, @@ -338,14 +338,14 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { }, wantResp: []Task{ { - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, }, @@ -361,7 +361,7 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, gotResp[i].UID, tt.wantResp[i].UID) + require.GreaterOrEqual(t, gotResp[i].TaskUID, tt.wantResp[i].TaskUID) require.Equal(t, gotResp[i].Status, tt.wantResp[i].Status) require.Equal(t, gotResp[i].Type, tt.wantResp[i].Type) require.Equal(t, gotResp[i].IndexUID, tt.args.UID) @@ -370,13 +370,13 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { testWaitForBatchTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{ + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{ Limit: 4, }, &documents) require.NoError(t, err) - require.Equal(t, tt.args.documentsPtr, documents) + require.Equal(t, tt.args.documentsPtr, documents.Results) }) } @@ -390,7 +390,7 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, gotResp[i].UID, tt.wantResp[i].UID) + require.GreaterOrEqual(t, gotResp[i].TaskUID, tt.wantResp[i].TaskUID) require.Equal(t, gotResp[i].Status, tt.wantResp[i].Status) require.Equal(t, gotResp[i].Type, tt.wantResp[i].Type) require.Equal(t, gotResp[i].IndexUID, tt.args.UID) @@ -399,13 +399,13 @@ func TestIndex_AddDocumentsInBatches(t *testing.T) { testWaitForBatchTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{ + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{ Limit: 4, }, &documents) require.NoError(t, err) - require.Equal(t, tt.args.documentsPtr, documents) + require.Equal(t, tt.args.documentsPtr, documents.Results) }) } } @@ -464,9 +464,9 @@ func TestIndex_AddDocumentsCsv(t *testing.T) { documents: testCsvDocuments, }, wantResp: &Task{ - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, } @@ -503,17 +503,17 @@ func TestIndex_AddDocumentsCsv(t *testing.T) { } require.NoError(t, err) - require.GreaterOrEqual(t, gotResp.UID, tt.wantResp.UID) - require.Equal(t, gotResp.Status, tt.wantResp.Status) - require.Equal(t, gotResp.Type, tt.wantResp.Type) + require.GreaterOrEqual(t, gotResp.TaskUID, tt.wantResp.TaskUID) + require.Equal(t, tt.wantResp.Status, gotResp.Status) + require.Equal(t, tt.wantResp.Type, gotResp.Type) require.NotZero(t, gotResp.EnqueuedAt) testWaitForTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{}, &documents) + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{}, &documents) require.NoError(t, err) - require.Equal(t, wantDocs, documents) + require.Equal(t, wantDocs, documents.Results) }) } @@ -548,19 +548,19 @@ func TestIndex_AddDocumentsCsvInBatches(t *testing.T) { }, wantResp: []Task{ { - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 2, + TaskUID: 2, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, }, @@ -600,7 +600,7 @@ func TestIndex_AddDocumentsCsvInBatches(t *testing.T) { require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, gotResp[i].UID, tt.wantResp[i].UID) + require.GreaterOrEqual(t, gotResp[i].TaskUID, tt.wantResp[i].TaskUID) require.Equal(t, gotResp[i].Status, tt.wantResp[i].Status) require.Equal(t, gotResp[i].Type, tt.wantResp[i].Type) require.NotZero(t, gotResp[i].EnqueuedAt) @@ -608,10 +608,10 @@ func TestIndex_AddDocumentsCsvInBatches(t *testing.T) { testWaitForBatchTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{}, &documents) + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{}, &documents) require.NoError(t, err) - require.Equal(t, wantDocs, documents) + require.Equal(t, wantDocs, documents.Results) }) } @@ -667,9 +667,9 @@ func TestIndex_AddDocumentsNdjson(t *testing.T) { documents: testNdjsonDocuments, }, wantResp: &Task{ - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, } @@ -706,17 +706,17 @@ func TestIndex_AddDocumentsNdjson(t *testing.T) { } require.NoError(t, err) - require.GreaterOrEqual(t, gotResp.UID, tt.wantResp.UID) - require.Equal(t, gotResp.Status, tt.wantResp.Status) - require.Equal(t, gotResp.Type, tt.wantResp.Type) + require.GreaterOrEqual(t, gotResp.TaskUID, tt.wantResp.TaskUID) + require.Equal(t, tt.wantResp.Status, gotResp.Status) + require.Equal(t, tt.wantResp.Type, gotResp.Type) require.NotZero(t, gotResp.EnqueuedAt) testWaitForTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{}, &documents) + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{}, &documents) require.NoError(t, err) - require.Equal(t, wantDocs, documents) + require.Equal(t, wantDocs, documents.Results) }) } @@ -751,19 +751,19 @@ func TestIndex_AddDocumentsNdjsonInBatches(t *testing.T) { }, wantResp: []Task{ { - UID: 0, + TaskUID: 0, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, { - UID: 2, + TaskUID: 2, Status: "enqueued", - Type: "documentAddition", + Type: "documentAdditionOrUpdate", }, }, }, @@ -803,7 +803,7 @@ func TestIndex_AddDocumentsNdjsonInBatches(t *testing.T) { require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, gotResp[i].UID, tt.wantResp[i].UID) + require.GreaterOrEqual(t, gotResp[i].TaskUID, tt.wantResp[i].TaskUID) require.Equal(t, gotResp[i].Status, tt.wantResp[i].Status) require.Equal(t, gotResp[i].Type, tt.wantResp[i].Type) require.NotZero(t, gotResp[i].EnqueuedAt) @@ -811,10 +811,10 @@ func TestIndex_AddDocumentsNdjsonInBatches(t *testing.T) { testWaitForBatchTask(t, i, gotResp) - var documents []map[string]interface{} - err = i.GetDocuments(&DocumentsRequest{}, &documents) + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{}, &documents) require.NoError(t, err) - require.Equal(t, wantDocs, documents) + require.Equal(t, wantDocs, documents.Results) }) } @@ -842,9 +842,9 @@ func TestIndex_DeleteAllDocuments(t *testing.T) { client: defaultClient, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "clearAll", + Type: "documentDeletion", }, }, { @@ -854,9 +854,9 @@ func TestIndex_DeleteAllDocuments(t *testing.T) { client: customClient, }, wantResp: &Task{ - UID: 2, + TaskUID: 2, Status: "enqueued", - Type: "clearAll", + Type: "documentDeletion", }, }, } @@ -869,17 +869,17 @@ func TestIndex_DeleteAllDocuments(t *testing.T) { SetUpBasicIndex(tt.args.UID) gotResp, err := i.DeleteAllDocuments() require.NoError(t, err) - require.GreaterOrEqual(t, gotResp.UID, tt.wantResp.UID) - require.Equal(t, gotResp.Status, tt.wantResp.Status) - require.Equal(t, gotResp.Type, tt.wantResp.Type) + require.GreaterOrEqual(t, gotResp.TaskUID, tt.wantResp.TaskUID) + require.Equal(t, tt.wantResp.Status, gotResp.Status) + require.Equal(t, tt.wantResp.Type, gotResp.Type) require.NotZero(t, gotResp.EnqueuedAt) testWaitForTask(t, i, gotResp) - var documents interface{} - err = i.GetDocuments(&DocumentsRequest{Limit: 5}, &documents) + var documents DocumentsResult + err = i.GetDocuments(&DocumentsQuery{Limit: 5}, &documents) require.NoError(t, err) - require.Empty(t, documents) + require.Empty(t, documents.Results) }) } } @@ -908,7 +908,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -924,7 +924,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -942,7 +942,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -958,7 +958,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -974,7 +974,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -992,7 +992,7 @@ func TestIndex_DeleteOneDocument(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -1005,16 +1005,16 @@ func TestIndex_DeleteOneDocument(t *testing.T) { t.Cleanup(cleanup(c)) gotAddResp, err := i.AddDocuments(tt.args.documentsPtr) - require.GreaterOrEqual(t, gotAddResp.UID, tt.wantResp.UID) + require.GreaterOrEqual(t, gotAddResp.TaskUID, tt.wantResp.TaskUID) require.NoError(t, err) testWaitForTask(t, i, gotAddResp) gotResp, err := i.DeleteDocument(tt.args.identifier) require.NoError(t, err) - require.GreaterOrEqual(t, gotResp.UID, tt.wantResp.UID) - require.Equal(t, gotResp.Status, tt.wantResp.Status) - require.Equal(t, gotResp.Type, tt.wantResp.Type) + require.GreaterOrEqual(t, gotResp.TaskUID, tt.wantResp.TaskUID) + require.Equal(t, tt.wantResp.Status, gotResp.Status) + require.Equal(t, tt.wantResp.Type, gotResp.Type) require.NotZero(t, gotResp.EnqueuedAt) testWaitForTask(t, i, gotResp) @@ -1050,7 +1050,7 @@ func TestIndex_DeleteDocuments(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -1066,7 +1066,7 @@ func TestIndex_DeleteDocuments(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -1084,7 +1084,7 @@ func TestIndex_DeleteDocuments(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -1102,7 +1102,7 @@ func TestIndex_DeleteDocuments(t *testing.T) { }, }, wantResp: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", Type: "documentDeletion", }, @@ -1121,9 +1121,9 @@ func TestIndex_DeleteDocuments(t *testing.T) { gotResp, err := i.DeleteDocuments(tt.args.identifier) require.NoError(t, err) - require.GreaterOrEqual(t, gotResp.UID, tt.wantResp.UID) - require.Equal(t, gotResp.Status, tt.wantResp.Status) - require.Equal(t, gotResp.Type, tt.wantResp.Type) + require.GreaterOrEqual(t, gotResp.TaskUID, tt.wantResp.TaskUID) + require.Equal(t, tt.wantResp.Status, gotResp.Status) + require.Equal(t, tt.wantResp.Type, gotResp.Type) require.NotZero(t, gotResp.EnqueuedAt) testWaitForTask(t, i, gotResp) @@ -1223,9 +1223,9 @@ func TestIndex_UpdateDocuments(t *testing.T) { }, }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1238,9 +1238,9 @@ func TestIndex_UpdateDocuments(t *testing.T) { }, }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1256,9 +1256,9 @@ func TestIndex_UpdateDocuments(t *testing.T) { }, }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1271,9 +1271,9 @@ func TestIndex_UpdateDocuments(t *testing.T) { }, }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1289,9 +1289,9 @@ func TestIndex_UpdateDocuments(t *testing.T) { }, }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, } @@ -1304,7 +1304,7 @@ func TestIndex_UpdateDocuments(t *testing.T) { got, err := i.UpdateDocuments(tt.args.documentsPtr) require.NoError(t, err) - require.GreaterOrEqual(t, got.UID, tt.want.UID) + require.GreaterOrEqual(t, got.TaskUID, tt.want.TaskUID) require.Equal(t, got.Status, tt.want.Status) require.Equal(t, got.Type, tt.want.Type) require.NotZero(t, got.EnqueuedAt) @@ -1345,9 +1345,9 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { primaryKey: "book_id", }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1361,9 +1361,9 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { primaryKey: "book_id", }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1380,9 +1380,9 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { primaryKey: "book_id", }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1396,9 +1396,9 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { primaryKey: "book_id", }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, { @@ -1415,9 +1415,9 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { primaryKey: "book_id", }, want: &Task{ - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, } @@ -1430,7 +1430,7 @@ func TestIndex_UpdateDocumentsWithPrimaryKey(t *testing.T) { got, err := i.UpdateDocuments(tt.args.documentsPtr, tt.args.primaryKey) require.NoError(t, err) - require.GreaterOrEqual(t, got.UID, tt.want.UID) + require.GreaterOrEqual(t, got.TaskUID, tt.want.TaskUID) require.Equal(t, got.Status, tt.want.Status) require.Equal(t, got.Type, tt.want.Type) require.NotZero(t, got.EnqueuedAt) @@ -1482,14 +1482,14 @@ func TestIndex_UpdateDocumentsInBatches(t *testing.T) { }, want: []Task{ { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, { - UID: 2, + TaskUID: 2, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, }, @@ -1514,14 +1514,14 @@ func TestIndex_UpdateDocumentsInBatches(t *testing.T) { }, want: []Task{ { - UID: 1, + TaskUID: 1, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, { - UID: 2, + TaskUID: 2, Status: "enqueued", - Type: "documentPartial", + Type: "documentAdditionOrUpdate", }, }, }, @@ -1537,7 +1537,7 @@ func TestIndex_UpdateDocumentsInBatches(t *testing.T) { got, err := i.UpdateDocumentsInBatches(tt.args.documentsPtr, tt.args.batchSize) require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, got[i].UID, tt.want[i].UID) + require.GreaterOrEqual(t, got[i].TaskUID, tt.want[i].TaskUID) require.Equal(t, got[i].Status, tt.want[i].Status) require.Equal(t, got[i].Type, tt.want[i].Type) require.NotZero(t, got[i].EnqueuedAt) @@ -1565,7 +1565,7 @@ func TestIndex_UpdateDocumentsInBatches(t *testing.T) { got, err := i.UpdateDocumentsInBatches(tt.args.documentsPtr, tt.args.batchSize, tt.args.primaryKey) require.NoError(t, err) for i := 0; i < 2; i++ { - require.GreaterOrEqual(t, got[i].UID, tt.want[i].UID) + require.GreaterOrEqual(t, got[i].TaskUID, tt.want[i].TaskUID) require.Equal(t, got[i].Status, tt.want[i].Status) require.Equal(t, got[i].Type, tt.want[i].Type) require.NotZero(t, got[i].EnqueuedAt) diff --git a/index_settings_test.go b/index_settings_test.go index 6f370915..ccdc3f92 100644 --- a/index_settings_test.go +++ b/index_settings_test.go @@ -438,7 +438,7 @@ func TestIndex_ResetFilterableAttributes(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -448,7 +448,7 @@ func TestIndex_ResetFilterableAttributes(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -461,7 +461,7 @@ func TestIndex_ResetFilterableAttributes(t *testing.T) { gotTask, err := i.ResetFilterableAttributes() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetFilterableAttributes() @@ -489,7 +489,7 @@ func TestIndex_ResetDisplayedAttributes(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -500,7 +500,7 @@ func TestIndex_ResetDisplayedAttributes(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -514,7 +514,7 @@ func TestIndex_ResetDisplayedAttributes(t *testing.T) { gotTask, err := i.ResetDisplayedAttributes() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetDisplayedAttributes() @@ -541,7 +541,7 @@ func TestIndex_ResetDistinctAttribute(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -551,7 +551,7 @@ func TestIndex_ResetDistinctAttribute(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -564,7 +564,7 @@ func TestIndex_ResetDistinctAttribute(t *testing.T) { gotTask, err := i.ResetDistinctAttribute() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetDistinctAttribute() @@ -592,7 +592,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultRankingRules, }, @@ -603,7 +603,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultRankingRules, }, @@ -617,7 +617,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { gotTask, err := i.ResetRankingRules() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetRankingRules() @@ -645,7 +645,7 @@ func TestIndex_ResetSearchableAttributes(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -656,7 +656,7 @@ func TestIndex_ResetSearchableAttributes(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -670,7 +670,7 @@ func TestIndex_ResetSearchableAttributes(t *testing.T) { gotTask, err := i.ResetSearchableAttributes() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetSearchableAttributes() @@ -698,7 +698,7 @@ func TestIndex_ResetSettings(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -719,7 +719,7 @@ func TestIndex_ResetSettings(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -743,7 +743,7 @@ func TestIndex_ResetSettings(t *testing.T) { gotTask, err := i.ResetSettings() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetSettings() @@ -770,7 +770,7 @@ func TestIndex_ResetStopWords(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -780,7 +780,7 @@ func TestIndex_ResetStopWords(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -793,7 +793,7 @@ func TestIndex_ResetStopWords(t *testing.T) { gotTask, err := i.ResetStopWords() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetStopWords() @@ -820,7 +820,7 @@ func TestIndex_ResetSynonyms(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -830,7 +830,7 @@ func TestIndex_ResetSynonyms(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -843,7 +843,7 @@ func TestIndex_ResetSynonyms(t *testing.T) { gotTask, err := i.ResetSynonyms() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetSynonyms() @@ -870,7 +870,7 @@ func TestIndex_ResetSortableAttributes(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -880,7 +880,7 @@ func TestIndex_ResetSortableAttributes(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -893,7 +893,7 @@ func TestIndex_ResetSortableAttributes(t *testing.T) { gotTask, err := i.ResetSortableAttributes() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetSortableAttributes() @@ -921,7 +921,7 @@ func TestIndex_ResetTypoTolerance(t *testing.T) { client: defaultClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -932,7 +932,7 @@ func TestIndex_ResetTypoTolerance(t *testing.T) { client: customClient, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -946,7 +946,7 @@ func TestIndex_ResetTypoTolerance(t *testing.T) { gotTask, err := i.ResetTypoTolerance() require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err := i.GetTypoTolerance() @@ -977,7 +977,7 @@ func TestIndex_UpdateFilterableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -990,7 +990,7 @@ func TestIndex_UpdateFilterableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -1007,7 +1007,7 @@ func TestIndex_UpdateFilterableAttributes(t *testing.T) { gotTask, err := i.UpdateFilterableAttributes(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetFilterableAttributes() @@ -1039,7 +1039,7 @@ func TestIndex_UpdateDisplayedAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -1053,7 +1053,7 @@ func TestIndex_UpdateDisplayedAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -1071,7 +1071,7 @@ func TestIndex_UpdateDisplayedAttributes(t *testing.T) { gotTask, err := i.UpdateDisplayedAttributes(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetDisplayedAttributes() @@ -1100,7 +1100,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { request: "movie_id", }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -1111,7 +1111,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { request: "movie_id", }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -1128,7 +1128,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { gotTask, err := i.UpdateDistinctAttribute(tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetDistinctAttribute() @@ -1160,7 +1160,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultRankingRules, }, @@ -1174,7 +1174,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultRankingRules, }, @@ -1188,7 +1188,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultRankingRules, }, @@ -1206,7 +1206,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { gotTask, err := i.UpdateRankingRules(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetRankingRules() @@ -1238,7 +1238,7 @@ func TestIndex_UpdateSearchableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -1252,7 +1252,7 @@ func TestIndex_UpdateSearchableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &[]string{"*"}, }, @@ -1270,7 +1270,7 @@ func TestIndex_UpdateSearchableAttributes(t *testing.T) { gotTask, err := i.UpdateSearchableAttributes(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetSearchableAttributes() @@ -1332,7 +1332,7 @@ func TestIndex_UpdateSettings(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1386,7 +1386,7 @@ func TestIndex_UpdateSettings(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1414,7 +1414,7 @@ func TestIndex_UpdateSettings(t *testing.T) { gotTask, err := i.UpdateSettings(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetSettings() @@ -1489,7 +1489,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1553,7 +1553,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1617,7 +1617,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1681,7 +1681,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1745,7 +1745,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1809,7 +1809,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1873,7 +1873,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1969,7 +1969,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &Settings{ RankingRules: defaultRankingRules, @@ -1997,7 +1997,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { gotTask, err := i.UpdateSettings(&tt.args.firstRequest) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetSettings() @@ -2006,7 +2006,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { gotTask, err = i.UpdateSettings(&tt.args.secondRequest) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) @@ -2038,7 +2038,7 @@ func TestIndex_UpdateStopWords(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -2051,7 +2051,7 @@ func TestIndex_UpdateStopWords(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -2068,7 +2068,7 @@ func TestIndex_UpdateStopWords(t *testing.T) { gotTask, err := i.UpdateStopWords(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetStopWords() @@ -2099,7 +2099,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -2112,7 +2112,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -2129,7 +2129,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) { gotTask, err := i.UpdateSynonyms(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetSynonyms() @@ -2160,7 +2160,7 @@ func TestIndex_UpdateSortableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, { @@ -2173,7 +2173,7 @@ func TestIndex_UpdateSortableAttributes(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, }, } @@ -2190,7 +2190,7 @@ func TestIndex_UpdateSortableAttributes(t *testing.T) { gotTask, err := i.UpdateSortableAttributes(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetSortableAttributes() @@ -2228,7 +2228,7 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -2248,7 +2248,7 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -2270,7 +2270,7 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -2292,7 +2292,7 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { }, }, wantTask: &Task{ - UID: 1, + TaskUID: 1, }, wantResp: &defaultTypoTolerance, }, @@ -2310,7 +2310,7 @@ func TestIndex_UpdateTypoTolerance(t *testing.T) { gotTask, err := i.UpdateTypoTolerance(&tt.args.request) require.NoError(t, err) - require.GreaterOrEqual(t, gotTask.UID, tt.wantTask.UID) + require.GreaterOrEqual(t, gotTask.TaskUID, tt.wantTask.TaskUID) testWaitForTask(t, i, gotTask) gotResp, err = i.GetTypoTolerance() diff --git a/index_test.go b/index_test.go index 8062753c..cf8e6035 100644 --- a/index_test.go +++ b/index_test.go @@ -195,7 +195,7 @@ func TestIndex_GetTask(t *testing.T) { type args struct { UID string client *Client - taskID int64 + taskUID int64 document []docTest } tests := []struct { @@ -205,9 +205,9 @@ func TestIndex_GetTask(t *testing.T) { { name: "TestIndexBasicGetTask", args: args{ - UID: "TestIndexBasicGetTask", - client: defaultClient, - taskID: 0, + UID: "TestIndexBasicGetTask", + client: defaultClient, + taskUID: 0, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, @@ -216,9 +216,9 @@ func TestIndex_GetTask(t *testing.T) { { name: "TestIndexGetTaskWithCustomClient", args: args{ - UID: "TestIndexGetTaskWithCustomClient", - client: customClient, - taskID: 0, + UID: "TestIndexGetTaskWithCustomClient", + client: customClient, + taskUID: 0, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, }, @@ -227,9 +227,9 @@ func TestIndex_GetTask(t *testing.T) { { name: "TestIndexGetTask", args: args{ - UID: "TestIndexGetTask", - client: defaultClient, - taskID: 0, + UID: "TestIndexGetTask", + client: defaultClient, + taskUID: 0, document: []docTest{ {ID: "456", Name: "Le Petit Prince"}, {ID: "1", Name: "Alice In Wonderland"}, @@ -249,13 +249,13 @@ func TestIndex_GetTask(t *testing.T) { task, err := i.AddDocuments(tt.args.document) require.NoError(t, err) - _, err = c.WaitForTask(task) + _, err = c.WaitForTask(task.TaskUID) require.NoError(t, err) - gotResp, err := i.GetTask(task.UID) + gotResp, err := i.GetTask(task.TaskUID) require.NoError(t, err) require.NotNil(t, gotResp) - require.GreaterOrEqual(t, gotResp.UID, tt.args.taskID) + require.GreaterOrEqual(t, gotResp.UID, tt.args.taskUID) require.Equal(t, gotResp.IndexUID, tt.args.UID) require.Equal(t, gotResp.Status, TaskStatusSucceeded) @@ -307,10 +307,10 @@ func TestIndex_GetTasks(t *testing.T) { task, err := i.AddDocuments(tt.args.document) require.NoError(t, err) - _, err = c.WaitForTask(task) + _, err = c.WaitForTask(task.TaskUID) require.NoError(t, err) - gotResp, err := i.GetTasks() + gotResp, err := i.GetTasks(nil) require.NoError(t, err) require.NotNil(t, (*gotResp).Results[0].Status) require.NotZero(t, (*gotResp).Results[0].UID) @@ -325,7 +325,6 @@ func TestIndex_WaitForTask(t *testing.T) { client *Client interval time.Duration timeout time.Duration - taskID *Task document []docTest } tests := []struct { @@ -340,9 +339,6 @@ func TestIndex_WaitForTask(t *testing.T) { client: defaultClient, interval: time.Millisecond * 50, timeout: time.Second * 5, - taskID: &Task{ - UID: 0, - }, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, {ID: "456", Name: "Le Petit Prince"}, @@ -358,9 +354,6 @@ func TestIndex_WaitForTask(t *testing.T) { client: customClient, interval: time.Millisecond * 50, timeout: time.Second * 5, - taskID: &Task{ - UID: 0, - }, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, {ID: "456", Name: "Le Petit Prince"}, @@ -376,9 +369,6 @@ func TestIndex_WaitForTask(t *testing.T) { client: defaultClient, interval: time.Millisecond * 10, timeout: time.Second * 5, - taskID: &Task{ - UID: 1, - }, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, {ID: "456", Name: "Le Petit Prince"}, @@ -394,9 +384,6 @@ func TestIndex_WaitForTask(t *testing.T) { client: defaultClient, interval: time.Millisecond * 50, timeout: time.Millisecond * 10, - taskID: &Task{ - UID: 1, - }, document: []docTest{ {ID: "123", Name: "Pride and Prejudice"}, {ID: "456", Name: "Le Petit Prince"}, @@ -418,7 +405,7 @@ func TestIndex_WaitForTask(t *testing.T) { ctx, cancelFunc := context.WithTimeout(context.Background(), tt.args.timeout) defer cancelFunc() - gotTask, err := i.WaitForTask(task, WaitParams{Context: ctx, Interval: tt.args.interval}) + gotTask, err := i.WaitForTask(task.TaskUID, WaitParams{Context: ctx, Interval: tt.args.interval}) if tt.args.timeout < tt.args.interval { require.Error(t, err) } else { @@ -576,7 +563,7 @@ func TestIndex_UpdateIndex(t *testing.T) { gotResp, err := i.UpdateIndex(tt.args.primaryKey) require.NoError(t, err) - _, err = c.WaitForTask(gotResp) + _, err = c.WaitForTask(gotResp.TaskUID) require.NoError(t, err) require.NoError(t, err) diff --git a/main_test.go b/main_test.go index 1cd615b2..c583fa0c 100644 --- a/main_test.go +++ b/main_test.go @@ -31,7 +31,7 @@ func deleteAllIndexes(client ClientInterface) (ok bool, err error) { for _, index := range list { task, _ := client.DeleteIndex(index.UID) - _, err := client.WaitForTask(task) + _, err := client.WaitForTask(task.TaskUID) if err != nil { return false, err } @@ -66,13 +66,13 @@ func cleanup(c ClientInterface) func() { } func testWaitForTask(t *testing.T, i *Index, u *Task) { - _, err := i.WaitForTask(u) + _, err := i.WaitForTask(u.TaskUID) require.NoError(t, err) } func testWaitForBatchTask(t *testing.T, i *Index, u []Task) { for _, id := range u { - _, err := i.WaitForTask(&id) + _, err := i.WaitForTask(id.TaskUID) require.NoError(t, err) } } @@ -100,7 +100,7 @@ func SetUpEmptyIndex(index *IndexConfig) (resp *Index, err error) { fmt.Println(err) return nil, err } - finalTask, _ := client.WaitForTask(task) + finalTask, _ := client.WaitForTask(task.TaskUID) if finalTask.Status != "succeeded" { os.Exit(1) } @@ -127,7 +127,7 @@ func SetUpBasicIndex(indexUID string) { fmt.Println(err) os.Exit(1) } - finalTask, _ := index.WaitForTask(task) + finalTask, _ := index.WaitForTask(task.TaskUID) if finalTask.Status != "succeeded" { os.Exit(1) } @@ -154,7 +154,7 @@ func SetUpIndexWithNestedFields(indexUID string) { fmt.Println(err) os.Exit(1) } - finalTask, _ := index.WaitForTask(task) + finalTask, _ := index.WaitForTask(task.TaskUID) if finalTask.Status != "succeeded" { os.Exit(1) } @@ -194,7 +194,7 @@ func SetUpIndexForFaceting() { fmt.Println(err) os.Exit(1) } - finalTask, _ := index.WaitForTask(task) + finalTask, _ := index.WaitForTask(task.TaskUID) if finalTask.Status != "succeeded" { os.Exit(1) } diff --git a/types.go b/types.go index 58149887..c0121b5e 100644 --- a/types.go +++ b/types.go @@ -95,7 +95,8 @@ const ( // Documentation: https://docs.meilisearch.com/learn/advanced/asynchronous_operations.html type Task struct { Status TaskStatus `json:"status"` - UID int64 `json:"uid"` + UID int64 `json:"uid,omitempty"` + TaskUID int64 `json:"taskUid,omitempty"` IndexUID string `json:"indexUid"` Type string `json:"type"` Error meilisearchApiError `json:"error,omitempty"` @@ -106,6 +107,15 @@ type Task struct { Details Details `json:"details,omitempty"` } +// TasksQuery is the request body for list documents method +type TasksQuery struct { + Limit int64 `json:"limit,omitempty"` + From int64 `json:"from,omitempty"` + IndexUID []string `json:"indexUid,omitempty"` + Status string `json:"status,omitempty"` + Type string `json:"type,omitempty"` +} + type Details struct { ReceivedDocuments int `json:"receivedDocuments,omitempty"` IndexedDocuments int `json:"indexedDocuments,omitempty"` @@ -121,8 +131,12 @@ type Details struct { SortableAttributes []string `json:"sortableAttributes,omitempty"` } -type ResultTask struct { +// Return of multiple tasks is wrap in a TaskResult +type TaskResult struct { Results []Task `json:"results"` + Limit int64 `json:"limit"` + From int64 `json:"from"` + Next int64 `json:"next"` } // Keys allow the user to connect to the Meilisearch instance