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

53 lines
1.1 KiB
Go
Raw Normal View History

2019-12-02 16:57:55 +01:00
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")
2019-12-02 16:57:55 +01:00
shutil.Copy(testingConfig, configPath, false)
ctx := ooni.NewContext(configPath, homePath)
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
err = ctx.Init(swName, swVersion)
2019-12-02 16:57:55 +01:00
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)
2019-12-02 16:57:55 +01:00
if err != nil {
t.Fatal(err)
}
2019-12-02 17:00:12 +01:00
res, err := database.CreateResult(ctx.DB, ctx.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, ctx, res, sess)
2019-12-02 16:57:55 +01:00
nt.Run(ctl)
}