Skip to content

Commit

Permalink
added get filesystem by filter (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishnan-Priyanshu authored Jan 17, 2025
1 parent 507558f commit a670c95
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type Client interface {
GetFsSnapshots(ctx context.Context) ([]FileSystem, error)
GetFsSnapshot(ctx context.Context, snapID string) (FileSystem, error)
CreateFsFromSnapshot(ctx context.Context, createParams *FsClone, snapID string) (CreateResponse, error)
GetFsByFilter(ctx context.Context, filter map[string]string) ([]FileSystem, error)
CloneVolume(ctx context.Context, createParams *VolumeClone, volID string) (CreateResponse, error)
ModifyVolume(ctx context.Context, modifyParams *VolumeModify, volID string) (EmptyResponse, error)
ModifyFS(ctx context.Context, modifyParams *FSModify, volID string) (EmptyResponse, error)
Expand Down
26 changes: 26 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,29 @@ func (c *ClientIMPL) CloneFS(ctx context.Context,
&resp)
return resp, WrapErr(err)
}

func (c *ClientIMPL) GetFsByFilter(ctx context.Context, filter map[string]string) ([]FileSystem, error) {
var result []FileSystem
err := c.readPaginatedData(func(offset int) (api.RespMeta, error) {
var page []FileSystem
qp := getFSDefaultQueryParams(c)
for k, v := range filter {
qp.RawArg(k, v)
}
qp.Offset(offset).Limit(paginationDefaultPageSize)
meta, err := c.APIClient().Query(
ctx,
RequestConfig{
Method: "GET",
Endpoint: fsURL,
QueryParams: qp,
},
&page)
err = WrapErr(err)
if err == nil {
result = append(result, page...)
}
return meta, err
})
return result, err
}
11 changes: 11 additions & 0 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,14 @@ func TestClientIMPL_CreateFsFromSnapshot(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, id, resp.ID)
}

func TestClientIMPL_GetFsByFilter(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
respData := fmt.Sprintf(`[{"id": "%s"}]`, fsID)
httpmock.RegisterResponder("GET", fsMockURL,
httpmock.NewStringResponder(200, respData))
resp, err := C.GetFsByFilter(context.Background(), nil)
assert.Nil(t, err)
assert.Equal(t, fsID, resp[0].ID)
}

0 comments on commit a670c95

Please sign in to comment.