| 1 | package testsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.15 context/" |
| 5 | "flagscip-go gomod github.com/golang/go/src go1.15 flag/" |
| 6 | "osscip-go gomod github.com/golang/go/src go1.15 os/" |
| 7 | "testingscip-go gomod github.com/golang/go/src go1.15 testing/" |
| 8 | "timescip-go gomod github.com/golang/go/src go1.15 time/" |
| 9 | |
| 10 | "github.com/cretz/bine/torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/" |
| 11 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/" |
| 12 | ) |
| 13 | |
| 14 | var torEnabledscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torEnabled. bool |
| 15 | var torExePathscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torExePath. string |
| 16 | var torVerbosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torVerbose. bool |
| 17 | var torIncludeNetworkTestsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torIncludeNetworkTests. bool |
| 18 | var globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext. *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext# |
| 19 | |
| 20 | func TestMainscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestMain().(m *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Mscip-go gomod github.com/golang/go/src go1.15 testing/M#) { |
| 21 | flagscip-go gomod github.com/golang/go/src go1.15 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.15 flag/BoolVar().(&torEnabledscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torEnabled., "tor", false, "Whether any of the integration tests are enabled") |
| 22 | flagscip-go gomod github.com/golang/go/src go1.15 flag/.StringVarscip-go gomod github.com/golang/go/src go1.15 flag/StringVar().(&torExePathscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torExePath., "tor.path", "tor", "The Tor exe path") |
| 23 | flagscip-go gomod github.com/golang/go/src go1.15 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.15 flag/BoolVar().(&torVerbosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torVerbose., "tor.verbose", false, "Show verbose test info") |
| 24 | flagscip-go gomod github.com/golang/go/src go1.15 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.15 flag/BoolVar().(&torIncludeNetworkTestsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torIncludeNetworkTests., "tor.network", false, "Include network tests") |
| 25 | flagscip-go gomod github.com/golang/go/src go1.15 flag/.Parsescip-go gomod github.com/golang/go/src go1.15 flag/Parse().() |
| 26 | exitCode := m.Runscip-go gomod github.com/golang/go/src go1.15 testing/M#Run().() |
| 27 | if globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext. != nil { |
| 28 | globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext..CloseTorOnClosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#CloseTorOnClose. = true |
| 29 | globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext..Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() |
| 30 | } |
| 31 | osscip-go gomod github.com/golang/go/src go1.15 os/.Exitscip-go gomod github.com/golang/go/src go1.15 os/Exit().(exitCode) |
| 32 | } |
| 33 | |
| 34 | func GlobalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/GlobalEnabledNetworkContext().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext# { |
| 35 | if !torEnabledscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torEnabled. || !torIncludeNetworkTestsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torIncludeNetworkTests. { |
| 36 | t.Skipscip-go gomod github.com/golang/go/src go1.15 testing/common#Skip().("Only runs if -tor and -tor.network are set") |
| 37 | } |
| 38 | if globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext. == nil { |
| 39 | ctx := NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, nil) |
| 40 | ctx.CloseTorOnClosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#CloseTorOnClose. = false |
| 41 | // 45 second wait for enable network |
| 42 | enableCtx, enableCancel := contextscip-go gomod github.com/golang/go/src go1.15 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.15 context/WithTimeout().(ctx, 45*timescip-go gomod github.com/golang/go/src go1.15 time/.Secondscip-go gomod github.com/golang/go/src go1.15 time/Second.) |
| 43 | defer enableCancel() |
| 44 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(ctx.EnableNetworkscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#EnableNetwork().(enableCtx, true)) |
| 45 | globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext. = ctx |
| 46 | } else { |
| 47 | globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext..Tscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#T. = t |
| 48 | globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext..Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require. = requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/New().(t) |
| 49 | } |
| 50 | return globalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/globalEnabledNetworkContext. |
| 51 | } |
| 52 | |
| 53 | type TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext# struct { |
| 54 | contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Context. |
| 55 | *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#T. |
| 56 | *torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.Torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Tor. |
| 57 | Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require. *requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Assertionsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions# |
| 58 | CloseTorOnClosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#CloseTorOnClose. bool |
| 59 | } |
| 60 | |
| 61 | func NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#, conf *torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.StartConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#) *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext# { |
| 62 | if !torEnabledscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torEnabled. { |
| 63 | t.Skipscip-go gomod github.com/golang/go/src go1.15 testing/common#Skip().("Only runs if -tor is set") |
| 64 | } |
| 65 | // Build start conf |
| 66 | if conf == nil { |
| 67 | conf = &torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.StartConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#{} |
| 68 | } |
| 69 | conf.ExePathscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#ExePath. = torExePathscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torExePath. |
| 70 | if torVerbosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/torVerbose. { |
| 71 | conf.DebugWriterscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#DebugWriter. = osscip-go gomod github.com/golang/go/src go1.15 os/.Stdoutscip-go gomod github.com/golang/go/src go1.15 os/Stdout. |
| 72 | conf.NoHushscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#NoHush. = true |
| 73 | } else { |
| 74 | conf.ExtraArgsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#ExtraArgs. = append(conf.ExtraArgsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#ExtraArgs., "--quiet") |
| 75 | } |
| 76 | ret := &TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#{Contextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Context.: contextscip-go gomod github.com/golang/go/src go1.15 context/.Backgroundscip-go gomod github.com/golang/go/src go1.15 context/Background().(), Tscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#T.: t, Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require.: requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/New().(t), CloseTorOnClosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#CloseTorOnClose.: true} |
| 77 | // Start tor |
| 78 | var err error |
| 79 | if ret.Torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Tor., err = torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.Startscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Start().(ret.Contextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Context., conf); err != nil { |
| 80 | defer ret.Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() |
| 81 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().(err) |
| 82 | } |
| 83 | return ret |
| 84 | } |
| 85 | |
| 86 | // Deadline to disambiguate context and test deadline and use test one. |
| 87 | func (t *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#) Deadlinescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Deadline().() (timescip-go gomod github.com/golang/go/src go1.15 time/.Timescip-go gomod github.com/golang/go/src go1.15 time/Time#, bool) { return t.Tscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#T..Deadlinescip-go gomod github.com/golang/go/src go1.15 testing/T#Deadline().() } |
| 88 | |
| 89 | func (t *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#) Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() { |
| 90 | if t.CloseTorOnClosescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#CloseTorOnClose. { |
| 91 | if err := t.Torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Tor..Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Close().(); err != nil { |
| 92 | if t.Failedscip-go gomod github.com/golang/go/src go1.15 testing/common#Failed().() { |
| 93 | t.Logfscip-go gomod github.com/golang/go/src go1.15 testing/common#Logf().("Failure on close: %v", err) |
| 94 | } else { |
| 95 | t.Errorfscip-go gomod github.com/golang/go/src go1.15 testing/common#Errorf().("Failure on close: %v", err) |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |