| 148 | } |
| 149 | |
| 150 | func (s) TestCallCredsFromDialOptionsStatusCodes(t *testing.T) { |
| 151 | testCases := []struct { |
| 152 | name string |
| 153 | credsErr error |
| 154 | want error |
| 155 | }{{ |
| 156 | name: "legal status code", |
| 157 | credsErr: status.Errorf(codes.Unavailable, "this error is fine"), |
| 158 | want: status.Errorf(codes.Unavailable, "this error is fine"), |
| 159 | }, { |
| 160 | name: "illegal status code", |
| 161 | credsErr: status.Errorf(codes.NotFound, "this error is bad"), |
| 162 | want: status.Errorf(codes.Internal, "this error is bad"), |
| 163 | }} |
| 164 | |
| 165 | for _, tc := range testCases { |
| 166 | t.Run(tc.name, func(t *testing.T) { |
| 167 | ss := &stubserver.StubServer{ |
| 168 | EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { |
| 169 | return &testpb.Empty{}, nil |
| 170 | }, |
| 171 | } |
| 172 | |
| 173 | errChan := make(chan error, 1) |
| 174 | creds := &testPerRPCCredentials{errChan: errChan} |
| 175 | |
| 176 | if err := ss.Start(nil, grpc.WithPerRPCCredentials(creds)); err != nil { |
| 177 | t.Fatalf("Error starting endpoint server: %v", err) |
| 178 | } |
| 179 | defer ss.Stop() |
| 180 | |
| 181 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 182 | defer cancel() |
| 183 | |
| 184 | errChan <- tc.credsErr |
| 185 | |
| 186 | if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != status.Code(tc.want) || !strings.Contains(err.Error(), status.Convert(tc.want).Message()) { |
| 187 | t.Fatalf("client.EmptyCall(_, _) = _, %v; want _, %v", err, tc.want) |
| 188 | } |
| 189 | }) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | func (s) TestCallCredsFromCallOptionsStatusCodes(t *testing.T) { |
| 194 | testCases := []struct { |