Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.31] test: add copyvolume unit test #2292

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/utils/ptr"
"sigs.k8s.io/azurefile-csi-driver/pkg/util"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/fileshareclient/mock_fileshareclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/mock_azclient"
Expand Down Expand Up @@ -1643,6 +1644,40 @@ var _ = ginkgo.Describe("TestCopyVolume", func() {
gomega.Expect(err).To(gomega.Equal(expectedErr))
})
})
ginkgo.When("azcopy job is in progress", func() {
ginkgo.It("should fail", func(ctx context.Context) {
accountOptions := azure.AccountOptions{}
mp := map[string]string{}

volumeSource := &csi.VolumeContentSource_VolumeSource{
VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#",
}
volumeContentSourceVolumeSource := &csi.VolumeContentSource_Volume{
Volume: volumeSource,
}
volumecontensource := csi.VolumeContentSource{
Type: volumeContentSourceVolumeSource,
}

req := &csi.CreateVolumeRequest{
Name: "unit-test",
VolumeCapabilities: stdVolCap,
Parameters: mp,
VolumeContentSource: &volumecontensource,
}

m := util.NewMockEXEC(ctrl)
listStr1 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstFileshare -B 3"), gomock.Any()).Return(listStr1, nil).AnyTimes()
m.EXPECT().RunCommand(gomock.Not("azcopy jobs list | grep dstFileshare -B 3"), gomock.Any()).Return("Percent Complete (approx): 50.0", nil).AnyTimes()

d.azcopy.ExecCmd = m
d.waitForAzCopyTimeoutMinutes = 1

err := d.copyVolume(ctx, req, "", "sastoken", []string{}, "", &ShareOptions{Name: "dstFileshare"}, &accountOptions, "core.windows.net")
gomega.Expect(err).To(gomega.Equal(wait.ErrWaitTimeout))
})
})
})

var _ = ginkgo.Describe("ControllerGetVolume", func() {
Expand Down
Loading