github.com/stffabi/git-lfs@v2.3.5-0.20180214015214-8eeaa8d88902+incompatible/git/odb/pack/index_v1_test.go (about) 1 package pack 2 3 import ( 4 "bytes" 5 "encoding/binary" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 var ( 12 V1IndexFanout = make([]uint32, indexFanoutEntries) 13 14 V1IndexSmallEntry = []byte{ 15 0x0, 0x0, 0x0, 0x1, 16 17 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 18 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 19 } 20 V1IndexSmallSha = V1IndexSmallEntry[4:] 21 22 V1IndexMediumEntry = []byte{ 23 0x0, 0x0, 0x0, 0x2, 24 25 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 26 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 27 } 28 V1IndexMediumSha = V1IndexMediumEntry[4:] 29 30 V1IndexLargeEntry = []byte{ 31 0x0, 0x0, 0x0, 0x3, 32 33 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 34 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 35 } 36 V1IndexLargeSha = V1IndexLargeEntry[4:] 37 38 V1Index = &Index{ 39 fanout: V1IndexFanout, 40 version: new(V1), 41 } 42 ) 43 44 func TestIndexV1SearchExact(t *testing.T) { 45 e, err := new(V1).Entry(V1Index, 1) 46 47 assert.NoError(t, err) 48 assert.EqualValues(t, 2, e.PackOffset) 49 } 50 51 func TestIndexVersionWidthV1(t *testing.T) { 52 assert.EqualValues(t, 0, new(V1).Width()) 53 } 54 55 func init() { 56 V1IndexFanout[1] = 1 57 V1IndexFanout[2] = 2 58 V1IndexFanout[3] = 3 59 60 for i := 3; i < len(V1IndexFanout); i++ { 61 V1IndexFanout[i] = 3 62 } 63 64 fanout := make([]byte, indexFanoutWidth) 65 for i, n := range V1IndexFanout { 66 binary.BigEndian.PutUint32(fanout[i*indexFanoutEntryWidth:], n) 67 } 68 69 buf := make([]byte, 0, indexOffsetV1Start+(3*indexObjectEntryV1Width)) 70 71 buf = append(buf, fanout...) 72 buf = append(buf, V1IndexSmallEntry...) 73 buf = append(buf, V1IndexMediumEntry...) 74 buf = append(buf, V1IndexLargeEntry...) 75 76 V1Index.r = bytes.NewReader(buf) 77 }