Skip to content

Commit

Permalink
Merge pull request #257 from meilisearch/delete-if-exists
Browse files Browse the repository at this point in the history
Remove `DeleteIndexIfExists` method
  • Loading branch information
alallema authored Jan 24, 2022
2 parents 07704e6 + 1f4eb15 commit 081174d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 124 deletions.
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type ClientInterface interface {
GetAllRawIndexes() (resp []map[string]interface{}, err error)
CreateIndex(config *IndexConfig) (resp *Index, err error)
DeleteIndex(uid string) (bool, error)
DeleteIndexIfExists(uid string) (bool, error)
GetKeys() (resp *Keys, err error)
GetAllStats() (resp *Stats, err error)
CreateDump() (resp *Dump, err error)
Expand Down
19 changes: 0 additions & 19 deletions client_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,3 @@ func (c *Client) DeleteIndex(uid string) (ok bool, err error) {
}
return true, nil
}

func (c *Client) DeleteIndexIfExists(uid string) (ok bool, err error) {
req := internalRequest{
endpoint: "/indexes/" + uid,
method: http.MethodDelete,
withRequest: nil,
withResponse: nil,
acceptedStatusCodes: []int{http.StatusNoContent},
functionName: "DeleteIndex",
}
// err is not nil if status code is not 204 StatusNoContent
if err := c.executeRequest(req); err != nil {
if err.(*Error).MeilisearchApiError.Code != "index_not_found" {
return false, err
}
return false, nil
}
return true, nil
}
104 changes: 0 additions & 104 deletions client_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,110 +264,6 @@ func TestClient_DeleteIndex(t *testing.T) {
}
}

func TestClient_DeleteIndexIfExists(t *testing.T) {
type args struct {
createUid []string
deleteUid []string
}
tests := []struct {
name string
client *Client
args args
wantOk bool
wantErr bool
expectedError []Error
}{
{
name: "TestBasicDeleteIndexIfExists",
client: defaultClient,
args: args{
createUid: []string{"1"},
deleteUid: []string{"1"},
},
wantOk: true,
wantErr: false,
},
{
name: "TestDeleteIndexIfExistsWithCustomClient",
client: customClient,
args: args{
createUid: []string{"1"},
deleteUid: []string{"1"},
},
wantOk: true,
wantErr: false,
},
{
name: "TestMultipleDeleteIndexIfExists",
client: defaultClient,
args: args{
createUid: []string{"2", "3", "4", "5"},
deleteUid: []string{"2", "3", "4", "5"},
},
wantOk: true,
wantErr: false,
},
{
name: "TestNotExistingDeleteIndexIfExists",
client: defaultClient,
args: args{
deleteUid: []string{"1"},
},
wantOk: false,
wantErr: false,
},
{
name: "TestMultipleNotExistingDeleteIndexIfExists",
client: defaultClient,
args: args{
deleteUid: []string{"2", "3", "4", "5"},
},
wantOk: false,
wantErr: false,
},
{
name: "TestDeleteIndexIfExistsTimeout",
client: timeoutClient,
args: args{
deleteUid: []string{"1"},
},
wantOk: false,
wantErr: true,
expectedError: []Error{
{
MeilisearchApiError: meilisearchApiError{},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := tt.client
t.Cleanup(cleanup(c))

for _, uid := range tt.args.createUid {
_, err := c.CreateIndex(&IndexConfig{Uid: uid})
require.NoError(t, err, "CreateIndex() in TestDeleteIndexIfExists error should be nil")
}
for k := range tt.args.deleteUid {
gotOk, err := c.DeleteIndexIfExists(tt.args.deleteUid[k])
if tt.wantErr {
require.Error(t, err)
require.Equal(t, tt.expectedError[k].MeilisearchApiError.Code,
err.(*Error).MeilisearchApiError.Code)
} else {
require.NoError(t, err)
if tt.wantOk {
require.True(t, gotOk)
} else {
require.False(t, gotOk)
}
}
}
})
}
}

func TestClient_GetAllIndexes(t *testing.T) {
type args struct {
uid []string
Expand Down

0 comments on commit 081174d

Please sign in to comment.