Skip to content

Commit

Permalink
test: add unit test for func storage/volume/VolumePath
Browse files Browse the repository at this point in the history
Signed-off-by: btlcmr0702 <[email protected]>
  • Loading branch information
btlcmr0702 committed Jul 24, 2018
1 parent 15753ec commit fa73c81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion storage/volume/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ func (c *Core) DetachVolume(id types.VolumeID, extra map[string]string) (*types.
if err != nil {
return nil, err
}

ctx := driver.Contexts()

// merge extra to volume spec extra.
Expand Down
27 changes: 15 additions & 12 deletions storage/volume/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,16 @@ func TestListVolumes(t *testing.T) {
}

func TestListVolumeName(t *testing.T) {
// TODO
driverName := "fake_driver4"
driverName := "my_fake"
dir, err := ioutil.TempDir("", "TestGetVolume")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

core, err := createVolumeCore(dir)
if err != nil {
t.Fatal(err)
core, err_cv := createVolumeCore(dir)
if err_cv != nil {
t.Fatal("create volume core error")
}

driver.Register(driver.NewFakeDriver(driverName))
Expand All @@ -199,12 +198,16 @@ func TestListVolumeName(t *testing.T) {
volid := types.VolumeID{Name: volName, Driver: driverName}
v, err := core.CreateVolume(volid)
if err != nil {
t.Fatalf("create volume error: %v", err)
t.Fatalf("create volume fail: %v", err)
}
volmap[volName] = v
}

volarray, err := core.ListVolumes(nil)
volarray, err_lv := core.ListVolumes(nil)
if err_lv != nil {
t.Fatalf("list volumes fail")
}

for k := 0; k < len(volarray); k++ {
vol := volarray[k]
_, found := volmap[vol.Name]
Expand All @@ -214,15 +217,15 @@ func TestListVolumeName(t *testing.T) {
}
//add unit test for listVolumeName
var volNames []string
volNames, err = core.ListVolumeName(nil)
if err != nil{
t.Fatalf("list volume name function failed!")
volNames, err = core.ListVolumeName(nil)
if err != nil {
t.Fatalf("list volume name function fail!")
}
for j:= 0; j < len(volNames); j++ {
for j := 0; j < len(volNames); j++ {
_, found := volmap[volNames[j]]
if found == false {
t.Fatalf("list volumes name %s not found", volNames[j])
}
}
}

}
Expand Down

0 comments on commit fa73c81

Please sign in to comment.