MCPcopy
hub / github.com/grpc/grpc-go / compareRequest

Function compareRequest

credentials/sts/sts_test.go:193–216  ·  view source on GitHub ↗

compareRequest compares the http.Request received in the test with the expected requestParameters specified in wantReqParams.

(gotRequest *http.Request, wantReqParams *requestParameters)

Source from the content-addressed store, hash-verified

191// compareRequest compares the http.Request received in the test with the
192// expected requestParameters specified in wantReqParams.
193func compareRequest(gotRequest *http.Request, wantReqParams *requestParameters) error {
194 jsonBody, err := json.Marshal(wantReqParams)
195 if err != nil {
196 return err
197 }
198 wantReq, err := http.NewRequest("POST", serviceURI, bytes.NewBuffer(jsonBody))
199 if err != nil {
200 return fmt.Errorf("failed to create http request: %v", err)
201 }
202 wantReq.Header.Set("Content-Type", "application/json")
203
204 wantR, err := httputil.DumpRequestOut(wantReq, true)
205 if err != nil {
206 return err
207 }
208 gotR, err := httputil.DumpRequestOut(gotRequest, true)
209 if err != nil {
210 return err
211 }
212 if diff := cmp.Diff(string(wantR), string(gotR)); diff != "" {
213 return fmt.Errorf("sts request diff (-want +got):\n%s", diff)
214 }
215 return nil
216}
217
218// receiveAndCompareRequest waits for a request to be sent out by the
219// credentials implementation using the fakeHTTPClient and compares it to an

Callers 2

receiveAndCompareRequestFunction · 0.85
TestConstructRequestMethod · 0.85

Calls 3

MarshalMethod · 0.65
ErrorfMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected