From 76df88f68ba7d0f0687d46a3a6c7a803be4b566c Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Wed, 14 Oct 2015 13:30:30 -0400 Subject: [PATCH] iscsi: make portal builder testable Signed-off-by: Huamin Chen --- pkg/volume/iscsi/iscsi.go | 12 ++++++++---- pkg/volume/iscsi/iscsi_test.go | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 9c75334348a..492f9175bfc 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -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 +} diff --git a/pkg/volume/iscsi/iscsi_test.go b/pkg/volume/iscsi/iscsi_test.go index 9ee8eef9769..2025d922c75 100644 --- a/pkg/volume/iscsi/iscsi_test.go +++ b/pkg/volume/iscsi/iscsi_test.go @@ -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) + } +}