Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added get filesystem by filter #168

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading