driver_test.go 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package devmapper
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. )
  7. type TestImage struct {
  8. id string
  9. path string
  10. }
  11. func (img *TestImage) ID() string {
  12. return img.id
  13. }
  14. func (img *TestImage) Path() string {
  15. return img.path
  16. }
  17. func (img *TestImage) Parent() (Image, error) {
  18. return nil, nil
  19. }
  20. func mkTestImage(t *testing.T) Image {
  21. return &TestImage{
  22. path: mkTestDirectory(t),
  23. id: "4242",
  24. }
  25. }
  26. func mkTestDirectory(t *testing.T) string {
  27. dir, err := ioutil.TempDir("", "docker-test-devmapper-")
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. return dir
  32. }
  33. func TestInit(t *testing.T) {
  34. home := mkTestDirectory(t)
  35. defer os.RemoveAll(home)
  36. plugin, err := Init(home)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. defer func() {
  41. return
  42. if err := plugin.Cleanup(); err != nil {
  43. t.Fatal(err)
  44. }
  45. }()
  46. img := mkTestImage(t)
  47. defer os.RemoveAll(img.(*TestImage).path)
  48. if err := plugin.OnCreate(img, nil); err != nil {
  49. t.Fatal(err)
  50. }
  51. }