2019-12-02 16:57:55 +01:00
|
|
|
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")
|
2020-11-13 17:14:26 +01:00
|
|
|
testingConfig := path.Join("..", "..", "testdata", "testing-config.json")
|
2019-12-02 16:57:55 +01:00
|
|
|
shutil.Copy(testingConfig, configPath, false)
|
|
|
|
ctx := ooni.NewContext(configPath, homePath)
|
2019-12-29 14:07:57 +01:00
|
|
|
swName := "ooniprobe-cli-tests"
|
|
|
|
swVersion := "3.0.0-alpha"
|
|
|
|
err = ctx.Init(swName, swVersion)
|
2019-12-02 16:57:55 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateContext(t *testing.T) {
|
|
|
|
newTestingContext(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRun(t *testing.T) {
|
|
|
|
ctx := newTestingContext(t)
|
2020-06-04 11:19:38 +02:00
|
|
|
sess, err := ctx.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
network, err := database.CreateNetwork(ctx.DB, sess)
|
2019-12-02 16:57:55 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-02 17:00:12 +01:00
|
|
|
res, err := database.CreateResult(ctx.DB, ctx.Home, "middlebox", network.ID)
|
2019-12-02 16:57:55 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-02 17:00:12 +01:00
|
|
|
nt := HTTPInvalidRequestLine{}
|
2020-06-04 11:19:38 +02:00
|
|
|
ctl := NewController(nt, ctx, res, sess)
|
2019-12-02 16:57:55 +01:00
|
|
|
nt.Run(ctl)
|
|
|
|
}
|