Index: server/auth/delegation/minter_test.go |
diff --git a/server/auth/delegation/minter_test.go b/server/auth/delegation/minter_test.go |
index 07f49ff0744477545a10f0459d0231c3605b11cd..3632a6f80b06540d3b9457399c92270f1b5be3b5 100644 |
--- a/server/auth/delegation/minter_test.go |
+++ b/server/auth/delegation/minter_test.go |
@@ -5,8 +5,6 @@ |
package delegation |
import ( |
- "bytes" |
- "io/ioutil" |
"net/http" |
"testing" |
"time" |
@@ -36,11 +34,15 @@ func TestCreateToken(t *testing.T) { |
Intent: "intent", |
} |
- ctx, tr := withTestTransport(ctx, `{ |
- "delegation_token": "tok", |
- "validity_duration": 3600, |
- "subtoken_id": "123" |
- }`) |
+ lastRequestBody := "" |
+ ctx = internal.WithTestTransport(ctx, func(r *http.Request, body string) (int, string) { |
+ lastRequestBody = body |
+ return 200, `{ |
+ "delegation_token": "tok", |
+ "validity_duration": 3600, |
+ "subtoken_id": "123" |
+ }` |
+ }) |
Convey("Works", t, func() { |
tok, err := CreateToken(ctx, goodReq) |
@@ -50,7 +52,7 @@ func TestCreateToken(t *testing.T) { |
SubtokenID: "123", |
Expiry: testclock.TestRecentTimeUTC.Add(time.Hour), |
}) |
- So(tr.request, ShouldEqual, |
+ So(lastRequestBody, ShouldEqual, |
`{"audience":["user:a@example.com","group:group"],`+ |
`"services":["service:abc"],"validity_duration":3600,`+ |
`"impersonate":"user:b@example.com","intent":"intent"}`) |
@@ -94,35 +96,3 @@ func TestCreateToken(t *testing.T) { |
So(err, ShouldBeNil) |
}) |
} |
- |
-var testTransportKey = "key for testTransport" |
- |
-func withTestTransport(c context.Context, response string) (context.Context, *testTransport) { |
- t := &testTransport{response: response} |
- return context.WithValue(c, &testTransportKey, t), t |
-} |
- |
-type testTransport struct { |
- response string |
- request string |
-} |
- |
-func (f *testTransport) RoundTrip(r *http.Request) (*http.Response, error) { |
- body, err := ioutil.ReadAll(r.Body) |
- r.Body.Close() |
- if err != nil { |
- return nil, err |
- } |
- f.request = string(body) |
- return &http.Response{ |
- StatusCode: 200, |
- Status: "OK", |
- Body: ioutil.NopCloser(bytes.NewReader([]byte(f.response))), |
- }, nil |
-} |
- |
-func init() { |
- internal.RegisterClientFactory(func(c context.Context, scopes []string) (*http.Client, error) { |
- return &http.Client{Transport: c.Value(&testTransportKey).(*testTransport)}, nil |
- }) |
-} |