aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-02-16 17:12:35 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-02-16 17:12:35 +0100
commit2c30880ae2fe590c82d581461b23cf59ec2ff83b (patch)
treef5a1cd70d49b53375ba94f4378b72e49cf1e787b
parentea24c3530752373890b9cdfc23b44d76a9817fa9 (diff)
downloadgo-schwift-2c30880ae2fe590c82d581461b23cf59ec2ff83b.tar.gz
add useProxy() helper function for tests
-rw-r--r--shared_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared_test.go b/shared_test.go
index 1e7130e..ba05453 100644
--- a/shared_test.go
+++ b/shared_test.go
@@ -22,6 +22,8 @@ import (
"crypto/rand"
"encoding/hex"
"math"
+ "net/http"
+ "net/url"
"os"
"testing"
@@ -30,6 +32,23 @@ import (
"github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth"
)
+//This function can be used during debugging to redirect the HTTP requests for
+//a specific unit test through a mitmproxy. Put this at the beginning of your
+//testcase like so:
+//
+// testWithAccount(t, func(a *Account) {
+// useProxy(a, "http://localhost:8888")
+// ...
+//
+// testWithContainer(t, func(c *Container) {
+// useProxy(c.Account(), "http://localhost:8888")
+// ...
+func useProxy(a *Account, proxyURL string) {
+ t := *(http.DefaultTransport.(*http.Transport))
+ t.Proxy = func(*http.Request) (*url.URL, error) { return url.Parse(proxyURL) }
+ a.client.ProviderClient.HTTPClient.Transport = &t
+}
+
func testWithAccount(t *testing.T, testCode func(a *Account)) {
stAuth := os.Getenv("ST_AUTH")
stUser := os.Getenv("ST_USER")