Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add unit-test for Volume Core's DetachVolume method #1824

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion storage/volume/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,45 @@ func TestAttachVolume(t *testing.T) {
}

func TestDetachVolume(t *testing.T) {
// TODO
volName1 := "vol2"
driverName1 := "fake_driver12"
volid1 := types.VolumeID{Name: volName1, Driver: driverName1}
extra1 := map[string]string{}

dir, err := ioutil.TempDir("", "TestDetachVolume")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

//create volume core

core, err := createVolumeCore(dir)
if err != nil {
t.Fatal(err)
}

driver.Register(driver.NewFakeDriver(driverName1))
defer driver.Unregister(driverName1)

core.CreateVolume(volid1)

//attach a volume and detach it
v1, err1 := core.AttachVolume(volid1, extra1)
if err1 != nil {
t.Fatalf("attach volume error: %v", err1)
}

if v1.Name != volName1 {
t.Fatalf("expect volume name is %s, but got %s", volName1, v1.Name)
}
if v1.Driver() != driverName1 {
t.Fatalf("expect volume driver is %s, but got %s", driverName1, v1.Driver())
}

//detach a null volume
_, err = core.DetachVolume(types.VolumeID{Name: "none", Driver: "none"}, nil)
if err == nil {
t.Fatal("expect get driver not found error, but err is nil")
}
}