Documentation ¶
Index ¶
- Variables
- type BeforeFunc
- type CandidateFunc
- type CleanFunc
- type CompareFunc
- type Config
- type ConfigFunc
- type Experiment
- func (e *Experiment) Before(fnc BeforeFunc)
- func (e *Experiment) Candidate(name string, fnc CandidateFunc) error
- func (e *Experiment) Clean(fnc CleanFunc)
- func (e *Experiment) Compare(fnc CompareFunc)
- func (e *Experiment) Control(fnc CandidateFunc)
- func (e *Experiment) Force(f bool)
- func (e *Experiment) Ignore(i bool)
- func (e *Experiment) Run() (interface{}, error)
- type Observation
- type Publisher
Constants ¶
This section is empty.
Variables ¶
var ( // ErrControlCandidate is returned when a candidate is initiated with // control as it's name. ErrControlCandidate = errors.New("Can't use a candidate with the name 'control'") // ErrCandidatePanic represents the error that a candidate panicked. ErrCandidatePanic = errors.New("candidate panicked") )
Functions ¶
This section is empty.
Types ¶
type BeforeFunc ¶
type BeforeFunc func() error
BeforeFunc represents the function that gets run before the experiment starts. This function will only run if the experiment should run. The functionality should be defined by the user.
type CandidateFunc ¶
type CandidateFunc func() (interface{}, error)
CandidateFunc represents a function that is implemented by a candidate. The value returned is the value that will be used to compare data.
type CleanFunc ¶
type CleanFunc func(interface{}) interface{}
CleanFunc represents the function that cleans up the output data. This function will only be called for candidates that did not error.
type CompareFunc ¶
type CompareFunc func(interface{}, interface{}) bool
CompareFunc represents the function that takes two candidates and knows how to compare them. The functionality is implemented by the user. This function will only be called for candidates that did not error.
type ConfigFunc ¶
type ConfigFunc func(*Config)
ConfigFunc represents a function that knows how to set a configuration option.
func WithConcurrency ¶
func WithConcurrency() ConfigFunc
WithConcurrency forces the experiment to run concurrently
func WithDefaultConfig ¶
func WithDefaultConfig() ConfigFunc
WithDefaultConfig returns a new configuration with defaults.
func WithPercentage ¶
func WithPercentage(p int) ConfigFunc
WithPercentage returns a new ConfigFunc that sets the percentage.
func WithPublisher ¶
func WithPublisher(p Publisher) ConfigFunc
WithPublisher returns a new ConfigFunc that sets the publisher.
type Experiment ¶
type Experiment struct { Config *Config // contains filtered or unexported fields }
Experiment represents a new refactoring experiment. This is where you'll define your control and candidates on and this will run the experiment according to the configuration.
func New ¶
func New(cfgs ...ConfigFunc) *Experiment
New creates a new Experiment with the given configuration options.
func (*Experiment) Before ¶
func (e *Experiment) Before(fnc BeforeFunc)
Before filter to do expensive setup only when the experiment is going to run. This will be skipped if the experiment doesn't need to run. A good use case would be to do a deep copy of a struct.
func (*Experiment) Candidate ¶
func (e *Experiment) Candidate(name string, fnc CandidateFunc) error
Candidate represents a refactoring solution. The order of candidates is randomly determined. If the concurrent configuration is given, candidates will run concurrently. If a candidate panics, your application will not panic, but the candidate will be marked as failed. If the name is control, this will error and not add the candidate.
func (*Experiment) Clean ¶
func (e *Experiment) Clean(fnc CleanFunc)
Clean will cleanup the state of a candidate (control included). This is done so the state could be cleaned up before storing for later comparison.
func (*Experiment) Compare ¶
func (e *Experiment) Compare(fnc CompareFunc)
Compare represents the comparison functionality between a control and a candidate.
func (*Experiment) Control ¶
func (e *Experiment) Control(fnc CandidateFunc)
Control represents the control function, this resembles the old or current implementation. This function will always run, regardless of the configuration percentage or overwrites. If this function panics, the application will panic. The output of this function will be the base to what all the candidates will be compared to.
func (*Experiment) Force ¶
func (e *Experiment) Force(f bool)
Force lets you overwrite the percentage. If set to true, the candidates will definitely run.
func (*Experiment) Ignore ¶
func (e *Experiment) Ignore(i bool)
Ignore lets you decide if the experiment should be ignored this run or not. If set to true, the candidates will not run.
func (*Experiment) Run ¶
func (e *Experiment) Run() (interface{}, error)
Run runs all the candidates and control in a random order. The value of the control function will be returned. If the concurrency configuration is given, this will return as soon as the control has finished running.
type Observation ¶
type Observation struct { Duration time.Duration Error error Success bool Name string Panic interface{} Value interface{} CleanValue interface{} }
Observation represents the outcome of a candidate that has run.
type Publisher ¶
type Publisher interface {
Publish(Observation)
}
Publisher represents an interface that allows you to publish results.