Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit 67e0bd5

Browse files
author
Harvey Lowndes
committed
Add tests
1 parent 1a3280e commit 67e0bd5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pkg/flexvolume/flexvolume.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ func ExecDriver(drivers map[string]Driver, args []string) DriverStatus {
154154
driver := drivers[DefaultSymlinkDirectory] //Block volume is default
155155

156156
dir := path.Base(args[0])
157-
dir = strings.TrimPrefix(dir, "oracle~")
157+
dir = string(strings.TrimPrefix(dir, "oracle~"))
158158

159159
if dir != "oci" && dir != DefaultSymlinkDirectory {
160160
driver = drivers[dir]
161161
}
162162

163163
// Moved outside the above if to catch errors in code.
164164
if driver == nil {
165-
Failf("No driver found for ", dir)
165+
return Failf("No driver found for %s", dir)
166166
}
167167

168168
log.Printf("Using %s driver", dir)
@@ -283,5 +283,4 @@ func ExecDriver(drivers map[string]Driver, args []string) DriverStatus {
283283
default:
284284
return Failf("invalid command; got ", args)
285285
}
286-
return Failf("Unexpected condition")
287286
}

pkg/flexvolume/flexvolume_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ func TestAttachUnsuported(t *testing.T) {
7272
expected := DriverStatus{Status: "Not supported"}
7373
assertFailure(t, expected, status)
7474
}
75+
76+
func TestInvalidSymlink(t *testing.T) {
77+
status := ExecDriver(map[string]Driver{"oci-bvs": mockFlexvolumeDriver{}},
78+
[]string{"oci-abc", "init", defaultTestOps, "nodeName"})
79+
80+
expected := DriverStatus{
81+
Status: "Failure",
82+
Message: "No driver found for oci-abc",
83+
}
84+
assertFailure(t, expected, status)
85+
}

0 commit comments

Comments
 (0)