Skip to content

Commit 8fd9975

Browse files
author
Rizal Widyarta Gowandy
committed
feat(command): add new client method for get_all_raw_indexes
Issue: #201 Extra: run gofmt the whole project
1 parent 4dc2cc3 commit 8fd9975

File tree

6 files changed

+139
-24
lines changed

6 files changed

+139
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
meilisearch-go.iml
3+
vendor

client_index.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ func (c *Client) GetAllIndexes() (resp []*Index, err error) {
4646
return resp, nil
4747
}
4848

49+
func (c *Client) GetAllRawIndexes() (resp []map[string]interface{}, err error) {
50+
resp = []map[string]interface{}{}
51+
req := internalRequest{
52+
endpoint: "/indexes",
53+
method: http.MethodGet,
54+
withRequest: nil,
55+
withResponse: &resp,
56+
acceptedStatusCodes: []int{http.StatusOK},
57+
functionName: "GetAllRawIndexes",
58+
}
59+
if err := c.executeRequest(req); err != nil {
60+
return nil, err
61+
}
62+
return resp, nil
63+
}
64+
4965
func (c *Client) GetOrCreateIndex(config *IndexConfig) (resp *Index, err error) {
5066
resp, err = c.GetIndex(config.Uid)
5167
if err == nil {

client_index_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,104 @@ func TestClient_GetAllIndexes(t *testing.T) {
463463
}
464464
}
465465

466+
func TestClient_GetAllRawIndexes(t *testing.T) {
467+
type args struct {
468+
uid []string
469+
}
470+
tests := []struct {
471+
name string
472+
client *Client
473+
args args
474+
wantResp []map[string]interface{}
475+
}{
476+
{
477+
name: "TestGelAllIndexesOnNoIndexes",
478+
client: defaultClient,
479+
args: args{
480+
uid: []string{},
481+
},
482+
wantResp: []map[string]interface{}{},
483+
},
484+
{
485+
name: "TestBasicGelAllIndexes",
486+
client: defaultClient,
487+
args: args{
488+
uid: []string{"1"},
489+
},
490+
wantResp: []map[string]interface{}{
491+
{
492+
"uid": "1",
493+
},
494+
},
495+
},
496+
{
497+
name: "TestGelAllIndexesWithCustomClient",
498+
client: customClient,
499+
args: args{
500+
uid: []string{"1"},
501+
},
502+
wantResp: []map[string]interface{}{
503+
{
504+
"uid": "1",
505+
},
506+
},
507+
},
508+
{
509+
name: "TestGelAllIndexesOnMultipleIndex",
510+
client: defaultClient,
511+
args: args{
512+
uid: []string{"1", "2", "3"},
513+
},
514+
wantResp: []map[string]interface{}{
515+
{
516+
"uid": "1",
517+
},
518+
{
519+
"uid": "2",
520+
},
521+
{
522+
"uid": "3",
523+
},
524+
},
525+
},
526+
{
527+
name: "TestGelAllIndexesOnMultipleIndexWithPrimaryKey",
528+
client: defaultClient,
529+
args: args{
530+
uid: []string{"1", "2", "3"},
531+
},
532+
wantResp: []map[string]interface{}{
533+
{
534+
"uid": "1",
535+
"primaryKey": "PrimaryKey1",
536+
},
537+
{
538+
"uid": "2",
539+
"primaryKey": "PrimaryKey2",
540+
},
541+
{
542+
"uid": "3",
543+
"primaryKey": "PrimaryKey3",
544+
},
545+
},
546+
},
547+
}
548+
for _, tt := range tests {
549+
t.Run(tt.name, func(t *testing.T) {
550+
c := tt.client
551+
t.Cleanup(cleanup(c))
552+
553+
for _, uid := range tt.args.uid {
554+
_, err := c.CreateIndex(&IndexConfig{Uid: uid})
555+
require.NoError(t, err, "CreateIndex() in TestGetAllIndexes error should be nil")
556+
}
557+
gotResp, err := c.GetAllRawIndexes()
558+
require.NoError(t, err)
559+
require.Equal(t, len(tt.wantResp), len(gotResp))
560+
})
561+
}
562+
}
563+
466564
func TestClient_GetIndex(t *testing.T) {
467565
type args struct {
468566
config IndexConfig

index_search_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ func TestIndex_SearchWithFilters(t *testing.T) {
470470
},
471471
request: SearchRequest{
472472
Filter: [][]string{
473-
[]string{"year < 1850"},
474-
[]string{"tag = romance"},
473+
{"year < 1850"},
474+
{"tag = romance"},
475475
},
476476
},
477477
},

index_settings_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func TestIndex_GetSettings(t *testing.T) {
221221
client: defaultClient,
222222
},
223223
wantResp: &Settings{
224-
RankingRules: defaultRankingRules,
224+
RankingRules: defaultRankingRules,
225225
DistinctAttribute: (*string)(nil),
226226
SearchableAttributes: []string{"*"},
227227
DisplayedAttributes: []string{"*"},
@@ -238,7 +238,7 @@ func TestIndex_GetSettings(t *testing.T) {
238238
client: customClient,
239239
},
240240
wantResp: &Settings{
241-
RankingRules: defaultRankingRules,
241+
RankingRules: defaultRankingRules,
242242
DistinctAttribute: (*string)(nil),
243243
SearchableAttributes: []string{"*"},
244244
DisplayedAttributes: []string{"*"},
@@ -656,7 +656,7 @@ func TestIndex_ResetSettings(t *testing.T) {
656656
UpdateID: 1,
657657
},
658658
wantResp: &Settings{
659-
RankingRules: defaultRankingRules,
659+
RankingRules: defaultRankingRules,
660660
DistinctAttribute: (*string)(nil),
661661
SearchableAttributes: []string{"*"},
662662
DisplayedAttributes: []string{"*"},
@@ -676,7 +676,7 @@ func TestIndex_ResetSettings(t *testing.T) {
676676
UpdateID: 1,
677677
},
678678
wantResp: &Settings{
679-
RankingRules: defaultRankingRules,
679+
RankingRules: defaultRankingRules,
680680
DistinctAttribute: (*string)(nil),
681681
SearchableAttributes: []string{"*"},
682682
DisplayedAttributes: []string{"*"},
@@ -1217,7 +1217,7 @@ func TestIndex_UpdateSettings(t *testing.T) {
12171217
FilterableAttributes: []string{
12181218
"title",
12191219
},
1220-
SortableAttributes: []string{
1220+
SortableAttributes: []string{
12211221
"title",
12221222
},
12231223
},
@@ -1226,7 +1226,7 @@ func TestIndex_UpdateSettings(t *testing.T) {
12261226
UpdateID: 1,
12271227
},
12281228
wantResp: &Settings{
1229-
RankingRules: defaultRankingRules,
1229+
RankingRules: defaultRankingRules,
12301230
DistinctAttribute: (*string)(nil),
12311231
SearchableAttributes: []string{"*"},
12321232
DisplayedAttributes: []string{"*"},
@@ -1261,7 +1261,7 @@ func TestIndex_UpdateSettings(t *testing.T) {
12611261
FilterableAttributes: []string{
12621262
"title",
12631263
},
1264-
SortableAttributes: []string{
1264+
SortableAttributes: []string{
12651265
"title",
12661266
},
12671267
},
@@ -1270,7 +1270,7 @@ func TestIndex_UpdateSettings(t *testing.T) {
12701270
UpdateID: 1,
12711271
},
12721272
wantResp: &Settings{
1273-
RankingRules: defaultRankingRules,
1273+
RankingRules: defaultRankingRules,
12741274
DistinctAttribute: (*string)(nil),
12751275
SearchableAttributes: []string{"*"},
12761276
DisplayedAttributes: []string{"*"},
@@ -1370,7 +1370,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
13701370
UpdateID: 1,
13711371
},
13721372
wantResp: &Settings{
1373-
RankingRules: defaultRankingRules,
1373+
RankingRules: defaultRankingRules,
13741374
DistinctAttribute: (*string)(nil),
13751375
SearchableAttributes: []string{"*"},
13761376
DisplayedAttributes: []string{"*"},
@@ -1431,7 +1431,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
14311431
UpdateID: 1,
14321432
},
14331433
wantResp: &Settings{
1434-
RankingRules: defaultRankingRules,
1434+
RankingRules: defaultRankingRules,
14351435
DistinctAttribute: (*string)(nil),
14361436
SearchableAttributes: []string{"*"},
14371437
DisplayedAttributes: []string{"*"},
@@ -1492,7 +1492,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
14921492
UpdateID: 1,
14931493
},
14941494
wantResp: &Settings{
1495-
RankingRules: defaultRankingRules,
1495+
RankingRules: defaultRankingRules,
14961496
DistinctAttribute: (*string)(nil),
14971497
SearchableAttributes: []string{"*"},
14981498
DisplayedAttributes: []string{"*"},
@@ -1553,7 +1553,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
15531553
UpdateID: 1,
15541554
},
15551555
wantResp: &Settings{
1556-
RankingRules: defaultRankingRules,
1556+
RankingRules: defaultRankingRules,
15571557
DistinctAttribute: (*string)(nil),
15581558
SearchableAttributes: []string{"*"},
15591559
DisplayedAttributes: []string{"*"},
@@ -1614,7 +1614,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
16141614
UpdateID: 1,
16151615
},
16161616
wantResp: &Settings{
1617-
RankingRules: defaultRankingRules,
1617+
RankingRules: defaultRankingRules,
16181618
DistinctAttribute: (*string)(nil),
16191619
SearchableAttributes: []string{"*"},
16201620
DisplayedAttributes: []string{"*"},
@@ -1649,7 +1649,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
16491649
FilterableAttributes: []string{
16501650
"title",
16511651
},
1652-
SortableAttributes: []string{},
1652+
SortableAttributes: []string{},
16531653
},
16541654
secondRequest: Settings{
16551655
FilterableAttributes: []string{
@@ -1668,14 +1668,14 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
16681668
FilterableAttributes: []string{
16691669
"title",
16701670
},
1671-
SortableAttributes: []string{},
1671+
SortableAttributes: []string{},
16721672
},
16731673
},
16741674
wantUpdate: &AsyncUpdateID{
16751675
UpdateID: 1,
16761676
},
16771677
wantResp: &Settings{
1678-
RankingRules: defaultRankingRules,
1678+
RankingRules: defaultRankingRules,
16791679
DistinctAttribute: (*string)(nil),
16801680
SearchableAttributes: []string{"*"},
16811681
DisplayedAttributes: []string{"*"},
@@ -1708,7 +1708,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
17081708
StopWords: []string{},
17091709
Synonyms: map[string][]string(nil),
17101710
FilterableAttributes: []string{},
1711-
SortableAttributes: []string{
1711+
SortableAttributes: []string{
17121712
"title",
17131713
},
17141714
},
@@ -1727,7 +1727,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
17271727
StopWords: []string{},
17281728
Synonyms: map[string][]string(nil),
17291729
FilterableAttributes: []string{},
1730-
SortableAttributes: []string{
1730+
SortableAttributes: []string{
17311731
"title",
17321732
},
17331733
},
@@ -1736,7 +1736,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) {
17361736
UpdateID: 1,
17371737
},
17381738
wantResp: &Settings{
1739-
RankingRules: defaultRankingRules,
1739+
RankingRules: defaultRankingRules,
17401740
DistinctAttribute: (*string)(nil),
17411741
SearchableAttributes: []string{"*"},
17421742
DisplayedAttributes: []string{"*"},
@@ -1858,7 +1858,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) {
18581858
UID: "indexUID",
18591859
client: defaultClient,
18601860
request: map[string][]string{
1861-
"wolverine": []string{"logan", "xmen"},
1861+
"wolverine": {"logan", "xmen"},
18621862
},
18631863
},
18641864
wantUpdate: &AsyncUpdateID{
@@ -1871,7 +1871,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) {
18711871
UID: "indexUID",
18721872
client: customClient,
18731873
request: map[string][]string{
1874-
"wolverine": []string{"logan", "xmen"},
1874+
"wolverine": {"logan", "xmen"},
18751875
},
18761876
},
18771877
wantUpdate: &AsyncUpdateID{

types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Settings struct {
3434
StopWords []string `json:"stopWords,omitempty"`
3535
Synonyms map[string][]string `json:"synonyms,omitempty"`
3636
FilterableAttributes []string `json:"filterableAttributes,omitempty"`
37-
SortableAttributes []string `json:"sortableAttributes,omitempty"`
37+
SortableAttributes []string `json:"sortableAttributes,omitempty"`
3838
}
3939

4040
// Version is the type that represents the versions in MeiliSearch

0 commit comments

Comments
 (0)