github.com/a4a881d4/docker@v1.9.0-rc2/volume/testutils/testutils.go (about)

     1  package volumetestutils
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/docker/docker/volume"
     7  )
     8  
     9  // NoopVolume is a volume that doesn't perform any operation
    10  type NoopVolume struct{}
    11  
    12  // Name is the name of the volume
    13  func (NoopVolume) Name() string { return "noop" }
    14  
    15  // DriverName is the name of the driver
    16  func (NoopVolume) DriverName() string { return "noop" }
    17  
    18  // Path is the filesystem path to the volume
    19  func (NoopVolume) Path() string { return "noop" }
    20  
    21  // Mount mounts the volume in the container
    22  func (NoopVolume) Mount() (string, error) { return "noop", nil }
    23  
    24  // Unmount unmounts the volume from the container
    25  func (NoopVolume) Unmount() error { return nil }
    26  
    27  // FakeVolume is a fake volume with a random name
    28  type FakeVolume struct {
    29  	name string
    30  }
    31  
    32  // NewFakeVolume creates a new fake volume for testing
    33  func NewFakeVolume(name string) volume.Volume {
    34  	return FakeVolume{name: name}
    35  }
    36  
    37  // Name is the name of the volume
    38  func (f FakeVolume) Name() string { return f.name }
    39  
    40  // DriverName is the name of the driver
    41  func (FakeVolume) DriverName() string { return "fake" }
    42  
    43  // Path is the filesystem path to the volume
    44  func (FakeVolume) Path() string { return "fake" }
    45  
    46  // Mount mounts the volume in the container
    47  func (FakeVolume) Mount() (string, error) { return "fake", nil }
    48  
    49  // Unmount unmounts the volume from the container
    50  func (FakeVolume) Unmount() error { return nil }
    51  
    52  // FakeDriver is a driver that generates fake volumes
    53  type FakeDriver struct{}
    54  
    55  // Name is the name of the driver
    56  func (FakeDriver) Name() string { return "fake" }
    57  
    58  // Create initializes a fake volume.
    59  // It returns an error if the options include an "error" key with a message
    60  func (FakeDriver) Create(name string, opts map[string]string) (volume.Volume, error) {
    61  	if opts != nil && opts["error"] != "" {
    62  		return nil, fmt.Errorf(opts["error"])
    63  	}
    64  	return NewFakeVolume(name), nil
    65  }
    66  
    67  // Remove deletes a volume.
    68  func (FakeDriver) Remove(v volume.Volume) error { return nil }