| 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 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/" |
| 6 | "io/ioutilscip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/" |
| 7 | "net/httpscip-go gomod github.com/golang/go/src go1.15 `net/http`/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.15 testing/" |
| 9 | "timescip-go gomod github.com/golang/go/src go1.15 time/" |
| 10 | |
| 11 | "github.com/cretz/bine/torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/" |
| 12 | "golang.org/x/net/context/ctxhttpscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/context/ctxhttp`/" |
| 13 | ) |
| 14 | |
| 15 | func TestDialerSimpleHTTPscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestDialerSimpleHTTP().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 16 | ctx := GlobalEnabledNetworkContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/GlobalEnabledNetworkContext().(t) |
| 17 | httpClient := httpClientscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpClient().(ctx, nil) |
| 18 | // IsTor check |
| 19 | byts := httpGetscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpGet().(ctx, httpClient, "https://check.torproject.org/api/ip") |
| 20 | jsn := map[string]interface{}{} |
| 21 | 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().(jsonscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.15 `encoding/json`/Unmarshal().(byts, &jsn)) |
| 22 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Truescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#True().(jsn["IsTor"].(bool)) |
| 23 | } |
| 24 | |
| 25 | func httpClientscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpClient().(ctx *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#, conf *torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.DialConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/DialConf#) *httpscip-go gomod github.com/golang/go/src go1.15 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.15 `net/http`/Client# { |
| 26 | // 15 seconds max to dial |
| 27 | dialCtx, dialCancel := contextscip-go gomod github.com/golang/go/src go1.15 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.15 context/WithTimeout().(ctx, 15*timescip-go gomod github.com/golang/go/src go1.15 time/.Secondscip-go gomod github.com/golang/go/src go1.15 time/Second.) |
| 28 | defer dialCancel() |
| 29 | // Make connection |
| 30 | dialer, err := ctx.Dialerscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Dialer().(dialCtx, conf) |
| 31 | 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().(err) |
| 32 | return &httpscip-go gomod github.com/golang/go/src go1.15 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.15 `net/http`/Client#{Transportscip-go gomod github.com/golang/go/src go1.15 `net/http`/Client#Transport.: &httpscip-go gomod github.com/golang/go/src go1.15 `net/http`/.Transportscip-go gomod github.com/golang/go/src go1.15 `net/http`/Transport#{DialContextscip-go gomod github.com/golang/go/src go1.15 `net/http`/Transport#DialContext.: dialer.DialContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Dialer#DialContext().}} |
| 33 | } |
| 34 | |
| 35 | func httpGetscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpGet().(ctx *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#, client *httpscip-go gomod github.com/golang/go/src go1.15 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.15 `net/http`/Client#, url string) []byte { |
| 36 | // We'll give it 30 seconds to respond |
| 37 | callCtx, callCancel := contextscip-go gomod github.com/golang/go/src go1.15 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.15 context/WithTimeout().(ctx, 30*timescip-go gomod github.com/golang/go/src go1.15 time/.Secondscip-go gomod github.com/golang/go/src go1.15 time/Second.) |
| 38 | defer callCancel() |
| 39 | resp, err := ctxhttpscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/context/ctxhttp`/.Getscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/context/ctxhttp`/Get().(callCtx, client, url) |
| 40 | 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().(err) |
| 41 | defer resp.Bodyscip-go gomod github.com/golang/go/src go1.15 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.15 io/Closer#Close().() |
| 42 | respBytes, err := ioutilscip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/.ReadAllscip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/ReadAll().(resp.Bodyscip-go gomod github.com/golang/go/src go1.15 `net/http`/Response#Body.) |
| 43 | 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().(err) |
| 44 | return respBytes |
| 45 | } |