Skip to content

Commit

Permalink
Merge pull request #109 from dell/Adding-UT
Browse files Browse the repository at this point in the history
improved coverage for host, host group, volume, volume group and snapshot rule
  • Loading branch information
Sakshi-dell authored Jul 10, 2023
2 parents bc046ba + adfe6c7 commit e0f94c9
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 5 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions host_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 15 additions & 2 deletions host_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,9 +21,10 @@ package gopowerstore
import (
"context"
"fmt"
"testing"

"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"testing"
)

const (
Expand Down Expand Up @@ -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()
Expand Down
44 changes: 44 additions & 0 deletions mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 21 additions & 1 deletion snapshot_rule_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Expand Down
48 changes: 47 additions & 1 deletion volume_group_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
47 changes: 46 additions & 1 deletion volume_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e0f94c9

Please sign in to comment.