Skip to content

Commit

Permalink
Modify UIDs for UIDS
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Dec 6, 2022
1 parent 029e503 commit 0d57189
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
9 changes: 4 additions & 5 deletions client.go
Expand Up @@ -285,7 +285,6 @@ func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) {
return resp, nil
}


// WaitForTask waits for a task to be processed
//
// The function will check by regular interval provided in parameter interval
Expand Down Expand Up @@ -400,11 +399,11 @@ func encodeTasksQuery(param *TasksQuery, req *internalRequest) {
if len(param.Types) != 0 {
req.withQueryParams["types"] = strings.Join(param.Types, ",")
}
if len(param.IndexUIDs) != 0 {
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDs, ",")
if len(param.IndexUIDS) != 0 {
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDS, ",")
}
if len(param.UIDs) != 0 {
req.withQueryParams["uids"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.UIDs)), ","), "[]")
if len(param.UIDS) != 0 {
req.withQueryParams["uids"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.UIDS)), ","), "[]")
}
if len(param.CanceledBy) != 0 {
req.withQueryParams["canceledBy"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.CanceledBy)), ","), "[]")
Expand Down
36 changes: 18 additions & 18 deletions client_test.go
Expand Up @@ -749,7 +749,7 @@ func TestClient_GetTasks(t *testing.T) {
query: &TasksQuery{
Limit: 1,
From: 0,
IndexUIDs: []string{"indexUID"},
IndexUIDS: []string{"indexUID"},
},
},
},
Expand All @@ -763,7 +763,7 @@ func TestClient_GetTasks(t *testing.T) {
},
query: &TasksQuery{
Limit: 1,
UIDs: []int64{1},
UIDS: []int64{1},
},
},
},
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func TestClient_ConnectionCloseByServer(t *testing.T) {

func TestClient_GenerateTenantToken(t *testing.T) {
type args struct {
IndexUIDs string
IndexUIDS string
client *Client
APIKeyUID string
searchRules map[string]interface{}
Expand All @@ -1037,7 +1037,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestDefaultGenerateTenantToken",
args: args{
IndexUIDs: "TestDefaultGenerateTenantToken",
IndexUIDS: "TestDefaultGenerateTenantToken",
client: privateClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1052,7 +1052,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithApiKey",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithApiKey",
IndexUIDS: "TestGenerateTenantTokenWithApiKey",
client: defaultClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1069,7 +1069,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithOnlyExpiresAt",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithOnlyExpiresAt",
IndexUIDS: "TestGenerateTenantTokenWithOnlyExpiresAt",
client: privateClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1086,7 +1086,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithApiKeyAndExpiresAt",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithApiKeyAndExpiresAt",
IndexUIDS: "TestGenerateTenantTokenWithApiKeyAndExpiresAt",
client: defaultClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1104,7 +1104,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithFilters",
args: args{
IndexUIDs: "indexUID",
IndexUIDS: "indexUID",
client: privateClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1123,7 +1123,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithFilterOnOneINdex",
args: args{
IndexUIDs: "indexUID",
IndexUIDS: "indexUID",
client: privateClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1142,7 +1142,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithoutSearchRules",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithoutSearchRules",
IndexUIDS: "TestGenerateTenantTokenWithoutSearchRules",
client: privateClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: nil,
Expand All @@ -1155,7 +1155,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithoutApiKey",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithoutApiKey",
IndexUIDS: "TestGenerateTenantTokenWithoutApiKey",
client: NewClient(ClientConfig{
Host: getenv("MEILISEARCH_URL", "http://localhost:7700"),
APIKey: "",
Expand All @@ -1173,7 +1173,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithBadExpiresAt",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithBadExpiresAt",
IndexUIDS: "TestGenerateTenantTokenWithBadExpiresAt",
client: defaultClient,
APIKeyUID: GetPrivateUIDKey(),
searchRules: map[string]interface{}{
Expand All @@ -1190,7 +1190,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithBadAPIKeyUID",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithBadAPIKeyUID",
IndexUIDS: "TestGenerateTenantTokenWithBadAPIKeyUID",
client: defaultClient,
APIKeyUID: GetPrivateUIDKey() + "1234",
searchRules: map[string]interface{}{
Expand All @@ -1205,7 +1205,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
{
name: "TestGenerateTenantTokenWithEmptyAPIKeyUID",
args: args{
IndexUIDs: "TestGenerateTenantTokenWithEmptyAPIKeyUID",
IndexUIDS: "TestGenerateTenantTokenWithEmptyAPIKeyUID",
client: defaultClient,
APIKeyUID: "",
searchRules: map[string]interface{}{
Expand All @@ -1231,11 +1231,11 @@ func TestClient_GenerateTenantToken(t *testing.T) {
require.NoError(t, err)

if tt.wantFilter {
gotTask, err := c.Index(tt.args.IndexUIDs).UpdateFilterableAttributes(&tt.args.filter)
gotTask, err := c.Index(tt.args.IndexUIDS).UpdateFilterableAttributes(&tt.args.filter)
require.NoError(t, err, "UpdateFilterableAttributes() in TestGenerateTenantToken error should be nil")
testWaitForTask(t, c.Index(tt.args.IndexUIDs), gotTask)
testWaitForTask(t, c.Index(tt.args.IndexUIDS), gotTask)
} else {
_, err := SetUpEmptyIndex(&IndexConfig{Uid: tt.args.IndexUIDs})
_, err := SetUpEmptyIndex(&IndexConfig{Uid: tt.args.IndexUIDS})
require.NoError(t, err, "CreateIndex() in TestGenerateTenantToken error should be nil")
}

Expand All @@ -1244,7 +1244,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
APIKey: token,
})

_, err = client.Index(tt.args.IndexUIDs).Search("", &SearchRequest{})
_, err = client.Index(tt.args.IndexUIDS).Search("", &SearchRequest{})

require.NoError(t, err)
}
Expand Down
6 changes: 3 additions & 3 deletions index.go
Expand Up @@ -189,9 +189,9 @@ func (i Index) GetTasks(param *TasksQuery) (resp *TaskResult, err error) {
if len(param.Types) != 0 {
req.withQueryParams["types"] = strings.Join(param.Types, ",")
}
if len(param.IndexUIDs) != 0 {
param.IndexUIDs = append(param.IndexUIDs, i.UID)
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDs, ",")
if len(param.IndexUIDS) != 0 {
param.IndexUIDS = append(param.IndexUIDS, i.UID)
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDS, ",")
} else {
req.withQueryParams["indexUids"] = i.UID
}
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Expand Up @@ -275,14 +275,14 @@ func TestMain(m *testing.M) {
}

func Test_deleteAllIndexes(t *testing.T) {
indexUIDs := []string{
indexUIDS := []string{
"Test_deleteAllIndexes",
"Test_deleteAllIndexes2",
"Test_deleteAllIndexes3",
}
_, _ = deleteAllIndexes(defaultClient)

for _, uid := range indexUIDs {
for _, uid := range indexUIDS {
task, err := defaultClient.CreateIndex(&IndexConfig{
Uid: uid,
})
Expand All @@ -297,7 +297,7 @@ func Test_deleteAllIndexes(t *testing.T) {

_, _ = deleteAllIndexes(defaultClient)

for _, uid := range indexUIDs {
for _, uid := range indexUIDS {
resp, err := defaultClient.GetIndex(uid)
if resp != nil {
t.Fatal(resp)
Expand Down
4 changes: 2 additions & 2 deletions types.go
Expand Up @@ -150,10 +150,10 @@ type TaskInfo struct {

// TasksQuery is the request body for list documents method
type TasksQuery struct {
UIDs []int64
UIDS []int64
Limit int64
From int64
IndexUIDs []string
IndexUIDS []string
Statuses []string
Types []string
CanceledBy []int64
Expand Down
40 changes: 20 additions & 20 deletions types_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d57189

Please sign in to comment.