func TestIntervalChunks(t *testing.T) {

	// we need to check four cases of the subscribe pull iterator:
	// - no chunks in interval
	// - less chunks reported than what is in the interval (but interval still intact, probably old chunks GCd)
	// - as much chunks as size of interval
	// - more chunks than what's in interval (return lower topmost value)
	// - less chunks in interval, but since we're at the top of the interval, block and wait for new chunks

	for _, tc := range []struct {
		desc     string
		from, to uint64 // request from, to

		mockAddrs []int  // which addresses should the mock return
		addrs     []byte // the expected returned chunk address byte slice
		topmost   uint64 // expected topmost
	}{
		{desc: "no chunks in interval", from: 0, to: 5, topmost: 5},
		{desc: "interval full", from: 0, to: 5, mockAddrs: []int{0, 1, 2, 3, 4}, topmost: 5},
		{desc: "some in the middle", from: 0, to: 5, mockAddrs: []int{1, 3}, topmost: 5},
		{desc: "at the edges", from: 0, to: 5, mockAddrs: []int{0, 4}, topmost: 5},
		{desc: "at the edges and the middle", from: 0, to: 5, mockAddrs: []int{0, 2, 4}, topmost: 5},
		{desc: "more than interval", from: 0, to: 5, mockAddrs: []int{0, 1, 2, 3, 4, 5}, topmost: 5},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			b := someAddrs(tc.mockAddrs...)
			desc := someDescriptors(tc.mockAddrs...)
			ps, _ := newPullStorage(t, mock.WithSubscribePullChunks(desc...))
			ctx, cancel := context.WithCancel(context.Background())

			addresses, topmost, err := ps.IntervalChunks(ctx, 0, tc.from, tc.to, limit)
			if err != nil {
				t.Fatal(err)
			}

			cancel()

			checkAinB(t, addresses, b)

			if topmost != tc.topmost {
				t.Fatalf("expected topmost %d but got %d", tc.topmost, topmost)
			}
		})
	}
}
// TestIntervalChunks tests that the IntervalChunks method always returns
// an upper bound of N chunks for a certain range, and the topmost equals:
// - to the To argument of the function (in case there are no chunks in the interval)
// - to the To argument of the function (in case the number of chunks in interval <= N)
// - to BinID of the last chunk in the returned collection in case number of chunks in interval > N
TestIntervalChunks tests that the IntervalChunks method always returns
an upper bound of N chunks for a certain range, and the topmost equals:
- to the To argument of the function (in case there are no chunks in the interval)
- to the To argument of the function (in case the number of chunks in interval <= N)
- to BinID of the last chunk in the returned collection in case number of chunks in interval > N
// TestIntervalChunks tests that the IntervalChunks method always returns // an upper bound of N chunks for a certain range and the topmost equals : // - to the To argument of the function ( in case there are no chunks in the interval ) // - to the To argument of the function ( in case the number of chunks in interval < = N ) // - to BinID of the last chunk in the returned collection in case number of chunks in interval > N
func TestIntervalChunks(t *testing.T) {
	for _, tc := range []struct {
		desc     string
		from, to uint64 
		mockAddrs []int  
		addrs     []byte 
		topmost   uint64 
	}{
		{desc: "no chunks in interval", from: 0, to: 5, topmost: 5},
		{desc: "interval full", from: 0, to: 5, mockAddrs: []int{0, 1, 2, 3, 4}, topmost: 5},
		{desc: "some in the middle", from: 0, to: 5, mockAddrs: []int{1, 3}, topmost: 5},
		{desc: "at the edges", from: 0, to: 5, mockAddrs: []int{0, 4}, topmost: 5},
		{desc: "at the edges and the middle", from: 0, to: 5, mockAddrs: []int{0, 2, 4}, topmost: 5},
		{desc: "more than interval", from: 0, to: 5, mockAddrs: []int{0, 1, 2, 3, 4, 5}, topmost: 5},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			b := someAddrs(tc.mockAddrs...)
			desc := someDescriptors(tc.mockAddrs...)
			ps, _ := newPullStorage(t, mock.WithSubscribePullChunks(desc...))
			ctx, cancel := context.WithCancel(context.Background())
			addresses, topmost, err := ps.IntervalChunks(ctx, 0, tc.from, tc.to, limit)
			if err != nil {
				t.Fatal(err)
			}
			cancel()
			checkAinB(t, addresses, b)
			if topmost != tc.topmost {
				t.Fatalf("expected topmost %d but got %d", tc.topmost, topmost)
			}
		})
	}
}
func TestIntervalChunks ( t * testing . T ) { for _ , tc := range [ ] struct { desc string from , to uint64 mockAddrs [ ] int addrs [ ] byte topmost uint64 } { { desc : " " , from : 0 , to : 5 , topmost : 5 } , { desc : " " , from : 0 , to : 5 , mockAddrs : [ ] int { 0 , 1 , 2 , 3 , 4 } , topmost : 5 } , { desc : " " , from : 0 , to : 5 , mockAddrs : [ ] int { 1 , 3 } , topmost : 5 } , { desc : " " , from : 0 , to : 5 , mockAddrs : [ ] int { 0 , 4 } , topmost : 5 } , { desc : " " , from : 0 , to : 5 , mockAddrs : [ ] int { 0 , 2 , 4 } , topmost : 5 } , { desc : " " , from : 0 , to : 5 , mockAddrs : [ ] int { 0 , 1 , 2 , 3 , 4 , 5 } , topmost : 5 } , } { t . Run ( tc . desc , func ( t * testing . T ) { b := someAddrs ( tc . mockAddrs ... ) desc := someDescriptors ( tc . mockAddrs ... ) ps , _ := newPullStorage ( t , mock . WithSubscribePullChunks ( desc ... ) ) ctx , cancel := context . WithCancel ( context . Background ( ) ) addresses , topmost , err := ps . IntervalChunks ( ctx , 0 , tc . from , tc . to , limit ) if err != nil { t . Fatal ( err ) } cancel ( ) checkAinB ( t , addresses , b ) if topmost != tc . topmost { t . Fatalf ( " " , tc . topmost , topmost ) } } ) } }
TestIntervalChunks tests that the IntervalChunks method always returns
an upper bound of N chunks for a certain range, and the topmost equals:
 to the To argument of the function (in case there are no chunks in the interval)
 to the To argument of the function (in case the number of chunks in interval <= N)
 to BinID of the last chunk in the returned collection in case number of chunks in interval > N
TestIntervalChunks tests that the IntervalChunks method always returns an upper bound of N chunks for a certain range and the topmost equals : to the To argument of the function ( in case there are no chunks in the interval ) to the To argument of the function ( in case the number of chunks in interval < = N ) to BinID of the last chunk in the returned collection in case number of chunks in interval > N
// we need to check four cases of the subscribe pull iterator: // - no chunks in interval // - less chunks reported than what is in the interval (but interval still intact, probably old chunks GCd) // - as much chunks as size of interval // - more chunks than what's in interval (return lower topmost value) // - less chunks in interval, but since we're at the top of the interval, block and wait for new chunks // request from, to // which addresses should the mock return // the expected returned chunk address byte slice // expected topmost