From f25b25a5d298d1784cbac67634e033038d4d8089 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Fri, 10 Jan 2025 06:18:22 -0500 Subject: [PATCH 1/2] added get filesystem by filter --- client.go | 1 + fs.go | 27 +++++++++++++++++++++++++++ fs_test.go | 12 ++++++++++++ 3 files changed, 40 insertions(+) diff --git a/client.go b/client.go index 4a59746..effe356 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/fs.go b/fs.go index 9857dc5..6003db2 100644 --- a/fs.go +++ b/fs.go @@ -324,3 +324,30 @@ 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 +} \ No newline at end of file diff --git a/fs_test.go b/fs_test.go index 3e5a2bb..2934184 100644 --- a/fs_test.go +++ b/fs_test.go @@ -257,3 +257,15 @@ 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) +} \ No newline at end of file From 426c7c96a01883fb15aa241319296aefbff52b15 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Fri, 10 Jan 2025 06:24:25 -0500 Subject: [PATCH 2/2] fix vet and fmt --- fs.go | 3 +-- fs_test.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs.go b/fs.go index 6003db2..5bf9f8a 100644 --- a/fs.go +++ b/fs.go @@ -325,7 +325,6 @@ func (c *ClientIMPL) CloneFS(ctx context.Context, 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) { @@ -350,4 +349,4 @@ func (c *ClientIMPL) GetFsByFilter(ctx context.Context, filter map[string]string return meta, err }) return result, err -} \ No newline at end of file +} diff --git a/fs_test.go b/fs_test.go index 2934184..9fcd364 100644 --- a/fs_test.go +++ b/fs_test.go @@ -258,7 +258,6 @@ func TestClientIMPL_CreateFsFromSnapshot(t *testing.T) { assert.Equal(t, id, resp.ID) } - func TestClientIMPL_GetFsByFilter(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() @@ -268,4 +267,4 @@ func TestClientIMPL_GetFsByFilter(t *testing.T) { resp, err := C.GetFsByFilter(context.Background(), nil) assert.Nil(t, err) assert.Equal(t, fsID, resp[0].ID) -} \ No newline at end of file +}