iscsi: make portal builder testable

Signed-off-by: Huamin Chen <hchen@redhat.com>
pull/6/head
Huamin Chen 2015-10-14 13:30:30 -04:00
parent 69a1f33dd5
commit 76df88f68b
2 changed files with 17 additions and 4 deletions

View File

@ -95,10 +95,7 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI
}
lun := strconv.Itoa(iscsi.Lun)
portal := iscsi.TargetPortal
if !strings.Contains(portal, ":") {
portal = iscsi.TargetPortal + ":3260"
}
portal := portalBuilder(iscsi.TargetPortal)
return &iscsiDiskBuilder{
iscsiDisk: &iscsiDisk{
@ -193,3 +190,10 @@ func (c *iscsiDiskCleaner) TearDown() error {
func (c *iscsiDiskCleaner) TearDownAt(dir string) error {
return diskTearDown(c.manager, *c, dir, c.mounter)
}
func portalBuilder(portal string) string {
if !strings.Contains(portal, ":") {
portal = portal + ":3260"
}
return portal
}

View File

@ -250,3 +250,12 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
t.Errorf("Expected true for builder.IsReadOnly")
}
}
func TestPortalBuilder(t *testing.T) {
if portal := portalBuilder("127.0.0.1"); portal != "127.0.0.1:3260" {
t.Errorf("wrong portal: %s", portal)
}
if portal := portalBuilder("127.0.0.1:3260"); portal != "127.0.0.1:3260" {
t.Errorf("wrong portal: %s", portal)
}
}