// Test pinning a Cid, unpinning it, and Stage it again.
Test pinning a Cid, unpinning it, and Stage it again.
// Test pinning a Cid unpinning it and Stage it again .
func TestPinUnpinStage(t *testing.T) {
	t.Parallel()
	ctx := context.Background()
	r := rand.New(rand.NewSource(22))
	ci, ipfs := newCoreIPFS(t)
	data := it.RandomBytes(r, 1500)
	iid := ffs.NewAPIID()
	rd := ipfsfiles.NewReaderFile(bytes.NewReader(data))
	p, err := ipfs.Unixfs().Add(ctx, rd, options.Unixfs.Pin(false))
	require.NoError(t, err)
	c := p.Cid()
	_, err = ci.Pin(ctx, iid, c)
	require.NoError(t, err)
	err = ci.Unpin(ctx, iid, c)
	require.NoError(t, err)
	requireRefCount(t, ci, c, 0, 0)
	c, err = ci.Stage(ctx, iid, bytes.NewReader(data))
	require.NoError(t, err)
	it.RequireIpfsPinnedCid(ctx, t, c, ipfs)
	requireCidIsGCable(t, ci, c)
	okPinned, err := ci.IsPinned(ctx, iid, c)
	require.NoError(t, err)
	require.True(t, okPinned)
	requireRefCount(t, ci, c, 0, 1)
}
func TestPinUnpinStage ( t * testing . T ) { t . Parallel ( ) ctx := context . Background ( ) r := rand . New ( rand . NewSource ( 22 ) ) ci , ipfs := newCoreIPFS ( t ) data := it . RandomBytes ( r , 1500 ) iid := ffs . NewAPIID ( ) rd := ipfsfiles . NewReaderFile ( bytes . NewReader ( data ) ) p , err := ipfs . Unixfs ( ) . Add ( ctx , rd , options . Unixfs . Pin ( false ) ) require . NoError ( t , err ) c := p . Cid ( ) _ , err = ci . Pin ( ctx , iid , c ) require . NoError ( t , err ) err = ci . Unpin ( ctx , iid , c ) require . NoError ( t , err ) requireRefCount ( t , ci , c , 0 , 0 ) c , err = ci . Stage ( ctx , iid , bytes . NewReader ( data ) ) require . NoError ( t , err ) it . RequireIpfsPinnedCid ( ctx , t , c , ipfs ) requireCidIsGCable ( t , ci , c ) okPinned , err := ci . IsPinned ( ctx , iid , c ) require . NoError ( t , err ) require . True ( t , okPinned ) requireRefCount ( t , ci , c , 0 , 1 ) }
Test pinning a Cid, unpinning it, and Stage it again.
Test pinning a Cid unpinning it and Stage it again .
// Stage it again and check invariants: // must be gcable, is pinned, and should have a staged-pin.