@@ -43,6 +43,7 @@ type OS interface {
|
||||
Mount(source string, target string, fstype string, flags uintptr, data string) error
|
||||
Unmount(target string) error
|
||||
LookupMount(path string) (mount.Info, error)
|
||||
Hostname() (string, error)
|
||||
}
|
||||
|
||||
// RealOS is used to dispatch the real system level operations.
|
||||
@@ -134,3 +135,8 @@ func Unmount(target string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Hostname will call os.Hostname to get the hostname of the host.
|
||||
func (RealOS) Hostname() (string, error) {
|
||||
return os.Hostname()
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ type FakeOS struct {
|
||||
MountFn func(source string, target string, fstype string, flags uintptr, data string) error
|
||||
UnmountFn func(target string) error
|
||||
LookupMountFn func(path string) (containerdmount.Info, error)
|
||||
HostnameFn func() (string, error)
|
||||
calls []CalledDetail
|
||||
errors map[string]error
|
||||
}
|
||||
@@ -254,3 +255,16 @@ func (f *FakeOS) LookupMount(path string) (containerdmount.Info, error) {
|
||||
}
|
||||
return containerdmount.Info{}, nil
|
||||
}
|
||||
|
||||
// Hostname is a fake call that invokes HostnameFn or just return nil.
|
||||
func (f *FakeOS) Hostname() (string, error) {
|
||||
f.appendCalls("Hostname")
|
||||
if err := f.getError("Hostname"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if f.HostnameFn != nil {
|
||||
return f.HostnameFn()
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user