Skip to content

Commit

Permalink
Merge pull request #7110 from swagiaal/improve-iscsi-test
Browse files Browse the repository at this point in the history
iscsi Test: Add explicit check for attach and detach calls.
  • Loading branch information
vishh committed Apr 22, 2015
2 parents ee06097 + 0a7f6c2 commit a054201
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/volume/iscsi/iscsi_test.go
Expand Up @@ -39,7 +39,10 @@ func TestCanSupport(t *testing.T) {
}
}

type fakeDiskManager struct{}
type fakeDiskManager struct {
attachCalled bool
detachCalled bool
}

func (fake *fakeDiskManager) MakeGlobalPDName(disk iscsiDisk) string {
return "/tmp/fake_iscsi_path"
Expand All @@ -50,6 +53,11 @@ func (fake *fakeDiskManager) AttachDisk(disk iscsiDisk) error {
if err != nil {
return err
}
// Simulate the global mount so that the fakeMounter returns the
// expected number of mounts for the attached disk.
disk.mounter.Mount(globalPath, globalPath, disk.fsType, 0, "")

fake.attachCalled = true
return nil
}

Expand All @@ -59,6 +67,7 @@ func (fake *fakeDiskManager) DetachDisk(disk iscsiDisk, mntPath string) error {
if err != nil {
return err
}
fake.detachCalled = true
return nil
}

Expand All @@ -81,7 +90,9 @@ func TestPlugin(t *testing.T) {
},
},
}
builder, err := plug.(*ISCSIPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{})
fakeManager := &fakeDiskManager{}
fakeMounter := &mount.FakeMounter{}
builder, err := plug.(*ISCSIPlugin).newBuilderInternal(volume.NewSpecFromVolume(spec), types.UID("poduid"), fakeManager, fakeMounter)
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
Expand Down Expand Up @@ -111,8 +122,12 @@ func TestPlugin(t *testing.T) {
t.Errorf("SetUp() failed: %v", err)
}
}
if !fakeManager.attachCalled {
t.Errorf("Attach was not called")
}

cleaner, err := plug.(*ISCSIPlugin).newCleanerInternal("vol1", types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{})
fakeManager = &fakeDiskManager{}
cleaner, err := plug.(*ISCSIPlugin).newCleanerInternal("vol1", types.UID("poduid"), fakeManager, fakeMounter)
if err != nil {
t.Errorf("Failed to make a new Cleaner: %v", err)
}
Expand All @@ -128,4 +143,7 @@ func TestPlugin(t *testing.T) {
} else if !os.IsNotExist(err) {
t.Errorf("SetUp() failed: %v", err)
}
if !fakeManager.detachCalled {
t.Errorf("Detach was not called")
}
}

0 comments on commit a054201

Please sign in to comment.