github.com/stffabi/git-lfs@v2.3.5-0.20180214015214-8eeaa8d88902+incompatible/git/odb/pack/set_test.go (about) 1 package pack 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestSetOpenOpensAPackedObject(t *testing.T) { 12 const sha = "decafdecafdecafdecafdecafdecafdecafdecaf" 13 const data = "Hello, world!\n" 14 compressed, _ := compress(data) 15 16 set := NewSetPacks(&Packfile{ 17 idx: IndexWith(map[string]uint32{ 18 sha: 0, 19 }), 20 r: bytes.NewReader(append([]byte{0x3e}, compressed...)), 21 }) 22 23 o, err := set.Object(DecodeHex(t, sha)) 24 25 assert.NoError(t, err) 26 assert.Equal(t, TypeBlob, o.Type()) 27 28 unpacked, err := o.Unpack() 29 assert.NoError(t, err) 30 assert.Equal(t, []byte(data), unpacked) 31 } 32 33 func TestSetOpenOpensPackedObjectsInPackOrder(t *testing.T) { 34 p1 := &Packfile{ 35 Objects: 1, 36 37 idx: IndexWith(map[string]uint32{ 38 "aa00000000000000000000000000000000000000": 1, 39 }), 40 r: bytes.NewReader(nil), 41 } 42 p2 := &Packfile{ 43 Objects: 2, 44 45 idx: IndexWith(map[string]uint32{ 46 "aa11111111111111111111111111111111111111": 1, 47 "aa22222222222222222222222222222222222222": 2, 48 }), 49 r: bytes.NewReader(nil), 50 } 51 p3 := &Packfile{ 52 Objects: 3, 53 54 idx: IndexWith(map[string]uint32{ 55 "aa33333333333333333333333333333333333333": 3, 56 "aa44444444444444444444444444444444444444": 4, 57 "aa55555555555555555555555555555555555555": 5, 58 }), 59 r: bytes.NewReader(nil), 60 } 61 62 set := NewSetPacks(p1, p2, p3) 63 64 var visited []*Packfile 65 66 set.each( 67 DecodeHex(t, "aa55555555555555555555555555555555555555"), 68 func(p *Packfile) (*Object, error) { 69 visited = append(visited, p) 70 return nil, errNotFound 71 }, 72 ) 73 74 require.Len(t, visited, 3) 75 assert.EqualValues(t, visited[0].Objects, 3) 76 assert.EqualValues(t, visited[1].Objects, 2) 77 assert.EqualValues(t, visited[2].Objects, 1) 78 }