Skip to content

Commit

Permalink
Merge pull request #2345 from Zhupku/mengzezhu/ut
Browse files Browse the repository at this point in the history
test: add UT for azurefile_dataplane_client.go
  • Loading branch information
andyzhangx authored Jan 17, 2025
2 parents 7251aeb + 7cfa3d0 commit a277f7a
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions pkg/azurefile/azurefile_dataplane_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,82 @@ func TestNewAzureFileClient(t *testing.T) {
}
}
}

func TestDeleteFileShare(t *testing.T) {
testCases := []struct {
name string
testFunc func(t *testing.T)
}{
{
name: "expect error on delete",
testFunc: func(t *testing.T) {
f, err := newAzureFileClient("test", "dW5pdHRlc3Q=", "ut")
if err != nil {
t.Errorf("error creating azure client: %v", err)
}
shareName := "nonexistent"
actualErr := f.DeleteFileShare(context.Background(), shareName)
expectedErr := fmt.Errorf("Delete \"https://test.file.ut/%s?restype=share\"", shareName)
if actualErr == nil || !strings.HasPrefix(actualErr.Error(), expectedErr.Error()) {
t.Errorf("actualErr: (%v), expectedErr: (%v)", actualErr, expectedErr)
}
},
},
}
for _, tc := range testCases {
t.Run(tc.name, tc.testFunc)
}
}

func TestResizeFileShare(t *testing.T) {
testCases := []struct {
name string
testFunc func(t *testing.T)
}{
{
name: "expect error on resize",
testFunc: func(t *testing.T) {
f, err := newAzureFileClient("test", "dW5pdHRlc3Q=", "ut")
if err != nil {
t.Errorf("error creating azure client: %v", err)
}
shareName := "nonexistent"
actualErr := f.ResizeFileShare(context.Background(), shareName, 20)
expectedErr := fmt.Errorf("failed to set quota on file share %s", shareName)
if actualErr == nil || !strings.HasPrefix(actualErr.Error(), expectedErr.Error()) {
t.Errorf("actualErr: (%v), expectedErr: (%v)", actualErr, expectedErr)
}
},
},
}
for _, tc := range testCases {
t.Run(tc.name, tc.testFunc)
}
}

func TestGetFileShareQuotaDataPlane(t *testing.T) {
testCases := []struct {
name string
testFunc func(t *testing.T)
}{
{
name: "expect error on resize",
testFunc: func(t *testing.T) {
f, err := newAzureFileClient("test", "dW5pdHRlc3Q=", "ut")
if err != nil {
t.Errorf("error creating azure client: %v", err)
}
shareName := "nonexistent"
actualQuota, actualErr := f.GetFileShareQuota(context.Background(), shareName)
expectedErr := fmt.Errorf("Get \"https://test.file.ut/%s?restype=share\"", shareName)
expectedQuota := -1
if actualErr == nil || !strings.HasPrefix(actualErr.Error(), expectedErr.Error()) || actualQuota != -1 {
t.Errorf("actualErr: (%v), expectedErr: (%v), actualQuota: (%v), expectedQuota: (%v)", actualErr, expectedErr, actualQuota, expectedQuota)
}
},
},
}
for _, tc := range testCases {
t.Run(tc.name, tc.testFunc)
}
}

0 comments on commit a277f7a

Please # to comment.