forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
experimentbuilder.go
75 lines (62 loc) · 2.1 KB
/
experimentbuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package engine
//
// ExperimentBuilder definition and implementation
//
import (
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/registry"
)
// experimentBuilder implements ExperimentBuilder.
//
// This type is now just a tiny wrapper around registry.Factory.
type experimentBuilder struct {
factory *registry.Factory
// callbacks contains callbacks for the new experiment.
callbacks model.ExperimentCallbacks
// session is the session
session *Session
}
// Interruptible implements ExperimentBuilder.Interruptible.
func (b *experimentBuilder) Interruptible() bool {
return b.factory.Interruptible()
}
// InputPolicy implements ExperimentBuilder.InputPolicy.
func (b *experimentBuilder) InputPolicy() model.InputPolicy {
return b.factory.InputPolicy()
}
// Options implements ExperimentBuilder.Options.
func (b *experimentBuilder) Options() (map[string]model.ExperimentOptionInfo, error) {
return b.factory.Options()
}
// SetOptionAny implements ExperimentBuilder.SetOptionAny.
func (b *experimentBuilder) SetOptionAny(key string, value any) error {
return b.factory.SetOptionAny(key, value)
}
// SetOptionsAny implements ExperimentBuilder.SetOptionsAny.
func (b *experimentBuilder) SetOptionsAny(options map[string]any) error {
return b.factory.SetOptionsAny(options)
}
// SetCallbacks implements ExperimentBuilder.SetCallbacks.
func (b *experimentBuilder) SetCallbacks(callbacks model.ExperimentCallbacks) {
b.callbacks = callbacks
}
// NewExperiment creates the experiment
func (b *experimentBuilder) NewExperiment() model.Experiment {
measurer := b.factory.NewExperimentMeasurer()
experiment := newExperiment(b.session, measurer)
experiment.callbacks = b.callbacks
return experiment
}
// newExperimentBuilder creates a new experimentBuilder instance.
func newExperimentBuilder(session *Session, name string) (*experimentBuilder, error) {
factory, err := registry.NewFactory(name)
if err != nil {
return nil, err
}
builder := &experimentBuilder{
factory: factory,
callbacks: model.NewPrinterCallbacks(session.Logger()),
session: session,
}
return builder, nil
}