(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestExtractContext(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | validID := uuid.MustParse("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") |
| 20 | ancestor1 := uuid.MustParse("11111111-2222-3333-4444-555555555555") |
| 21 | ancestor2 := uuid.MustParse("66666666-7777-8888-9999-aaaaaaaaaaaa") |
| 22 | |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | chatID string // empty means header not set |
| 26 | setChatID bool // whether to set the chat ID header at all |
| 27 | ancestors string // empty means header not set |
| 28 | setAncestors bool // whether to set the ancestor header at all |
| 29 | wantChatID uuid.UUID |
| 30 | wantAncestorIDs []uuid.UUID |
| 31 | wantOK bool |
| 32 | }{ |
| 33 | { |
| 34 | name: "NoHeadersPresent", |
| 35 | setChatID: false, |
| 36 | setAncestors: false, |
| 37 | wantChatID: uuid.Nil, |
| 38 | wantAncestorIDs: nil, |
| 39 | wantOK: false, |
| 40 | }, |
| 41 | { |
| 42 | name: "ValidChatID_NoAncestors", |
| 43 | chatID: validID.String(), |
| 44 | setChatID: true, |
| 45 | setAncestors: false, |
| 46 | wantChatID: validID, |
| 47 | wantAncestorIDs: []uuid.UUID{}, |
| 48 | wantOK: true, |
| 49 | }, |
| 50 | { |
| 51 | name: "ValidChatID_ValidAncestors", |
| 52 | chatID: validID.String(), |
| 53 | setChatID: true, |
| 54 | ancestors: mustMarshalJSON(t, []string{ |
| 55 | ancestor1.String(), |
| 56 | ancestor2.String(), |
| 57 | }), |
| 58 | setAncestors: true, |
| 59 | wantChatID: validID, |
| 60 | wantAncestorIDs: []uuid.UUID{ancestor1, ancestor2}, |
| 61 | wantOK: true, |
| 62 | }, |
| 63 | { |
| 64 | name: "MalformedChatID", |
| 65 | chatID: "not-a-uuid", |
| 66 | setChatID: true, |
| 67 | setAncestors: false, |
| 68 | wantChatID: uuid.Nil, |
| 69 | wantAncestorIDs: nil, |
| 70 | wantOK: false, |
| 71 | }, |
| 72 | { |
| 73 | name: "ValidChatID_MalformedAncestorJSON", |
nothing calls this directly
no test coverage detected