Lay out the structure of nettests
This commit is contained in:
parent
6586166282
commit
7cf5bd2718
8
Gopkg.lock
generated
8
Gopkg.lock
generated
|
@ -82,6 +82,12 @@
|
|||
revision = "3247c84500bff8d9fb6d579d800f20b3e091582c"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/measurement-kit/go-measurement-kit"
|
||||
packages = ["."]
|
||||
revision = "93d8ecd6537d99a83845a9e6928dfd27b665ad6a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mgutz/ansi"
|
||||
|
@ -168,6 +174,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "d1ff03c816b12576a88c6ab2c3ffab44bf0fd40a67d765965f06fd9ac9e58d99"
|
||||
inputs-digest = "348ea586d927a4a6ce2aef27d7734ba88a12917b9b074ae2d41b229731c9bc33"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -52,3 +52,7 @@
|
|||
[[constraint]]
|
||||
name = "github.com/apex/log"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/measurement-kit/go-measurement-kit"
|
||||
|
|
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ GO ?= go
|
|||
|
||||
build:
|
||||
@echo "Building ./ooni"
|
||||
@$(GO) build -o ooni cmd/ooni/main.go
|
||||
@$(GO) build -i -o ooni cmd/ooni/main.go
|
||||
.PHONY: build
|
||||
|
||||
bindata:
|
||||
|
|
|
@ -44,7 +44,7 @@ func init() {
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
dbPath, err := DefaultDatabasePath()
|
||||
dbPath, err := database.DefaultDatabasePath()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/apex/log"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
ooni "github.com/openobservatory/gooni"
|
||||
"github.com/openobservatory/gooni/internal/bindata"
|
||||
"github.com/pkg/errors"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
|
@ -36,9 +37,9 @@ func Connect(path string) (*sqlx.DB, error) {
|
|||
}
|
||||
|
||||
func DefaultDatabasePath() (string, error) {
|
||||
home, err := GetOONIHome()
|
||||
home, err := ooni.GetOONIHome()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "default database path")
|
||||
return "", errors.Wrap(err, "default database path")
|
||||
}
|
||||
return filepath.Join(home, "db", "main.db"), nil
|
||||
}
|
||||
|
|
28
nettests/groups/groups.go
Normal file
28
nettests/groups/groups.go
Normal 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
nettests/nettests.go
Normal file
57
nettests/nettests.go
Normal 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
nettests/websites/web_connectivity.go
Normal file
25
nettests/websites/web_connectivity.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user