@@ -23,12 +23,14 @@ import (
23
23
"net/http"
24
24
"net/url"
25
25
"reflect"
26
- "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient"
27
26
"strings"
28
27
"sync"
29
28
"testing"
30
29
"time"
31
30
31
+ "sigs.k8s.io/azurefile-csi-driver/pkg/util"
32
+ "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient"
33
+
32
34
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network"
33
35
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/subnetclient/mocksubnetclient"
34
36
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
@@ -1783,6 +1785,95 @@ func TestCopyVolume(t *testing.T) {
1783
1785
}
1784
1786
},
1785
1787
},
1788
+ {
1789
+ name : "azcopy job is already completed" ,
1790
+ testFunc : func (t * testing.T ) {
1791
+ d := NewFakeDriver ()
1792
+ mp := map [string ]string {}
1793
+
1794
+ volumeSource := & csi.VolumeContentSource_VolumeSource {
1795
+ VolumeId : "vol_1#f5713de20cde511e8ba4900#fileshare#" ,
1796
+ }
1797
+ volumeContentSourceVolumeSource := & csi.VolumeContentSource_Volume {
1798
+ Volume : volumeSource ,
1799
+ }
1800
+ volumecontensource := csi.VolumeContentSource {
1801
+ Type : volumeContentSourceVolumeSource ,
1802
+ }
1803
+
1804
+ req := & csi.CreateVolumeRequest {
1805
+ Name : "unit-test" ,
1806
+ VolumeCapabilities : stdVolCap ,
1807
+ Parameters : mp ,
1808
+ VolumeContentSource : & volumecontensource ,
1809
+ }
1810
+
1811
+ ctrl := gomock .NewController (t )
1812
+ defer ctrl .Finish ()
1813
+
1814
+ m := util .NewMockEXEC (ctrl )
1815
+ listStr := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\n Start Time: Monday, 07-Aug-23 03:29:54 UTC\n Status: Completed\n Command: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1816
+ m .EXPECT ().RunCommand (gomock .Eq ("azcopy jobs list | grep dstFileshare -B 3" )).Return (listStr , nil )
1817
+ // if test.enableShow {
1818
+ // m.EXPECT().RunCommand(gomock.Not("azcopy jobs list | grep dstContainer -B 3")).Return(test.showStr, test.showErr)
1819
+ // }
1820
+
1821
+ d .azcopy .ExecCmd = m
1822
+
1823
+ ctx := context .Background ()
1824
+
1825
+ var expectedErr error
1826
+ err := d .copyVolume (ctx , req , "" , & fileclient.ShareOptions {Name : "dstFileshare" }, "core.windows.net" )
1827
+ if ! reflect .DeepEqual (err , expectedErr ) {
1828
+ t .Errorf ("Unexpected error: %v" , err )
1829
+ }
1830
+ },
1831
+ },
1832
+ {
1833
+ name : "azcopy job is first in progress and then be completed" ,
1834
+ testFunc : func (t * testing.T ) {
1835
+ d := NewFakeDriver ()
1836
+ mp := map [string ]string {}
1837
+
1838
+ volumeSource := & csi.VolumeContentSource_VolumeSource {
1839
+ VolumeId : "vol_1#f5713de20cde511e8ba4900#fileshare#" ,
1840
+ }
1841
+ volumeContentSourceVolumeSource := & csi.VolumeContentSource_Volume {
1842
+ Volume : volumeSource ,
1843
+ }
1844
+ volumecontensource := csi.VolumeContentSource {
1845
+ Type : volumeContentSourceVolumeSource ,
1846
+ }
1847
+
1848
+ req := & csi.CreateVolumeRequest {
1849
+ Name : "unit-test" ,
1850
+ VolumeCapabilities : stdVolCap ,
1851
+ Parameters : mp ,
1852
+ VolumeContentSource : & volumecontensource ,
1853
+ }
1854
+
1855
+ ctrl := gomock .NewController (t )
1856
+ defer ctrl .Finish ()
1857
+
1858
+ m := util .NewMockEXEC (ctrl )
1859
+ listStr1 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\n Start Time: Monday, 07-Aug-23 03:29:54 UTC\n Status: InProgress\n Command: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1860
+ listStr2 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\n Start Time: Monday, 07-Aug-23 03:29:54 UTC\n Status: Completed\n Command: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1861
+ o1 := m .EXPECT ().RunCommand (gomock .Eq ("azcopy jobs list | grep dstFileshare -B 3" )).Return (listStr1 , nil ).Times (1 )
1862
+ m .EXPECT ().RunCommand (gomock .Not ("azcopy jobs list | grep dstFileshare -B 3" )).Return ("Percent Complete (approx): 50.0" , nil )
1863
+ o2 := m .EXPECT ().RunCommand (gomock .Eq ("azcopy jobs list | grep dstFileshare -B 3" )).Return (listStr2 , nil )
1864
+ gomock .InOrder (o1 , o2 )
1865
+
1866
+ d .azcopy .ExecCmd = m
1867
+
1868
+ ctx := context .Background ()
1869
+
1870
+ var expectedErr error
1871
+ err := d .copyVolume (ctx , req , "" , & fileclient.ShareOptions {Name : "dstFileshare" }, "core.windows.net" )
1872
+ if ! reflect .DeepEqual (err , expectedErr ) {
1873
+ t .Errorf ("Unexpected error: %v" , err )
1874
+ }
1875
+ },
1876
+ },
1786
1877
}
1787
1878
1788
1879
for _ , tc := range testCases {
0 commit comments