Skip to content

Commit

Permalink
Merge pull request #311 from meilisearch/dumps_changes
Browse files Browse the repository at this point in the history
Apply dumps changes
  • Loading branch information
alallema authored Jul 5, 2022
2 parents fabd976 + 50a38c9 commit ecc833f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ faceted_search_walkthrough_filter_1: |-
})
post_dump_1: |-
resp, err := client.CreateDump()
get_dump_status_1: |-
resp, err := client.GetDumpStatus("dump-uid")
phrase_search_1: |-
resp, err := client.Index("movies").Search("\"african american\" horror", &meilisearch.SearchRequest{})
sorting_guide_update_sortable_attributes_1: |-
Expand Down
7 changes: 3 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ type ClientInterface interface {
UpdateKey(identifier string, request *Key) (resp *Key, err error)
DeleteKey(identifier string) (resp bool, err error)
GetAllStats() (resp *Stats, err error)
CreateDump() (resp *Dump, err error)
GetDumpStatus(dumpUID string) (resp *Dump, err error)
CreateDump() (resp *Task, err error)
Version() (*Version, error)
GetVersion() (resp *Version, err error)
Health() (*Health, error)
Expand Down Expand Up @@ -224,8 +223,8 @@ func (c *Client) IsHealthy() bool {
return true
}

func (c *Client) CreateDump() (resp *Dump, err error) {
resp = &Dump{}
func (c *Client) CreateDump() (resp *Task, err error) {
resp = &Task{}
req := internalRequest{
endpoint: "/dumps",
method: http.MethodPost,
Expand Down
39 changes: 5 additions & 34 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ func TestClient_CreateDump(t *testing.T) {
tests := []struct {
name string
client *Client
wantResp *Dump
wantResp *Task
}{
{
name: "TestCreateDump",
client: defaultClient,
wantResp: &Dump{
Status: "in_progress",
wantResp: &Task{
Status: "enqueued",
},
},
}
Expand All @@ -554,44 +554,15 @@ func TestClient_CreateDump(t *testing.T) {

// Waiting for CreateDump() to finished
for {
gotResp, _ := c.GetDumpStatus(gotResp.UID)
if gotResp.Status == "done" {
gotResp, _ := c.GetTask(gotResp.TaskUID)
if gotResp.Status == "succeeded" {
break
}
}
})
}
}

func TestClient_GetDumpStatus(t *testing.T) {
tests := []struct {
name string
client *Client
wantResp []DumpStatus
wantErr bool
}{
{
name: "TestGetDumpStatus",
client: defaultClient,
wantResp: []DumpStatus{DumpStatusInProgress, DumpStatusFailed, DumpStatusDone},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := tt.client

dump, err := c.CreateDump()
require.NoError(t, err, "CreateDump() in TestGetDumpStatus error should be nil")

gotResp, err := c.GetDumpStatus(dump.UID)
require.NoError(t, err)
require.Contains(t, tt.wantResp, gotResp.Status, "GetDumpStatus() got response status %v", gotResp.Status)
require.NotEqual(t, "failed", gotResp.Status, "GetDumpStatus() response status should not be failed")
})
}
}

func TestClient_GetTask(t *testing.T) {
type args struct {
UID string
Expand Down

0 comments on commit ecc833f

Please sign in to comment.