ooni-probe-cli/cmd/ooniprobe/internal/nettests/nettests_test.go
Simone Basso 1d70b81187
More progress towards release v3.10.0 (#320)
* chore: unvendor github.com/mitchellh/go-wordwrap

The library seems reasonably maintained and tested.

Part of https://github.com/ooni/probe/issues/1439

* fix(netx/quicdialer): ensure we handle all errors

Part of https://github.com/ooni/probe/issues/1439

* fix previous

* cleanup: remove unnecessary shutil fork

Part of https://github.com/ooni/probe/issues/1439

* doc: documented some undocumented functions

Part of https://github.com/ooni/probe/issues/1439

* fix(ooniprobe): rename mis-named function

Part of https://github.com/ooni/probe/issues/1439
2021-04-29 15:59:53 +02:00

63 lines
1.4 KiB
Go

package nettests
import (
"context"
"io/ioutil"
"path"
"testing"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/database"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
)
func copyfile(source, dest string) error {
data, err := ioutil.ReadFile(source)
if err != nil {
return err
}
return ioutil.WriteFile(dest, data, 0600)
}
func newOONIProbe(t *testing.T) *ooni.Probe {
homePath, err := ioutil.TempDir("", "ooniprobetests")
if err != nil {
t.Fatal(err)
}
configPath := path.Join(homePath, "config.json")
testingConfig := path.Join("..", "..", "testdata", "testing-config.json")
if err := copyfile(testingConfig, configPath); err != nil {
t.Fatal(err)
}
probe := ooni.NewProbe(configPath, homePath)
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
err = probe.Init(swName, swVersion)
if err != nil {
t.Fatal(err)
}
return probe
}
func TestCreateContext(t *testing.T) {
newOONIProbe(t)
}
func TestRun(t *testing.T) {
probe := newOONIProbe(t)
sess, err := probe.NewSession(context.Background())
if err != nil {
t.Fatal(err)
}
network, err := database.CreateNetwork(probe.DB(), sess)
if err != nil {
t.Fatal(err)
}
res, err := database.CreateResult(probe.DB(), probe.Home(), "middlebox", network.ID)
if err != nil {
t.Fatal(err)
}
nt := HTTPInvalidRequestLine{}
ctl := NewController(nt, probe, res, sess)
nt.Run(ctl)
}