@@ -865,6 +865,8 @@ func TestNVMeNamespaceUnmapped(t *testing.T) {
865865 nsUUID := "fakeNsUUID"
866866 hostNQN := "fakeHostNQN"
867867 host2NQN := "fakeHost2NQN"
868+ nonExistentHostNQN := "fakeHostNQNNonExisting"
869+
868870 host1 := & models.NvmeSubsystemHost {Nqn : & hostNQN }
869871 host2 := & models.NvmeSubsystemHost {Nqn : & host2NQN }
870872 var removePublishInfo bool
@@ -901,11 +903,14 @@ func TestNVMeNamespaceUnmapped(t *testing.T) {
901903 mock .EXPECT ().ClientConfig ().Return (clientConfig ).AnyTimes ()
902904 mock .EXPECT ().NVMeIsNamespaceMapped (ctx , subsystemUUID , nsUUID ).Return (true , nil ).Times (1 )
903905 mock .EXPECT ().NVMeGetHostsOfSubsystem (ctx , subsystemUUID ).Return (nil , nil ).Times (1 )
906+ mock .EXPECT ().NVMeSubsystemRemoveNamespace (ctx , subsystemUUID , nsUUID ).AnyTimes ().Return (nil ).Times (1 )
907+ mock .EXPECT ().NVMeNamespaceCount (ctx , subsystemUUID ).Return (int64 (0 ), nil ).Times (1 )
908+ mock .EXPECT ().NVMeSubsystemDelete (ctx , subsystemUUID ).Return (nil ).Times (1 )
904909
905910 removePublishInfo , err = oapi .NVMeEnsureNamespaceUnmapped (ctx , hostNQN , subsystemUUID , nsUUID )
906911
907- assert .Equal (t , false , removePublishInfo , "subsystem removed" )
908- assert .Error (t , err )
912+ assert .Equal (t , true , removePublishInfo , "subsystem removed" )
913+ assert .NoError (t , err )
909914
910915 // case 5: multiple hosts of the subsystem returned but error while removing host from subsystem
911916 mock .EXPECT ().ClientConfig ().Return (clientConfig ).AnyTimes ()
@@ -977,6 +982,28 @@ func TestNVMeNamespaceUnmapped(t *testing.T) {
977982
978983 assert .Equal (t , true , removePublishInfo , "subsystem is not removed" )
979984 assert .NoError (t , err )
985+
986+ // case 11: Success when the nqn is already removed from subsystem
987+ mock .EXPECT ().ClientConfig ().Return (clientConfig ).AnyTimes ()
988+ mock .EXPECT ().NVMeIsNamespaceMapped (ctx , subsystemUUID , nsUUID ).Return (true , nil ).Times (1 )
989+ mock .EXPECT ().NVMeGetHostsOfSubsystem (ctx , subsystemUUID ).Return ([]* models.NvmeSubsystemHost {host1 },
990+ nil ).Times (1 )
991+
992+ removePublishInfo , err = oapi .NVMeEnsureNamespaceUnmapped (ctx , nonExistentHostNQN , subsystemUUID , nsUUID )
993+
994+ assert .Equal (t , false , removePublishInfo , "nqn is unmapped" )
995+ assert .NoError (t , err )
996+
997+ // case 12: Success when the nqn is already removed from subsystem with multiple hosts
998+ mock .EXPECT ().ClientConfig ().Return (clientConfig ).AnyTimes ()
999+ mock .EXPECT ().NVMeIsNamespaceMapped (ctx , subsystemUUID , nsUUID ).Return (true , nil ).Times (1 )
1000+ mock .EXPECT ().NVMeGetHostsOfSubsystem (ctx , subsystemUUID ).Return ([]* models.NvmeSubsystemHost {host1 , host2 },
1001+ nil ).Times (1 )
1002+
1003+ removePublishInfo , err = oapi .NVMeEnsureNamespaceUnmapped (ctx , nonExistentHostNQN , subsystemUUID , nsUUID )
1004+
1005+ assert .Equal (t , false , removePublishInfo , "nqn is unmapped" )
1006+ assert .NoError (t , err )
9801007}
9811008
9821009func TestNVMeIsNamespaceMapped (t * testing.T ) {
0 commit comments