MCPcopy Create free account
hub / github.com/GetStream/stream-go2 / Test_makeStreamError

Function Test_makeStreamError

client_internal_test.go:140–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138func (badReader) Read([]byte) (int, error) { return 0, fmt.Errorf("boom") }
139
140func Test_makeStreamError(t *testing.T) {
141 testCases := []struct {
142 body io.Reader
143 expected error
144 apiErr APIError
145 }{
146 {
147 body: nil,
148 expected: fmt.Errorf("invalid body"),
149 },
150 {
151 body: badReader{},
152 expected: fmt.Errorf("boom"),
153 },
154 {
155 body: strings.NewReader(`{{`),
156 expected: fmt.Errorf("unexpected error (status code 123)"),
157 },
158 {
159 body: strings.NewReader(`{"code":"A"}`),
160 expected: fmt.Errorf("unexpected error (status code 123)"),
161 },
162 {
163 body: strings.NewReader(`{"code":1, "detail":"test", "duration": "1m2s", "exception": "boom", "status_code": 456, "exception_fields": {"foo":["bar"]}}`),
164 expected: fmt.Errorf("test"),
165 apiErr: APIError{
166 Code: 1,
167 Detail: "test",
168 Duration: Duration{time.Minute + time.Second*2},
169 Exception: "boom",
170 StatusCode: 123,
171 ExceptionFields: map[string][]any{
172 "foo": {"bar"},
173 },
174 },
175 },
176 }
177 for _, tc := range testCases {
178 err := (&Client{}).makeStreamError(123, nil, tc.body)
179 assert.Equal(t, tc.expected.Error(), err.Error())
180 if tc.apiErr.Code != 0 {
181 assert.Equal(t, tc.apiErr, err)
182 }
183 }
184}
185
186type requester struct {
187 code int

Callers

nothing calls this directly

Calls 2

makeStreamErrorMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected