-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
137: Add dumps endpoint support r=eskombro a=claudiunicolaa Implementation for /dumps #82 - [x] Implement dump creation route - [x] Implement get dump status route - [x] Add tests - [x] Add code samples Co-authored-by: Claudiu Nicola <claudiu.nicola@complyadvantage.com>
- Loading branch information
Showing
7 changed files
with
286 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type clientDumps struct { | ||
client *Client | ||
} | ||
|
||
func newClientDumps(client *Client) clientDumps { | ||
return clientDumps{client: client} | ||
} | ||
|
||
func (c clientDumps) Create() (resp *Dump, err error) { | ||
resp = &Dump{} | ||
req := internalRequest{ | ||
endpoint: "/dumps", | ||
method: http.MethodPost, | ||
withRequest: nil, | ||
withResponse: resp, | ||
acceptedStatusCodes: []int{http.StatusAccepted}, | ||
functionName: "Create", | ||
apiName: "Dumps", | ||
} | ||
if err := c.client.executeRequest(req); err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} | ||
|
||
func (c clientDumps) GetStatus(dumpUID string) (resp *Dump, err error) { | ||
resp = &Dump{} | ||
req := internalRequest{ | ||
endpoint: "/dumps/" + dumpUID + "/status", | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: resp, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "GetStatus", | ||
apiName: "Dumps", | ||
} | ||
if err := c.client.executeRequest(req); err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func contains(a []string, x string) bool { | ||
for _, n := range a { | ||
if x == n { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func TestClientDumps_CreateAndGetStatus(t *testing.T) { | ||
resp, err := client.Dumps().Create() | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if resp.Status != "in_progress" { | ||
t.Fatal("response create dump does not have the 'in_progress' status") | ||
} | ||
var dumpUID = resp.UID | ||
resp, err = client.Dumps().GetStatus(dumpUID) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp.UID != dumpUID { | ||
t.Fatal("response get dump status does not have the same UID") | ||
} | ||
|
||
var possibleStatuses = []string{"in_progress", "failed", "done"} | ||
if !contains(possibleStatuses, resp.Status) { | ||
t.Fatalf("response get dump status must be from %q", possibleStatuses) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.