Lay out the structure of nettests

This commit is contained in:
Arturo Filastò
2018-02-13 11:48:46 +02:00
parent 6586166282
commit 7cf5bd2718
8 changed files with 126 additions and 5 deletions
+28
View File
@@ -0,0 +1,28 @@
package groups
import (
"github.com/openobservatory/gooni/nettests"
"github.com/openobservatory/gooni/nettests/websites"
)
// NettestGroups that can be run by the user
var NettestGroups = map[string]nettests.NettestGroup{
"websites": nettests.NettestGroup{
Label: "Websites",
Nettests: []nettests.Nettest{
websites.WebConnectivity{},
},
},
"performance": nettests.NettestGroup{
Label: "Performance",
Nettests: []nettests.Nettest{},
},
"middleboxes": nettests.NettestGroup{
Label: "Middleboxes",
Nettests: []nettests.Nettest{},
},
"im": nettests.NettestGroup{
Label: "Instant Messaging",
Nettests: []nettests.Nettest{},
},
}
+57
View File
@@ -0,0 +1,57 @@
package nettests
import (
"github.com/apex/log"
"github.com/measurement-kit/go-measurement-kit"
ooni "github.com/openobservatory/gooni"
"github.com/openobservatory/gooni/internal/database"
)
// Nettest interface. Every Nettest should implement this.
type Nettest interface {
Run(*Controller) error
Summary(*database.Measurement) string
LogSummary(string) error
}
// NettestGroup base structure
type NettestGroup struct {
Label string
Nettests []Nettest
Summary func(s string) string
}
// Controller is passed to the run method of every Nettest
type Controller struct {
ctx *ooni.Context
}
// New Nettest Controller
func (c *Controller) New(ctx *ooni.Context) *Controller {
return &Controller{
ctx,
}
}
// Init should be called once to initialise the nettest
func (c *Controller) Init(nt *mk.Nettest) {
log.Debugf("Init: %s", nt)
}
// OnProgress should be called when a new progress event is available.
func (c *Controller) OnProgress(perc float32, msg string) {
log.Debugf("OnProgress: %f - %s", perc, msg)
}
// OnEntry should be called every time there is a new entry
func (c *Controller) OnEntry(entry string) {
log.Debugf("OnEntry: %s", entry)
}
// MKStart is the interface for the mk.Nettest Start() function
type MKStart func(name string) (chan bool, error)
// Start should be called every time there is a new entry
func (c *Controller) Start(f MKStart) {
log.Debugf("MKStart: %s", f)
}
+25
View File
@@ -0,0 +1,25 @@
package websites
import (
"github.com/openobservatory/gooni/internal/database"
"github.com/openobservatory/gooni/nettests"
)
// WebConnectivity test implementation
type WebConnectivity struct {
}
// Run starts the test
func (n WebConnectivity) Run(ctl *nettests.Controller) error {
return nil
}
// Summary generates a summary for a test run
func (n WebConnectivity) Summary(m *database.Measurement) string {
return ""
}
// LogSummary writes the summary to the standard output
func (n WebConnectivity) LogSummary(s string) error {
return nil
}