From a8fa4c68c584acc21dec49ad76c48f19e95b04d9 Mon Sep 17 00:00:00 2001 From: Wilson Radadia Date: Fri, 24 Jan 2025 17:28:40 +0530 Subject: [PATCH] Update UT coverage for snapshot.go --- snapshots_test.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/snapshots_test.go b/snapshots_test.go index c81a69a8..263a1620 100644 --- a/snapshots_test.go +++ b/snapshots_test.go @@ -425,3 +425,61 @@ func TestCreateSnapshotWithPath(t *testing.T) { _, err := client.CreateSnapshotWithPath(context.Background(), path, snapshotName) assert.Nil(t, err) } + +func TestGetSnapshotFolderSize(t *testing.T) { + client := &Client{ + API: new(mocks.Client), + } + + ctx := context.Background() + var isiPath, accessZone, name string + + // Mock GetSnapshot to return a snapshot from GetIsiSnapshotsResp + client.API.(*mocks.Client).On("Get", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(nil).Run(func(args mock.Arguments) { + resp := args.Get(5).(**apiv1.GetIsiSnapshotsResp) + *resp = &apiv1.GetIsiSnapshotsResp{ + SnapshotList: []*apiv1.IsiSnapshot{ + { + ID: 1, + Name: "test_snapshot", + Path: "/path/to/snapshot", + }, + }, + Total: 1, + Resume: "", + } + }).Once() + + // Mock GetZoneByName to return a zone + client.API.(*mocks.Client).On("Get", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(nil).Run(func(args mock.Arguments) { + resp := args.Get(5).(*apiv1.GetIsiZonesResp) + *resp = apiv1.GetIsiZonesResp{ + Zones: []*apiv1.IsiZone{ + { + Name: "zone1", + Path: "/ifs/data", + }, + }, + } + }).Once() + + client.API.(*mocks.Client).On("Get", anyArgs...).Return(nil).Run(func(args mock.Arguments) { + resp := args.Get(5).(**apiv1.GetIsiVolumeSizeResp) + *resp = &apiv1.GetIsiVolumeSizeResp{ + AttributeMap: []struct { + Name string `json:"name"` + Size int64 `json:"size"` + }{ + {Name: "test", Size: 12345}, + }, + } + }).Once() + + // Call GetSnapshotFolderSize + _, err := client.GetSnapshotFolderSize(ctx, isiPath, name, accessZone) + + // Assert that no error occurred + assert.Nil(t, err) +}