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

Method TestSendRequest

credentials/sts/sts_test.go:646–704  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

644}
645
646func (s) TestSendRequest(t *testing.T) {
647 defer overrideSubjectTokenGood()()
648 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
649 defer cancel()
650 req, err := constructRequest(ctx, goodOptions)
651 if err != nil {
652 t.Fatal(err)
653 }
654
655 tests := []struct {
656 name string
657 resp *http.Response
658 respErr error
659 wantErr bool
660 }{
661 {
662 name: "client error",
663 respErr: errors.New("http.Client.Do failed"),
664 wantErr: true,
665 },
666 {
667 name: "bad response body",
668 resp: &http.Response{
669 Status: "200 OK",
670 StatusCode: http.StatusOK,
671 Body: io.NopCloser(errReader{}),
672 },
673 wantErr: true,
674 },
675 {
676 name: "nonOK status code",
677 resp: &http.Response{
678 Status: "400 BadRequest",
679 StatusCode: http.StatusBadRequest,
680 Body: io.NopCloser(strings.NewReader("")),
681 },
682 wantErr: true,
683 },
684 {
685 name: "good case",
686 resp: makeGoodResponse(),
687 },
688 }
689
690 for _, test := range tests {
691 t.Run(test.name, func(t *testing.T) {
692 client := &testutils.FakeHTTPClient{
693 ReqChan: testutils.NewChannel(),
694 RespChan: testutils.NewChannel(),
695 Err: test.respErr,
696 }
697 client.RespChan.Send(test.resp)
698 _, err := sendRequest(client, req)
699 if (err != nil) != test.wantErr {
700 t.Errorf("sendRequest(%v) = %v, wantErr: %v", req, err, test.wantErr)
701 }
702 })
703 }

Callers

nothing calls this directly

Calls 8

NewChannelFunction · 0.92
overrideSubjectTokenGoodFunction · 0.85
constructRequestFunction · 0.85
makeGoodResponseFunction · 0.85
sendRequestFunction · 0.85
FatalMethod · 0.65
SendMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected