2013-11-01 15:04:08 -04:00
|
|
|
package devmapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2013-11-01 15:30:30 -04:00
|
|
|
"os"
|
2013-11-01 15:04:08 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mkTestDirectory(t *testing.T) string {
|
|
|
|
dir, err := ioutil.TempDir("", "docker-test-devmapper-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return dir
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
home := mkTestDirectory(t)
|
2013-11-01 15:30:30 -04:00
|
|
|
defer os.RemoveAll(home)
|
2013-11-07 17:37:33 -05:00
|
|
|
driver, err := Init(home)
|
2013-11-01 15:04:08 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
return
|
2013-11-07 17:37:33 -05:00
|
|
|
if err := driver.Cleanup(); err != nil {
|
2013-11-01 15:04:08 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2013-11-07 17:37:33 -05:00
|
|
|
id := "foo"
|
|
|
|
if err := driver.Create(id, ""); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
dir, err := driver.Get(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if st, err := os.Stat(dir); err != nil {
|
2013-11-01 15:04:08 -04:00
|
|
|
t.Fatal(err)
|
2013-11-07 17:37:33 -05:00
|
|
|
} else if !st.IsDir() {
|
|
|
|
t.Fatalf("Get(%V) did not return a directory", id)
|
2013-11-01 15:04:08 -04:00
|
|
|
}
|
|
|
|
}
|