connectivity/testing/launch_tor_integration_test.go

32 lines
941 B
Go

package testing
import (
"git.openprivacy.ca/openprivacy/connectivity/tor"
"git.openprivacy.ca/openprivacy/log"
"os"
"path"
"testing"
)
func TestLaunchTor(t *testing.T) {
log.SetLevel(log.LevelDebug)
// Create the tor data directory if it doesn't already exist..
os.MkdirAll("../tmp/data/tor", 0700)
err := tor.GenerateTorrc("examplehashedpassword", "../tmp/data/tor/torrc")
if err != nil {
t.Fatalf("failed to create torrc file: %v", err)
}
// Get the current working director, clean the paths to remove relative references
wd, _ := os.Getwd()
t.Logf("Launching bundled tor at %v", path.Clean(wd+"/../tmp/tor"))
acn, err := tor.NewTorACNWithAuth(path.Clean(wd+"/../tmp/data"), path.Clean(wd+"/../tmp/tor"), 9051, tor.HashedPasswordAuthenticator{Password: "examplehashedpassword"})
if err != nil {
t.Fatalf("tor failed to start: %v", err)
}
acn.WaitTillBootstrapped()
t.Log("we have bootstrapped!")
acn.Close()
}