ooni-probe-cli/nettests/nettests_test.go
Simone Basso 1e8b482c23
Allow to specify custom software name and version (#94)
In turn, this allows us to identify as ooniprobe-cli v3.0.0-rc.5.

Closes #41.
2019-12-29 14:07:57 +01:00

49 lines
1.1 KiB
Go

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)
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
err = ctx.Init(swName, swVersion)
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, "middlebox", network.ID)
if err != nil {
t.Fatal(err)
}
nt := HTTPInvalidRequestLine{}
ctl := NewController(nt, ctx, res)
nt.Run(ctl)
}