Refactor nettests into top tree
This commit is contained in:
parent
d6d2490d2c
commit
b20af107dc
8 changed files with 102 additions and 66 deletions
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)
|
||||
}
|
||||
Loading…
Reference in a new issue