README
¶
Go Os Wrapper
gooswrap is a thin wrapper around the os and io/ioutil packages.
The wrapper provides a virtualisation layer for int testing in an automated environment.
Production usage
Just replace the os and io/ioutil packages to the ones provided in this package.
import (
"os"
"io/ioutil"
)
To
import (
"github.com/kwitsch/gooswrap/os"
"github.com/kwitsch/gooswrap/ioutil"
)
Test usage
A virtual environment can be initialized with gooswrap.NewVirtual()
.
After that several values specified can be set in the virtual environment.
Some methodes will return ErrNotSupported
in virtual mode as not all functions can be virtulaized.
Ginkgo example:
When("Set values in virtual environment", func() {
const (
egid int = 991
euid int = 992
gid int = 993
group int = 994
pagesize int = 995
pid int = 996
ppid int = 997
uid int = 998
)
BeforeEach(func() {
gooswrap.NewVirtual()
err = gooswrap.Wrapper.Virtual.SetEgid(egid)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetEuid(euid)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetGid(gid)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetGroups([]int{group})
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetPagesize(pagesize)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetPid(pid)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetPpid(ppid)
Expect(err).Should(BeNil())
err = gooswrap.Wrapper.Virtual.SetUid(uid)
Expect(err).Should(BeNil())
})
Documentation
¶
Index ¶
- Constants
- Variables
- func NewVirtual()
- func ToOs()
- type VirtualData
- func (v *VirtualData) Egid() (int, error)
- func (v *VirtualData) Euid() (int, error)
- func (v *VirtualData) Gid() (int, error)
- func (v *VirtualData) Groups() ([]int, error)
- func (v *VirtualData) Hostname() (string, error)
- func (v *VirtualData) InitDirectories() error
- func (v *VirtualData) Pagesize() (int, error)
- func (v *VirtualData) Pid() (int, error)
- func (v *VirtualData) Ppid() (int, error)
- func (v *VirtualData) SetEgid(egid int) error
- func (v *VirtualData) SetEuid(euid int) error
- func (v *VirtualData) SetGid(gid int) error
- func (v *VirtualData) SetGroups(groups []int) error
- func (v *VirtualData) SetHostname(hostname string) error
- func (v *VirtualData) SetPagesize(pagesize int) error
- func (v *VirtualData) SetPid(pid int) error
- func (v *VirtualData) SetPpid(ppid int) error
- func (v *VirtualData) SetUid(uid int) error
- func (v *VirtualData) SyncEnv() error
- func (v *VirtualData) Uid() (int, error)
- type WrapperStore
Constants ¶
const ( VirtualTempDir string = "/tmp" VirtualUserCacheDir string = "/user/cache" VirtualUserConfigDir string = "/user/config" VirtualUserHomeDir string = "/user/home" )
Variables ¶
var (
ErrNotVirtual = errors.New("Wrapper is not virtual")
)
Functions ¶
Types ¶
type VirtualData ¶
type VirtualData struct { // pseudo environment Env map[string]string // contains filtered or unexported fields }
data store for virtual mode
func (*VirtualData) Egid ¶
func (v *VirtualData) Egid() (int, error)
get virtual Egid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Euid ¶
func (v *VirtualData) Euid() (int, error)
get virtual Euid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Gid ¶
func (v *VirtualData) Gid() (int, error)
get virtual Gid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Groups ¶
func (v *VirtualData) Groups() ([]int, error)
get virtual Groups returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Hostname ¶
func (v *VirtualData) Hostname() (string, error)
get virtual hostname returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) InitDirectories ¶
func (v *VirtualData) InitDirectories() error
create TempDir, UserCacheDir, UserConfigDir & UserHomeDir returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Pagesize ¶
func (v *VirtualData) Pagesize() (int, error)
get virtual Pagesize returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Pid ¶
func (v *VirtualData) Pid() (int, error)
get virtual Pid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Ppid ¶
func (v *VirtualData) Ppid() (int, error)
get virtual Ppid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetEgid ¶
func (v *VirtualData) SetEgid(egid int) error
set virtual Egid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetEuid ¶
func (v *VirtualData) SetEuid(euid int) error
set virtual Euid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetGid ¶
func (v *VirtualData) SetGid(gid int) error
set virtual Gid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetGroups ¶
func (v *VirtualData) SetGroups(groups []int) error
set virtual Groups returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetHostname ¶
func (v *VirtualData) SetHostname(hostname string) error
set virtual hostname returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetPagesize ¶
func (v *VirtualData) SetPagesize(pagesize int) error
set virtual Pagesize returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetPid ¶
func (v *VirtualData) SetPid(pid int) error
set virtual Pid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetPpid ¶
func (v *VirtualData) SetPpid(ppid int) error
set virtual Ppid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SetUid ¶
func (v *VirtualData) SetUid(uid int) error
set virtual Uid returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) SyncEnv ¶
func (v *VirtualData) SyncEnv() error
sync current os environment variables to virtual environment variables returns ErrNotVirtual if Wrapper isen't in virtual mode
func (*VirtualData) Uid ¶
func (v *VirtualData) Uid() (int, error)
get virtual Uid returns ErrNotVirtual if Wrapper isen't in virtual mode
type WrapperStore ¶
type WrapperStore struct { // afero filesystem Fs afero.Fs // afero ioutil Util *afero.Afero // current working directory WorkingDirectory string // virtual data store Virtual *VirtualData }
data store for wrapper object
var Wrapper *WrapperStore
wrapper object
func (*WrapperStore) GetPath ¶
func (ws *WrapperStore) GetPath(fpath string) string
get file path prefixed with current working directory if it doesen't start with a slash