@@ -2,7 +2,10 @@ package csi
22
33import (
44 "context"
5+ "encoding/json"
56 "errors"
7+ "os"
8+ "path/filepath"
69 "testing"
710 "time"
811
@@ -221,7 +224,7 @@ func TestNodeUnstageVolume_Success(t *testing.T) {
221224 ctrl := gomock .NewController (t )
222225 defer ctrl .Finish ()
223226
224- svc , _ , mmount := newTestNode (ctrl )
227+ svc , iscsiMgr , mmount := newTestNode (ctrl )
225228 ctx := context .Background ()
226229
227230 req := & csi.NodeUnstageVolumeRequest {
@@ -230,24 +233,32 @@ func TestNodeUnstageVolume_Success(t *testing.T) {
230233 }
231234
232235 mmount .EXPECT ().IsMounted ("/tmp/staging" ).Return (true , nil )
233- mmount .EXPECT ().GetMountInfo ("/tmp/staging" ).Return (& mount.MountInfo {
234- Device : "/dev/sdb" ,
235- FSType : "ext4" ,
236- }, nil )
237236 mmount .EXPECT ().Unmount (ctx , "/tmp/staging" ).Return (nil )
238237
238+ target := & iscsi.TargetInfo {
239+ IQN : "iqn.test" ,
240+ Portal : "127.0.0.1:3260" ,
241+ }
242+ data , _ := json .Marshal (target )
243+ _ = os .MkdirAll (req .StagingTargetPath , 0755 )
244+ _ = os .WriteFile (filepath .Join (req .StagingTargetPath , ".target-info" ), data , 0600 )
245+
246+ iscsiMgr .EXPECT ().CleanupTarget (ctx , target ).Return (nil )
247+
239248 resp , err := svc .NodeUnstageVolume (ctx , req )
240249
241250 g .Expect (err ).To (BeNil ())
242251 g .Expect (resp ).NotTo (BeNil ())
252+
253+ _ = os .RemoveAll (req .StagingTargetPath )
243254}
244255
245256func TestNodeUnstageVolume_NotMounted (t * testing.T ) {
246257 g := NewGomegaWithT (t )
247258 ctrl := gomock .NewController (t )
248259 defer ctrl .Finish ()
249260
250- svc , _ , mmount := newTestNode (ctrl )
261+ svc , iscsiMgr , mmount := newTestNode (ctrl )
251262 ctx := context .Background ()
252263
253264 req := & csi.NodeUnstageVolumeRequest {
@@ -257,10 +268,21 @@ func TestNodeUnstageVolume_NotMounted(t *testing.T) {
257268
258269 mmount .EXPECT ().IsMounted ("/tmp/staging" ).Return (false , nil )
259270
271+ target := & iscsi.TargetInfo {
272+ IQN : "iqn.test" ,
273+ Portal : "127.0.0.1:3260" ,
274+ }
275+ _ = os .MkdirAll (req .StagingTargetPath , 0755 )
276+ _ = os .WriteFile (filepath .Join (req .StagingTargetPath , ".target-info" ), []byte (`{"IQN":"iqn.test","Portal":"127.0.0.1:3260"}` ), 0600 )
277+
278+ iscsiMgr .EXPECT ().CleanupTarget (ctx , target ).Return (nil )
279+
260280 resp , err := svc .NodeUnstageVolume (ctx , req )
261281
262282 g .Expect (err ).To (BeNil ())
263283 g .Expect (resp ).NotTo (BeNil ())
284+
285+ _ = os .RemoveAll (req .StagingTargetPath )
264286}
265287
266288func TestNodePublishVolume_Success (t * testing.T ) {
0 commit comments