(t *testing.T)
| 695 | } |
| 696 | |
| 697 | func TestVarintCompatibility(t *testing.T) { |
| 698 | td := []testData{ |
| 699 | { |
| 700 | 1, |
| 701 | types.NewFieldType(mysql.TypeLonglong), |
| 702 | types.NewIntDatum(1), |
| 703 | types.NewIntDatum(1), |
| 704 | nil, |
| 705 | false, |
| 706 | }, |
| 707 | { |
| 708 | 2, |
| 709 | withUnsigned(types.NewFieldType(mysql.TypeLonglong)), |
| 710 | types.NewUintDatum(1), |
| 711 | types.NewUintDatum(1), |
| 712 | nil, |
| 713 | false, |
| 714 | }, |
| 715 | } |
| 716 | |
| 717 | // transform test data into input. |
| 718 | colIDs := make([]int64, 0, len(td)) |
| 719 | dts := make([]types.Datum, 0, len(td)) |
| 720 | cols := make([]rowcodec.ColInfo, 0, len(td)) |
| 721 | for _, d := range td { |
| 722 | colIDs = append(colIDs, d.id) |
| 723 | dts = append(dts, d.input) |
| 724 | cols = append(cols, rowcodec.ColInfo{ |
| 725 | ID: d.id, |
| 726 | IsPKHandle: d.handle, |
| 727 | Ft: d.ft, |
| 728 | }) |
| 729 | } |
| 730 | |
| 731 | // test encode input. |
| 732 | var encoder rowcodec.Encoder |
| 733 | newRow, err := encoder.Encode(time.UTC, colIDs, dts, nil, nil) |
| 734 | require.NoError(t, err) |
| 735 | |
| 736 | decoder := rowcodec.NewByteDecoder(cols, []int64{-1}, nil, time.UTC) |
| 737 | // decode to old row bytes. |
| 738 | colOffset := make(map[int64]int) |
| 739 | for i, t := range td { |
| 740 | colOffset[t.id] = i |
| 741 | } |
| 742 | oldRow, err := decoder.DecodeToBytes(colOffset, kv.IntHandle(1), newRow, nil) |
| 743 | require.NoError(t, err) |
| 744 | |
| 745 | for i, d := range td { |
| 746 | oldVarint, err := tablecodec.EncodeValue(nil, nil, d.output) // tablecodec will encode as varint/varuint |
| 747 | require.NoError(t, err) |
| 748 | require.Equal(t, oldRow[i], oldVarint) |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | func TestCodecUtil(t *testing.T) { |
| 753 | colIDs := []int64{1, 2, 3, 4} |
nothing calls this directly
no test coverage detected
searching dependent graphs…