-
Notifications
You must be signed in to change notification settings - Fork 46
/
run.go
94 lines (85 loc) · 2.73 KB
/
run.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package run
import (
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/fatih/color"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/onboard"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/root"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/nettests"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
)
func init() {
cmd := root.Command("run", "Run a test group or OONI Run link")
noCollector := cmd.Flag("no-collector", "Disable uploading measurements to a collector").Bool()
var probe *ooni.Probe
cmd.Action(func(_ *kingpin.ParseContext) error {
var err error
probe, err = root.Init()
if err != nil {
log.Errorf("%s", err)
return err
}
if err = onboard.MaybeOnboarding(probe); err != nil {
log.WithError(err).Error("failed to perform onboarding")
return err
}
if *noCollector {
probe.Config().Sharing.UploadResults = false
}
return nil
})
functionalRun := func(runType string, pred func(name string, gr nettests.Group) bool) error {
for name, group := range nettests.All {
if !pred(name, group) {
continue
}
log.Infof("Running %s tests", color.BlueString(name))
conf := nettests.RunGroupConfig{
GroupName: name,
Probe: probe,
RunType: runType,
}
if err := nettests.RunGroup(conf); err != nil {
log.WithError(err).Errorf("failed to run %s", name)
}
}
return nil
}
genRunWithGroupName := func(targetName string) func(*kingpin.ParseContext) error {
return func(*kingpin.ParseContext) error {
return functionalRun("manual", func(groupName string, gr nettests.Group) bool {
return groupName == targetName
})
}
}
websitesCmd := cmd.Command("websites", "")
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
log.Infof("Running %s tests", color.BlueString("websites"))
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "websites",
Probe: probe,
InputFiles: *inputFile,
Inputs: *input,
RunType: "manual",
})
})
easyRuns := []string{
"im", "performance", "circumvention", "middlebox", "experimental"}
for _, name := range easyRuns {
cmd.Command(name, "").Action(genRunWithGroupName(name))
}
unattendedCmd := cmd.Command("unattended", "")
unattendedCmd.Action(func(_ *kingpin.ParseContext) error {
return functionalRun("timed", func(name string, gr nettests.Group) bool {
return gr.UnattendedOK
})
})
allCmd := cmd.Command("all", "").Default()
allCmd.Action(func(_ *kingpin.ParseContext) error {
return functionalRun("manual", func(name string, gr nettests.Group) bool {
return true
})
})
}