diff --git a/client.go b/client.go index 9a0a862..b96c409 100644 --- a/client.go +++ b/client.go @@ -51,6 +51,7 @@ type Client interface { DeleteVolume(ctx context.Context, deleteParams *VolumeDelete, id string) (EmptyResponse, error) GetSnapshotRules(ctx context.Context) ([]SnapshotRule, error) GetSnapshotRule(ctx context.Context, id string) (SnapshotRule, error) + GetSnapshotRuleByName(ctx context.Context, name string) (SnapshotRule, error) CreateSnapshotRule(ctx context.Context, createParams *SnapshotRuleCreate) (CreateResponse, error) ModifySnapshotRule(ctx context.Context, modifyParams *SnapshotRuleCreate, id string) (resp EmptyResponse, err error) DeleteSnapshotRule(ctx context.Context, deleteParams *SnapshotRuleDelete, id string) (EmptyResponse, error) @@ -179,6 +180,7 @@ type Client interface { ModifyStorageContainer(ctx context.Context, modifyParams *StorageContainer, id string) (EmptyResponse, error) CreateHostGroup(ctx context.Context, createParams *HostGroupCreate) (CreateResponse, error) GetHostGroup(ctx context.Context, id string) (HostGroup, error) + GetHostGroups(ctx context.Context) ([]HostGroup, error) GetHostGroupByName(ctx context.Context, name string) (HostGroup, error) DeleteHostGroup(ctx context.Context, id string) (EmptyResponse, error) ModifyHostGroup(ctx context.Context, modifyParams *HostGroupModify, id string) (EmptyResponse, error) diff --git a/host_group_test.go b/host_group_test.go index 3def66d..1c3e064 100644 --- a/host_group_test.go +++ b/host_group_test.go @@ -87,6 +87,18 @@ func TestClientIMPL_GetHostGroup(t *testing.T) { assert.Equal(t, hostGroupID, hostGroup.ID) } +func TestClientIMPL_GetHostGroups(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`[{"id": "%s"}, {"id": "%s"}]`, hostGroupID, hostGroupID2) + httpmock.RegisterResponder("GET", hostGroupMockURL, + httpmock.NewStringResponder(200, respData)) + hostGroups, err := C.GetHostGroups(context.Background()) + assert.Nil(t, err) + assert.Len(t, hostGroups, 2) + assert.Equal(t, hostGroupID, hostGroups[0].ID) +} + func TestClientIMPL_CreateHostGroup(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/host_test.go b/host_test.go index 1644246..a17e18f 100644 --- a/host_test.go +++ b/host_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2020 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2020-2023 Dell Inc. or its subsidiaries. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,10 @@ package gopowerstore import ( "context" "fmt" + "testing" + "github.com/jarcoal/httpmock" "github.com/stretchr/testify/assert" - "testing" ) const ( @@ -138,6 +139,18 @@ func TestClientIMPL_GetHostVolumeMapping(t *testing.T) { assert.Equal(t, hostID, resp.ID) } +func TestClientIMPL_GetHostVolumeMappingByVolumeID(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`[{"id": "%s"}]`, hostID) + httpmock.RegisterResponder("GET", hostMappingMockURL, + httpmock.NewStringResponder(200, respData)) + resp, err := C.GetHostVolumeMappingByVolumeID(context.Background(), volID) + assert.Nil(t, err) + assert.Len(t, resp, 1) + assert.Equal(t, hostID, resp[0].ID) +} + func TestClientIMPL_AttachVolumeToHost(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/mocks/Client.go b/mocks/Client.go index cf51b92..2768c37 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -1366,6 +1366,29 @@ func (_m *Client) GetHostGroupByName(ctx context.Context, name string) (gopowers return r0, r1 } +// GetHostGroups provides a mock function with given fields: ctx +func (_m *Client) GetHostGroups(ctx context.Context) ([]gopowerstore.HostGroup, error) { + ret := _m.Called(ctx) + + var r0 []gopowerstore.HostGroup + if rf, ok := ret.Get(0).(func(context.Context) []gopowerstore.HostGroup); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]gopowerstore.HostGroup) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetHostVolumeMapping provides a mock function with given fields: ctx, id func (_m *Client) GetHostVolumeMapping(ctx context.Context, id string) (gopowerstore.HostVolumeMapping, error) { ret := _m.Called(ctx, id) @@ -1815,6 +1838,27 @@ func (_m *Client) GetSnapshotRule(ctx context.Context, id string) (gopowerstore. return r0, r1 } +// GetSnapshotRuleByName provides a mock function with given fields: ctx, name +func (_m *Client) GetSnapshotRuleByName(ctx context.Context, name string) (gopowerstore.SnapshotRule, error) { + ret := _m.Called(ctx, name) + + var r0 gopowerstore.SnapshotRule + if rf, ok := ret.Get(0).(func(context.Context, string) gopowerstore.SnapshotRule); ok { + r0 = rf(ctx, name) + } else { + r0 = ret.Get(0).(gopowerstore.SnapshotRule) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetSnapshotRules provides a mock function with given fields: ctx func (_m *Client) GetSnapshotRules(ctx context.Context) ([]gopowerstore.SnapshotRule, error) { ret := _m.Called(ctx) diff --git a/replication_test.go b/replication_test.go index 204ccb0..bf476ab 100644 --- a/replication_test.go +++ b/replication_test.go @@ -34,6 +34,7 @@ const ( var ( protectionPolicyID = "15c03067-c4f2-428b-b637-18b0266979f0" protectionPolicyID2 = "3224ff5a-2e83-4a7f-a0c4-009df20e36db" + replicationRuleID = "6b930711-46bc-4a4b-9d6a-22c77a7838c4" ) func TestClientIMPL_CreateProtectionPolicy(t *testing.T) { @@ -140,6 +141,17 @@ func TestClientIMPL_ModifyProtectionPolicy(t *testing.T) { assert.Equal(t, EmptyResponse(""), resp) } +func TestClientIMPL_GetReplicationRule(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`{"id": "%s"}`, replicationRuleID) + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/%s", replicationRuleMockURL, replicationRuleID), + httpmock.NewStringResponder(200, respData)) + replicationRule, err := C.GetReplicationRule(context.Background(), replicationRuleID) + assert.Nil(t, err) + assert.Equal(t, replicationRuleID, replicationRule.ID) +} + func TestClientIMPL_GetReplicationRuleByName(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/snapshot_rule_test.go b/snapshot_rule_test.go index 0c1aed2..085f5c1 100644 --- a/snapshot_rule_test.go +++ b/snapshot_rule_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2022 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2022-2023 Dell Inc. or its subsidiaries. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,26 @@ func TestClientIMPL_GetSnapshotRule(t *testing.T) { assert.Equal(t, snapshotRuleID, snapshotRule.ID) } +func TestClientIMPL_GetSnapshotRuleByName(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + setResponder := func(respData string) { + httpmock.RegisterResponder("GET", snapshotRuleMockURL, + httpmock.NewStringResponder(200, respData)) + } + respData := fmt.Sprintf(`[{"id": "%s"}]`, snapshotRuleID) + setResponder(respData) + snapshotRule, err := C.GetSnapshotRuleByName(context.Background(), "test") + assert.Nil(t, err) + assert.Equal(t, snapshotRuleID, snapshotRule.ID) + httpmock.Reset() + setResponder("") + _, err = C.GetSnapshotRuleByName(context.Background(), "test") + assert.NotNil(t, err) + apiError := err.(APIError) + assert.True(t, apiError.NotFound()) +} + func TestClientIMPL_GetSnapshotRules(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/volume_group_test.go b/volume_group_test.go index 01f122b..cb58616 100644 --- a/volume_group_test.go +++ b/volume_group_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2021-2022 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2021-2023 Dell Inc. or its subsidiaries. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,9 @@ const ( volumeGroupSnapshotMockURL = APIMockURL + volumeGroupURL + "/test-id" + snapshotURL ) +var volGroupSnapID = "1966782b-60c9-40e2-a1ee-9b2b8f6b98e7" +var volGroupSnapID2 = "34380c29-2203-4490-aeb7-2853b9a85075" + func TestClientIMPL_CreateVolumeGroup(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() @@ -133,6 +136,49 @@ func TestClientIMPL_GetVolumeGroups(t *testing.T) { assert.Equal(t, volID, volumeGroups[0].ID) } +func TestClientIMPL_GetVolumeGroupSnapshot(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`{"id": "%s"}`, volGroupSnapID) + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/%s", volumeGroupMockURL, volGroupSnapID), + httpmock.NewStringResponder(200, respData)) + snapshot, err := C.GetVolumeGroupSnapshot(context.Background(), volGroupSnapID) + assert.Nil(t, err) + assert.Equal(t, volGroupSnapID, snapshot.ID) +} + +func TestClientIMPL_GetVolumeGroupSnapshots(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`[{"id": "%s"}, {"id": "%s"}]`, volGroupSnapID, volGroupSnapID2) + httpmock.RegisterResponder("GET", volumeGroupMockURL, + httpmock.NewStringResponder(200, respData)) + snapshots, err := C.GetVolumeGroupSnapshots(context.Background()) + assert.Nil(t, err) + assert.Len(t, snapshots, 2) + assert.Equal(t, volGroupSnapID, snapshots[0].ID) +} + +func TestClientIMPL_GetVolumeGroupSnapshotByName(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + setResponder := func(respData string) { + httpmock.RegisterResponder("GET", volumeGroupMockURL, + httpmock.NewStringResponder(200, respData)) + } + respData := fmt.Sprintf(`[{"id": "%s"}]`, volGroupSnapID) + setResponder(respData) + snapshot, err := C.GetVolumeGroupSnapshotByName(context.Background(), "test") + assert.Nil(t, err) + assert.Equal(t, volGroupSnapID, snapshot.ID) + httpmock.Reset() + setResponder("") + _, err = C.GetVolumeGroupSnapshotByName(context.Background(), "test") + assert.NotNil(t, err) + apiError := err.(APIError) + assert.True(t, apiError.NotFound()) +} + func TestClientIMPL_ModifyVolumeGroup(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/volume_test.go b/volume_test.go index f4d05d2..34de9c1 100644 --- a/volume_test.go +++ b/volume_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2020-2022 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2020-2023 Dell Inc. or its subsidiaries. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,8 @@ const ( var volID = "6b930711-46bc-4a4b-9d6a-22c77a7838c4" var volID2 = "3765da74-28a7-49db-a693-10cec1de91f8" var appID = "A1" +var volSnapID = "1966782b-60c9-40e2-a1ee-9b2b8f6b98e7" +var volSnapID2 = "34380c29-2203-4490-aeb7-2853b9a85075" func TestClientIMPL_GetVolumes(t *testing.T) { httpmock.Activate() @@ -144,6 +146,49 @@ func TestClientIMPL_GetSnapshotsByVolumeID(t *testing.T) { assert.Equal(t, volID2, resp[0].ID) } +func TestClientIMPL_GetSnapshot(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`{"id": "%s"}`, volSnapID) + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/%s", volumeMockURL, volSnapID), + httpmock.NewStringResponder(200, respData)) + snapshot, err := C.GetSnapshot(context.Background(), volSnapID) + assert.Nil(t, err) + assert.Equal(t, volSnapID, snapshot.ID) +} + +func TestClientIMPL_GetSnapshots(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`[{"id": "%s"}, {"id": "%s"}]`, volSnapID, volSnapID2) + httpmock.RegisterResponder("GET", volumeMockURL, + httpmock.NewStringResponder(200, respData)) + snapshots, err := C.GetSnapshots(context.Background()) + assert.Nil(t, err) + assert.Len(t, snapshots, 2) + assert.Equal(t, volSnapID, snapshots[0].ID) +} + +func TestClientIMPL_GetSnapshotByName(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + setResponder := func(respData string) { + httpmock.RegisterResponder("GET", volumeMockURL, + httpmock.NewStringResponder(200, respData)) + } + respData := fmt.Sprintf(`[{"id": "%s"}]`, volSnapID) + setResponder(respData) + snap, err := C.GetSnapshotByName(context.Background(), "test") + assert.Nil(t, err) + assert.Equal(t, volSnapID, snap.ID) + httpmock.Reset() + setResponder("") + _, err = C.GetSnapshotByName(context.Background(), "test") + assert.NotNil(t, err) + apiError := err.(APIError) + assert.True(t, apiError.NotFound()) +} + func TestClientIMPL_CreateVolume(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset()