@@ -1926,25 +1926,32 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
19261926 mockAPI , d := newMockOntapSanEcoDriver (t )
19271927
19281928 volConfig := & storage.VolumeConfig {
1929- InternalName : "my_vol/my_LUN " ,
1929+ InternalName : "pvc-1234 " ,
19301930 Size : "1g" ,
19311931 Encryption : "false" ,
19321932 FileSystem : "xfs" ,
19331933 }
19341934 d .flexvolNamePrefix = "test_lun_pool_"
1935+ originalFlexvol := & api.Volume {
1936+ AccessType : "rw" ,
1937+ Name : "my_vol" ,
1938+ }
19351939
19361940 tests := []struct {
19371941 name string // Name of the test case
1942+ volConfig * storage.VolumeConfig
19381943 volToImport string
19391944 mocks func (mockAPI * mockapi.MockOntapAPI )
19401945 wantErr assert.ErrorAssertionFunc
19411946 testOut string
1947+ validate func (t * testing.T , volConfig * storage.VolumeConfig )
19421948 }{
19431949 {
1944- name : "VolumeInfo_mangedImport_LUNRenameFail" ,
1950+ name : "VolumeInfo_managedImport_LUNRenameFail" ,
1951+ volConfig : volConfig .ConstructClone (),
19451952 volToImport : "my_vol/my_LUN" ,
19461953 mocks : func (mockAPI * mockapi.MockOntapAPI ) {
1947- mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (& api. Volume { AccessType : "rw" } , nil )
1954+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
19481955 mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
19491956 Return (& api.Lun {Name : "/vol/my_vol/my_LUN" , State : "online" , Size : "1073741824" }, nil )
19501957 mockAPI .EXPECT ().LunRename (gomock .Any (), gomock .Any (), gomock .Any ()).
@@ -1954,12 +1961,13 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
19541961 testOut : "Import succeeded" ,
19551962 },
19561963 {
1957- name : "VolumeInfo_mangedImport_VolumeRenameFailed" ,
1964+ name : "VolumeInfo_managedImport_VolumeRenameFailed" ,
1965+ volConfig : volConfig .ConstructClone (),
19581966 volToImport : "my_vol/my_LUN" ,
19591967 mocks : func (mockAPI * mockapi.MockOntapAPI ) {
1960- mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (& api. Volume { AccessType : "rw" } , nil )
1968+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
19611969 mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
1962- Return (& api.Lun {Name : "/vol/my_vol/my_LUN " , State : "online" , Size : "1073741824" }, nil )
1970+ Return (& api.Lun {Name : "/vol/my_vol/importMe " , State : "online" , Size : "1073741824" }, nil )
19631971 mockAPI .EXPECT ().LunRename (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (nil )
19641972 mockAPI .EXPECT ().VolumeRename (gomock .Any (), gomock .Any (), gomock .Any ()).
19651973 Return (errors .New ("volume rename failed" ))
@@ -1968,10 +1976,11 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
19681976 testOut : "Import succeeded" ,
19691977 },
19701978 {
1971- name : "VolumeInfo_mangedImport_LUNNameRestoreFailed" ,
1979+ name : "VolumeInfo_managedImport_LUNNameRestoreFailed" ,
1980+ volConfig : volConfig .ConstructClone (),
19721981 volToImport : "my_vol/my_LUN" ,
19731982 mocks : func (mockAPI * mockapi.MockOntapAPI ) {
1974- mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (& api. Volume { AccessType : "rw" } , nil )
1983+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
19751984 mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
19761985 Return (& api.Lun {Name : "/vol/my_vol/my_LUN" , State : "online" , Size : "1073741824" }, nil )
19771986 mockAPI .EXPECT ().LunRename (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
@@ -1984,12 +1993,13 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
19841993 testOut : "Import succeeded" ,
19851994 },
19861995 {
1987- name : "VolumeInfo_mangedImport_igroupListFailed" ,
1996+ name : "VolumeInfo_managedImport_igroupListFailed" ,
1997+ volConfig : volConfig .ConstructClone (),
19881998 volToImport : "my_vol/my_LUN" ,
19891999 mocks : func (mockAPI * mockapi.MockOntapAPI ) {
1990- mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (& api. Volume { AccessType : "rw" } , nil )
2000+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
19912001 mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
1992- Return (& api.Lun {Name : "/vol/my_vol /my_LUN" , State : "online" , Size : "1073741824" }, nil )
2002+ Return (& api.Lun {Name : "/vol/my_LUN /my_LUN" , State : "online" , Size : "1073741824" }, nil )
19932003 mockAPI .EXPECT ().LunRename (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
19942004 mockAPI .EXPECT ().VolumeRename (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
19952005 mockAPI .EXPECT ().LunListIgroupsMapped (gomock .Any (), gomock .Any ()).
@@ -1999,10 +2009,33 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
19992009 testOut : "Import succeeded" ,
20002010 },
20012011 {
2002- name : "VolumeInfo_mangedImport_igroupListSucceeds" ,
2012+ name : "VolumeInfo_managedImport_renameNotNecessary" ,
2013+ volConfig : & storage.VolumeConfig {
2014+ InternalName : "my_LUN" ,
2015+ Size : "1g" ,
2016+ Encryption : "false" ,
2017+ FileSystem : "xfs" ,
2018+ },
20032019 volToImport : "my_vol/my_LUN" ,
20042020 mocks : func (mockAPI * mockapi.MockOntapAPI ) {
2005- mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (& api.Volume {AccessType : "rw" }, nil )
2021+
2022+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
2023+ mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
2024+ Return (& api.Lun {Name : "/vol/my_vol/my_LUN" , State : "online" , Size : "1073741824" }, nil )
2025+ mockAPI .EXPECT ().LunListIgroupsMapped (gomock .Any (), gomock .Any ()).Return (nil , nil )
2026+ },
2027+ wantErr : assert .NoError ,
2028+ testOut : "Import succeeded" ,
2029+ validate : func (t * testing.T , volConfig * storage.VolumeConfig ) {
2030+ assert .Equal (t , "/svm/SVM1/flexvol/my_vol/lun/my_LUN" , volConfig .InternalID )
2031+ },
2032+ },
2033+ {
2034+ name : "VolumeInfo_managedImport_lunAndFlexvolRename" ,
2035+ volConfig : volConfig .ConstructClone (),
2036+ volToImport : "my_vol/my_LUN" ,
2037+ mocks : func (mockAPI * mockapi.MockOntapAPI ) {
2038+ mockAPI .EXPECT ().VolumeInfo (gomock .Any (), gomock .Any ()).Return (originalFlexvol , nil )
20062039 mockAPI .EXPECT ().LunGetByName (gomock .Any (), gomock .Any ()).
20072040 Return (& api.Lun {Name : "/vol/my_vol/my_LUN" , State : "online" , Size : "1073741824" }, nil )
20082041 mockAPI .EXPECT ().LunRename (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
@@ -2011,16 +2044,25 @@ func TestOntapSanEconomyVolumeImport_Managed(t *testing.T) {
20112044 },
20122045 wantErr : assert .NoError ,
20132046 testOut : "Import succeeded" ,
2047+ validate : func (t * testing.T , volConfig * storage.VolumeConfig ) {
2048+ assert .True (t , strings .HasPrefix (volConfig .InternalID , "/svm/SVM1/flexvol/test_lun_pool_" ),
2049+ "InternalID should have correct prefix" )
2050+ assert .True (t , strings .HasSuffix (volConfig .InternalID , "/lun/pvc-1234" ),
2051+ "InternalID should have correct suffix" )
2052+ },
20142053 },
20152054 }
20162055 for _ , test := range tests {
20172056 t .Run (test .name , func (t * testing.T ) {
20182057 test .mocks (mockAPI )
2019- err := d .Import (ctx , volConfig , test .volToImport )
2058+ err := d .Import (ctx , test . volConfig , test .volToImport )
20202059 if ! test .wantErr (t , err , test .testOut ) {
20212060 // Stop on failure of any tests
20222061 return
20232062 }
2063+ if test .validate != nil {
2064+ test .validate (t , test .volConfig )
2065+ }
20242066 })
20252067 }
20262068}
0 commit comments