mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add DeviceSetWrapper
This wraps an existing DeviceSet and just adds a prefix to all ids in it. This will be useful for reusing a single DeviceSet for all the tests (but with separate ids)
This commit is contained in:
parent
99393cf3cf
commit
381ce94ef4
1 changed files with 49 additions and 0 deletions
49
deviceset.go
49
deviceset.go
|
@ -9,3 +9,52 @@ type DeviceSet interface {
|
|||
HasDevice(hash string) bool
|
||||
HasInitializedDevice(hash string) bool
|
||||
}
|
||||
|
||||
type DeviceSetWrapper struct {
|
||||
wrapped DeviceSet
|
||||
prefix string
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) wrap(hash string) string {
|
||||
if hash != "" {
|
||||
hash = wrapper.prefix + "-" + hash
|
||||
}
|
||||
return hash
|
||||
}
|
||||
|
||||
|
||||
func (wrapper *DeviceSetWrapper) AddDevice(hash, baseHash string) error {
|
||||
return wrapper.wrapped.AddDevice(wrapper.wrap(hash), wrapper.wrap(baseHash))
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) SetInitialized(hash string) error {
|
||||
return wrapper.wrapped.SetInitialized(wrapper.wrap(hash))
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) DeactivateDevice(hash string) error {
|
||||
return wrapper.wrapped.DeactivateDevice(wrapper.wrap(hash))
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) RemoveDevice(hash string) error {
|
||||
return wrapper.wrapped.RemoveDevice(wrapper.wrap(hash))
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) MountDevice(hash, path string) error {
|
||||
return wrapper.wrapped.MountDevice(wrapper.wrap(hash), path)
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) HasDevice(hash string) bool {
|
||||
return wrapper.wrapped.HasDevice(wrapper.wrap(hash))
|
||||
}
|
||||
|
||||
func (wrapper *DeviceSetWrapper) HasInitializedDevice(hash string) bool {
|
||||
return wrapper.wrapped.HasInitializedDevice(wrapper.wrap(hash))
|
||||
}
|
||||
|
||||
func NewDeviceSetWrapper(wrapped DeviceSet, prefix string) DeviceSet {
|
||||
wrapper := &DeviceSetWrapper{
|
||||
wrapped: wrapped,
|
||||
prefix: prefix,
|
||||
}
|
||||
return wrapper
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue