Refactor nettests into top tree
This commit is contained in:
parent
d6d2490d2c
commit
b20af107dc
@ -1,9 +1,7 @@
|
|||||||
package performance
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dash test implementation
|
// Dash test implementation
|
||||||
@ -11,7 +9,7 @@ type Dash struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (d Dash) Run(ctl *nettests.Controller) error {
|
func (d Dash) Run(ctl *Controller) error {
|
||||||
builder, err := ctl.Ctx.Session.NewExperimentBuilder("dash")
|
builder, err := ctl.Ctx.Session.NewExperimentBuilder("dash")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
39
nettests/groups.go
Normal file
39
nettests/groups.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package nettests
|
||||||
|
|
||||||
|
// NettestGroup base structure
|
||||||
|
type NettestGroup struct {
|
||||||
|
Label string
|
||||||
|
Nettests []Nettest
|
||||||
|
}
|
||||||
|
|
||||||
|
// NettestGroups that can be run by the user
|
||||||
|
var NettestGroups = map[string]NettestGroup{
|
||||||
|
"websites": NettestGroup{
|
||||||
|
Label: "Websites",
|
||||||
|
Nettests: []Nettest{
|
||||||
|
WebConnectivity{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"performance": NettestGroup{
|
||||||
|
Label: "Performance",
|
||||||
|
Nettests: []Nettest{
|
||||||
|
Dash{},
|
||||||
|
NDT{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"middlebox": NettestGroup{
|
||||||
|
Label: "Middleboxes",
|
||||||
|
Nettests: []Nettest{
|
||||||
|
HTTPInvalidRequestLine{},
|
||||||
|
HTTPHeaderFieldManipulation{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"im": NettestGroup{
|
||||||
|
Label: "Instant Messaging",
|
||||||
|
Nettests: []Nettest{
|
||||||
|
FacebookMessenger{},
|
||||||
|
Telegram{},
|
||||||
|
WhatsApp{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
package groups
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
"github.com/ooni/probe-cli/nettests/im"
|
|
||||||
"github.com/ooni/probe-cli/nettests/middlebox"
|
|
||||||
"github.com/ooni/probe-cli/nettests/performance"
|
|
||||||
"github.com/ooni/probe-cli/nettests/websites"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NettestGroup base structure
|
|
||||||
type NettestGroup struct {
|
|
||||||
Label string
|
|
||||||
Nettests []nettests.Nettest
|
|
||||||
}
|
|
||||||
|
|
||||||
// NettestGroups that can be run by the user
|
|
||||||
var NettestGroups = map[string]NettestGroup{
|
|
||||||
"websites": NettestGroup{
|
|
||||||
Label: "Websites",
|
|
||||||
Nettests: []nettests.Nettest{
|
|
||||||
websites.WebConnectivity{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"performance": NettestGroup{
|
|
||||||
Label: "Performance",
|
|
||||||
Nettests: []nettests.Nettest{
|
|
||||||
performance.Dash{},
|
|
||||||
performance.NDT{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"middlebox": NettestGroup{
|
|
||||||
Label: "Middleboxes",
|
|
||||||
Nettests: []nettests.Nettest{
|
|
||||||
middlebox.HTTPInvalidRequestLine{},
|
|
||||||
middlebox.HTTPHeaderFieldManipulation{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"im": NettestGroup{
|
|
||||||
Label: "Instant Messaging",
|
|
||||||
Nettests: []nettests.Nettest{
|
|
||||||
im.FacebookMessenger{},
|
|
||||||
im.Telegram{},
|
|
||||||
im.WhatsApp{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,9 +1,7 @@
|
|||||||
package middlebox
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPHeaderFieldManipulation test implementation
|
// HTTPHeaderFieldManipulation test implementation
|
||||||
@ -11,7 +9,7 @@ type HTTPHeaderFieldManipulation struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (h HTTPHeaderFieldManipulation) Run(ctl *nettests.Controller) error {
|
func (h HTTPHeaderFieldManipulation) Run(ctl *Controller) error {
|
||||||
builder, err := ctl.Ctx.Session.NewExperimentBuilder(
|
builder, err := ctl.Ctx.Session.NewExperimentBuilder(
|
||||||
"http_header_field_manipulation",
|
"http_header_field_manipulation",
|
||||||
)
|
)
|
@ -1,9 +1,7 @@
|
|||||||
package middlebox
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPInvalidRequestLine test implementation
|
// HTTPInvalidRequestLine test implementation
|
||||||
@ -11,7 +9,7 @@ type HTTPInvalidRequestLine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (h HTTPInvalidRequestLine) Run(ctl *nettests.Controller) error {
|
func (h HTTPInvalidRequestLine) Run(ctl *Controller) error {
|
||||||
builder, err := ctl.Ctx.Session.NewExperimentBuilder(
|
builder, err := ctl.Ctx.Session.NewExperimentBuilder(
|
||||||
"http_invalid_request_line",
|
"http_invalid_request_line",
|
||||||
)
|
)
|
@ -1,7 +1,6 @@
|
|||||||
package performance
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,7 +9,7 @@ type NDT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (n NDT) Run(ctl *nettests.Controller) error {
|
func (n NDT) Run(ctl *Controller) error {
|
||||||
builder, err := ctl.Ctx.Session.NewExperimentBuilder("ndt")
|
builder, err := ctl.Ctx.Session.NewExperimentBuilder("ndt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
52
nettests/nettests_test.go
Normal file
52
nettests/nettests_test.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package nettests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
ooni "github.com/ooni/probe-cli"
|
||||||
|
"github.com/ooni/probe-cli/internal/database"
|
||||||
|
"github.com/ooni/probe-cli/utils/shutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newTestingContext(t *testing.T) *ooni.Context {
|
||||||
|
homePath, err := ioutil.TempDir("", "ooniprobetests")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
configPath := path.Join(homePath, "config.json")
|
||||||
|
testingConfig := path.Join("..", "testdata", "testing-config.json")
|
||||||
|
shutil.Copy(testingConfig, configPath, false)
|
||||||
|
ctx := ooni.NewContext(configPath, homePath)
|
||||||
|
err = ctx.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateContext(t *testing.T) {
|
||||||
|
newTestingContext(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRun(t *testing.T) {
|
||||||
|
ctx := newTestingContext(t)
|
||||||
|
network, err := database.CreateNetwork(ctx.DB, ctx.Session)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
res, err := database.CreateResult(ctx.DB, ctx.Home, tg, network.ID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
builder, err := ctl.Ctx.Session.NewExperimentBuilder(
|
||||||
|
"telegram",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ctl := NewController(nt, ctx, res)
|
||||||
|
ctl.Run(builder, []string{""})
|
||||||
|
nt.Run(ctl)
|
||||||
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package websites
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/ooni/probe-cli/internal/database"
|
"github.com/ooni/probe-cli/internal/database"
|
||||||
"github.com/ooni/probe-cli/nettests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func lookupURLs(ctl *nettests.Controller, limit int64) ([]string, map[int64]int64, error) {
|
func lookupURLs(ctl *Controller, limit int64) ([]string, map[int64]int64, error) {
|
||||||
var urls []string
|
var urls []string
|
||||||
urlIDMap := make(map[int64]int64)
|
urlIDMap := make(map[int64]int64)
|
||||||
config := ctl.Ctx.Session.NewTestListsConfig()
|
config := ctl.Ctx.Session.NewTestListsConfig()
|
||||||
@ -37,7 +36,7 @@ type WebConnectivity struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (n WebConnectivity) Run(ctl *nettests.Controller) error {
|
func (n WebConnectivity) Run(ctl *Controller) error {
|
||||||
urls, urlIDMap, err := lookupURLs(ctl, ctl.Ctx.Config.Nettests.WebsitesURLLimit)
|
urls, urlIDMap, err := lookupURLs(ctl, ctl.Ctx.Config.Nettests.WebsitesURLLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
Loading…
x
Reference in New Issue
Block a user