2019-12-02 16:57:55 +01:00
|
|
|
package nettests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/internal/database"
|
2020-11-13 18:42:10 +01:00
|
|
|
"github.com/ooni/probe-cli/internal/ooni"
|
2020-11-13 17:28:02 +01:00
|
|
|
"github.com/ooni/probe-cli/internal/utils/shutil"
|
2019-12-02 16:57:55 +01:00
|
|
|
)
|
|
|
|
|
2020-11-13 19:01:06 +01:00
|
|
|
func newOONIProbe(t *testing.T) *ooni.Probe {
|
2019-12-02 16:57:55 +01:00
|
|
|
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)
|
2020-11-13 19:01:06 +01:00
|
|
|
probe := ooni.NewProbe(configPath, homePath)
|
2019-12-29 14:07:57 +01:00
|
|
|
swName := "ooniprobe-cli-tests"
|
|
|
|
swVersion := "3.0.0-alpha"
|
2020-11-13 19:01:06 +01:00
|
|
|
err = probe.Init(swName, swVersion)
|
2019-12-02 16:57:55 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-11-13 19:01:06 +01:00
|
|
|
return probe
|
2019-12-02 16:57:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateContext(t *testing.T) {
|
2020-11-13 19:01:06 +01:00
|
|
|
newOONIProbe(t)
|
2019-12-02 16:57:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRun(t *testing.T) {
|
2020-11-13 19:01:06 +01:00
|
|
|
probe := newOONIProbe(t)
|
|
|
|
sess, err := probe.NewSession()
|
2020-06-04 11:19:38 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-11-13 20:07:30 +01:00
|
|
|
network, err := database.CreateNetwork(probe.DB(), sess)
|
2019-12-02 16:57:55 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-11-13 20:07:30 +01:00
|
|
|
res, err := database.CreateResult(probe.DB(), probe.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-11-13 19:01:06 +01:00
|
|
|
ctl := NewController(nt, probe, res, sess)
|
2019-12-02 16:57:55 +01:00
|
|
|
nt.Run(ctl)
|
|
|
|
}
|