ooni-probe-cli/internal/nettests/nettests_test.go

53 lines
1.2 KiB
Go
Raw Normal View History

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"
"github.com/ooni/probe-cli/internal/utils/shutil"
2019-12-02 16:57:55 +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")
testingConfig := path.Join("..", "..", "testdata", "testing-config.json")
2019-12-02 16:57:55 +01:00
shutil.Copy(testingConfig, configPath, false)
probe := ooni.NewProbe(configPath, homePath)
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
err = probe.Init(swName, swVersion)
2019-12-02 16:57:55 +01:00
if err != nil {
t.Fatal(err)
}
return probe
2019-12-02 16:57:55 +01:00
}
func TestCreateContext(t *testing.T) {
newOONIProbe(t)
2019-12-02 16:57:55 +01:00
}
func TestRun(t *testing.T) {
probe := newOONIProbe(t)
sess, err := probe.NewSession()
if err != nil {
t.Fatal(err)
}
network, err := database.CreateNetwork(probe.DB, sess)
2019-12-02 16:57:55 +01:00
if err != nil {
t.Fatal(err)
}
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{}
ctl := NewController(nt, probe, res, sess)
2019-12-02 16:57:55 +01:00
nt.Run(ctl)
}