ooni-probe-cli/internal/nettests/nettests_test.go
Simone Basso c81393b31a
refactor: move ooni into the internal package (#168)
With this commit we've reorganised the package structure. Now I will
go more in depth and perform further refactoring.
2020-11-13 17:47:29 +01:00

53 lines
1.2 KiB
Go

package nettests
import (
"io/ioutil"
"path"
"testing"
"github.com/ooni/probe-cli/internal/ooni"
"github.com/ooni/probe-cli/internal/database"
"github.com/ooni/probe-cli/internal/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)
sess, err := ctx.NewSession()
if err != nil {
t.Fatal(err)
}
network, err := database.CreateNetwork(ctx.DB, sess)
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, sess)
nt.Run(ctl)
}