|
| 1 | +import { Span, setHttpStatus, spanToJSON } from '../../../src/index'; |
| 2 | + |
| 3 | +describe('setHttpStatus', () => { |
| 4 | + it.each([ |
| 5 | + [200, 'ok'], |
| 6 | + [300, 'ok'], |
| 7 | + [401, 'unauthenticated'], |
| 8 | + [403, 'permission_denied'], |
| 9 | + [404, 'not_found'], |
| 10 | + [409, 'already_exists'], |
| 11 | + [413, 'failed_precondition'], |
| 12 | + [429, 'resource_exhausted'], |
| 13 | + [455, 'invalid_argument'], |
| 14 | + [501, 'unimplemented'], |
| 15 | + [503, 'unavailable'], |
| 16 | + [504, 'deadline_exceeded'], |
| 17 | + [520, 'internal_error'], |
| 18 | + ])('applies the correct span status and http status code to the span (%s - $%s)', (code, status) => { |
| 19 | + const span = new Span({ name: 'test' }); |
| 20 | + |
| 21 | + setHttpStatus(span!, code); |
| 22 | + |
| 23 | + const { status: spanStatus, data, tags } = spanToJSON(span!); |
| 24 | + |
| 25 | + expect(spanStatus).toBe(status); |
| 26 | + expect(data).toMatchObject({ 'http.response.status_code': code }); |
| 27 | + expect(tags).toMatchObject({ 'http.status_code': String(code) }); |
| 28 | + }); |
| 29 | + |
| 30 | + it("doesn't set the status for an unknown http status code", () => { |
| 31 | + const span = new Span({ name: 'test' }); |
| 32 | + |
| 33 | + setHttpStatus(span!, 600); |
| 34 | + |
| 35 | + const { status: spanStatus, data, tags } = spanToJSON(span!); |
| 36 | + |
| 37 | + expect(spanStatus).toBeUndefined(); |
| 38 | + expect(data).toMatchObject({ 'http.response.status_code': 600 }); |
| 39 | + expect(tags).toMatchObject({ 'http.status_code': '600' }); |
| 40 | + }); |
| 41 | +}); |
0 commit comments