Skip to content

Commit

Permalink
Merge pull request #255 from meilisearch/get-or-create
Browse files Browse the repository at this point in the history
Remove `GetOrCreateIndex` method
  • Loading branch information
alallema authored Jan 24, 2022
2 parents 95dda12 + c1fdb5e commit 67d29de
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 76 deletions.
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type ClientInterface interface {
GetAllIndexes() (resp []*Index, err error)
GetAllRawIndexes() (resp []map[string]interface{}, err error)
CreateIndex(config *IndexConfig) (resp *Index, err error)
GetOrCreateIndex(config *IndexConfig) (resp *Index, err error)
DeleteIndex(uid string) (bool, error)
DeleteIndexIfExists(uid string) (bool, error)
GetKeys() (resp *Keys, err error)
Expand Down
8 changes: 0 additions & 8 deletions client_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ func (c *Client) GetAllRawIndexes() (resp []map[string]interface{}, err error) {
return resp, nil
}

func (c *Client) GetOrCreateIndex(config *IndexConfig) (resp *Index, err error) {
resp, err = c.GetIndex(config.Uid)
if err == nil {
return resp, err
}
return c.CreateIndex(config)
}

func (c *Client) DeleteIndex(uid string) (ok bool, err error) {
req := internalRequest{
endpoint: "/indexes/" + uid,
Expand Down
67 changes: 0 additions & 67 deletions client_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,73 +766,6 @@ func TestClient_GetRawIndex(t *testing.T) {
}
}

func TestClient_GetOrCreateIndex(t *testing.T) {
type args struct {
config IndexConfig
}
tests := []struct {
name string
client *Client
args args
wantResp *Index
}{
{
name: "TestBasicGetOrCreateIndex",
client: defaultClient,
args: args{
config: IndexConfig{
Uid: "TestBasicGetOrCreateIndex",
},
},
wantResp: &Index{
UID: "TestBasicGetOrCreateIndex",
},
},
{
name: "TestGetOrCreateIndexWithCustomClient",
client: customClient,
args: args{
config: IndexConfig{
Uid: "TestBasicGetOrCreateIndex",
},
},
wantResp: &Index{
UID: "TestBasicGetOrCreateIndex",
},
},
{
name: "TestGetOrCreateIndexWithPrimaryKey",
client: defaultClient,
args: args{
config: IndexConfig{
Uid: "TestGetOrCreateIndexWithPrimaryKey",
PrimaryKey: "PrimaryKey",
},
},
wantResp: &Index{
UID: "TestGetOrCreateIndexWithPrimaryKey",
PrimaryKey: "PrimaryKey",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := tt.client
t.Cleanup(cleanup(c))

gotResp, err := c.GetOrCreateIndex(&tt.args.config)
require.NoError(t, err)
if assert.NotNil(t, gotResp) {
require.Equal(t, tt.wantResp.UID, gotResp.UID)
require.Equal(t, tt.wantResp.PrimaryKey, gotResp.PrimaryKey)
// Make sure that timestamps are also retrieved
require.NotZero(t, gotResp.CreatedAt)
require.NotZero(t, gotResp.UpdatedAt)
}
})
}
}

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

0 comments on commit 67d29de

Please sign in to comment.