You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
genny v2 could be improved imho by making the API feel more like one is writing go code using the standard library instead of an abstraction of such. This issue serves as a collection of sorts for those API proposals:
remove all usages of packr
With the io/fs package introduced in go 1.16 we can remove all usages of packr and replace them with their new equivalents.
genny.Runner should not change behavior after instantiation
All fields of genny.Runner should be private to ensure they are only set during instantiation of the object and not modified afterwards. Provide a New function with options like WithLogger, WithExecFn, etc. to set those fields. WithDisk can be used by gentest.NewRunner to return a runner for testing together with a reference to the virtual disk for seeding.
typeRunnerstruct {
loggerLoggerInterface// Instead of a concrete type Logger should just be an interfacecontext context.ContextexecFnfunc(*exec.Cmd) errorfileFnfunc(File) (File, error)
chdirFnfunc(string, func() error) errordeleteFnfunc(string) errorrequestFnfunc(*http.Request, *http.Client) (*http.Response, error)
lookPathFnfunc(string) (string, error)
rootstringdisk*Diskstepsmap[string]*Stepmoot*sync.RWMutexresultsResultscurGen*Generator
}
genny.Runner should abstract usage of virtual / real files
The disk object represents a virtual file system that is used in a dry run to simulate the actual file system. It should not be accessed from outside genny.Runner to prevent the user from thinking that modifying the disk actually changes something on the hard drive when a wet runner is used. Instead most of it's functionality will be added to genny.Runner:
// replaces File. Create creates a new file the returned file is a proxy of either os.File or a virtual file// mkdir and mkdirall behave like their os package equivalents or create directories on the virtual diskfunc (r*Runner) Create(namestring) (*File, error)
func (r*Runner) Mkdir(namestring, perm os.FileMode) errorfunc (r*Runner) MkdirAll(pathstring, perm os.FileMode) error// new method signature, runner remembers where it chdir'd to correctly access to the virtual disk after changing the directory// it also changes back to the original directory when the runner finishesfunc (r*Runner) Chdir(dirstring) error// replaces from FindFile. tries to open a file on disk or the virtual file systemfunc (r*Runner) Open(namestring) (*File, error)
// renamed from delete to be more in line with the "os" packagefunc (r*Runner) Remove(namestring) errorfunc (r*Runner) RemoveAll(pathstring) error// updated method signature to be more in line with "net/http" package:func (r*Runner) DoRequest(req*http.Request) (*http.Response, error)
func (r*Runner) DoRequestWithClient(c*http.Client, req*http.Request) (*http.Response, error)
// unchangedfunc (r*Runner) Exec(cmd*exec.Cmd) errorfunc (r*Runner) FindStep(namestring) (*Step, error)
func (r*Runner) LookPath(filestring) (string, error)
func (r*Runner) ReplaceStep(namestring, s*Step) errorfunc (r*Runner) Results() Resultsfunc (r*Runner) Run() errorfunc (r*Runner) Steps() []*Stepfunc (r*Runner) With(g*Generator) errorfunc (r*Runner) WithFn(fnfunc() (*Generator, error)) errorfunc (r*Runner) WithGroup(gg*Group)
func (r*Runner) WithNew(g*Generator, errerror) errorfunc (r*Runner) WithRun(fnRunFn)
func (r*Runner) WithStep(namestring, step*Step) error
gentest package updates
To make it easier to setup a virtual filesystem in tests now gentest.NewRunner() returns access to the internal disk of the runner that is used for testing:
funcNewRunner() (*genny.Runner, *genny.Disk)
implementation of io/fs interfaces
Disk should implement the following interfaces; Runner should probably implement most of these interfaces too:
fs.FS{} // because it is a FS
fs.StatFS{} // allows to walk the Disk with fs.WalkDir
fs.GlobFS{} // to easily find all files matching a pattern
fs.ReadDirFS{} // equivalent of os.ReadDir; allows more efficient walking
fs.ReadFileFS{} // equivalent of os.ReadFile
fs.SubFS{} // allows the creation of sub-filesystems
Returned virtual files and directories should implement the io/fs interfaces like their os equivalents:
fs.File{}
fs.DirEntry{}
The text was updated successfully, but these errors were encountered:
genny v2 could be improved imho by making the API feel more like one is writing go code using the standard library instead of an abstraction of such. This issue serves as a collection of sorts for those API proposals:
remove all usages of
packr
With the
io/fs
package introduced in go 1.16 we can remove all usages ofpackr
and replace them with their new equivalents.genny.Runner
should not change behavior after instantiationAll fields of
genny.Runner
should be private to ensure they are only set during instantiation of the object and not modified afterwards. Provide a New function with options likeWithLogger
,WithExecFn
, etc. to set those fields.WithDisk
can be used bygentest.NewRunner
to return a runner for testing together with a reference to the virtual disk for seeding.genny.Runner
should abstract usage of virtual / real filesThe disk object represents a virtual file system that is used in a dry run to simulate the actual file system. It should not be accessed from outside
genny.Runner
to prevent the user from thinking that modifying the disk actually changes something on the hard drive when a wet runner is used. Instead most of it's functionality will be added togenny.Runner:
gentest
package updatesTo make it easier to setup a virtual filesystem in tests now
gentest.NewRunner()
returns access to the internal disk of the runner that is used for testing:implementation of
io/fs
interfacesDisk
should implement the following interfaces;Runner
should probably implement most of these interfaces too:Returned virtual files and directories should implement the
io/fs
interfaces like theiros
equivalents:The text was updated successfully, but these errors were encountered: