create_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // +build linux
  2. package volume
  3. import (
  4. "context"
  5. "testing"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/api/types/volume"
  8. "github.com/docker/docker/integration-cli/daemon"
  9. )
  10. // TestCreateDerefOnError ensures that if a volume create fails, that the plugin is dereferenced
  11. // Normally 1 volume == 1 reference to a plugin, which prevents a plugin from being removed.
  12. // If the volume create fails, we should make sure to dereference the plugin.
  13. func TestCreateDerefOnError(t *testing.T) {
  14. t.Parallel()
  15. d := daemon.New(t, "", dockerdBinary, daemon.Config{})
  16. d.Start(t)
  17. defer d.Stop(t)
  18. c, err := d.NewClient()
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. pName := "testderef"
  23. createPlugin(t, c, pName, "create-error", asVolumeDriver)
  24. if err := c.PluginEnable(context.Background(), pName, types.PluginEnableOptions{Timeout: 30}); err != nil {
  25. t.Fatal(err)
  26. }
  27. _, err = c.VolumeCreate(context.Background(), volume.VolumesCreateBody{
  28. Driver: pName,
  29. Name: "fake",
  30. })
  31. if err == nil {
  32. t.Fatal("volume create should have failed")
  33. }
  34. if err := c.PluginDisable(context.Background(), pName, types.PluginDisableOptions{}); err != nil {
  35. t.Fatal(err)
  36. }
  37. if err := c.PluginRemove(context.Background(), pName, types.PluginRemoveOptions{}); err != nil {
  38. t.Fatal(err)
  39. }
  40. }