func TestIntervalChunks_Localstore(t *testing.T) {
	fill := func(f, t int) (ints []int) {
		for i := f; i <= t; i++ {
			ints = append(ints, i)
		}
		return ints
	}
	for _, tc := range []struct {
		name   string
		chunks int
		f, t   uint64
		limit  int
		expect int    // chunks
		top    uint64 // topmost
		addrs  []int  // indexes of the generated chunk slice
	}{
		{
			name:   "0-1, expect 1 chunk", // intervals always >0
			chunks: 50,
			f:      0, t: 1,
			limit:  50,
			expect: 1, top: 1, addrs: fill(1, 1),
		},
		{
			name:   "1-1, expect 1 chunk",
			chunks: 50,
			f:      1, t: 1,
			limit:  50,
			expect: 1, top: 1, addrs: fill(1, 1),
		},
		{
			name:   "2-2, expect 1 chunk",
			chunks: 50,
			f:      2, t: 2,
			limit:  50,
			expect: 1, top: 2, addrs: fill(2, 2),
		},
		{
			name:   "0-10, expect 10 chunks", // intervals always >0
			chunks: 50,
			f:      0, t: 10,
			limit:  50,
			expect: 10, top: 10, addrs: fill(1, 10),
		},
		{
			name:   "1-10, expect 10 chunks",
			chunks: 50,
			f:      0, t: 10,
			limit:  50,
			expect: 10, top: 10, addrs: fill(1, 10),
		},

		{
			name:   "0-50, expect 50 chunks", // intervals always >0
			chunks: 50,
			f:      0, t: 50,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "1-50, expect 50 chunks",
			chunks: 50,
			f:      1, t: 50,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "0-60, expect 50 chunks", // hit the limit
			chunks: 50,
			f:      0, t: 60,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "1-60, expect 50 chunks", // hit the limit
			chunks: 50,
			f:      0, t: 60,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
	} {
		t.Run(tc.name, func(t *testing.T) {

			base, db := newTestDB(t, nil)
			ps := pullstorage.New(db)

			var chunks []swarm.Chunk

			for i := 1; i <= tc.chunks; {
				c := stesting.GenerateTestRandomChunk()
				po := swarm.Proximity(c.Address().Bytes(), base)
				if po == 1 {
					chunks = append(chunks, c)
					i++
				}
			}

			ctx := context.Background()
			_, err := db.Put(ctx, storage.ModePutUpload, chunks...)
			if err != nil {
				t.Fatal(err)
			}

			//always bin 1
			chs, topmost, err := ps.IntervalChunks(ctx, 1, tc.f, tc.t, tc.limit)
			if err != nil {
				t.Fatal(err)
			}

			checkAddrs := make([]swarm.Address, len(tc.addrs))
			for i, v := range tc.addrs {
				checkAddrs[i] = chunks[v-1].Address()
			}

			for i, c := range chs {
				if !c.Equal(checkAddrs[i]) {
					t.Fatalf("chunk %d address mismatch", i)
				}
			}

			if topmost != tc.top {
				t.Fatalf("topmost mismatch, got %d want %d", topmost, tc.top)
			}

			if l := len(chs); l != tc.expect {
				t.Fatalf("expected %d chunks but got %d", tc.expect, l)
			}

		})
	}
}
// TestIntervalChunks_Localstore is an integration test with a real
// localstore instance.
TestIntervalChunks_Localstore is an integration test with a real
localstore instance.
// TestIntervalChunks_Localstore is an integration test with a real // localstore instance .
func TestIntervalChunks_Localstore(t *testing.T) {
	fill := func(f, t int) (ints []int) {
		for i := f; i <= t; i++ {
			ints = append(ints, i)
		}
		return ints
	}
	for _, tc := range []struct {
		name   string
		chunks int
		f, t   uint64
		limit  int
		expect int    
		top    uint64 
		addrs  []int  
	}{
		{
			name:   "0-1, expect 1 chunk", 
			chunks: 50,
			f:      0, t: 1,
			limit:  50,
			expect: 1, top: 1, addrs: fill(1, 1),
		},
		{
			name:   "1-1, expect 1 chunk",
			chunks: 50,
			f:      1, t: 1,
			limit:  50,
			expect: 1, top: 1, addrs: fill(1, 1),
		},
		{
			name:   "2-2, expect 1 chunk",
			chunks: 50,
			f:      2, t: 2,
			limit:  50,
			expect: 1, top: 2, addrs: fill(2, 2),
		},
		{
			name:   "0-10, expect 10 chunks", 
			chunks: 50,
			f:      0, t: 10,
			limit:  50,
			expect: 10, top: 10, addrs: fill(1, 10),
		},
		{
			name:   "1-10, expect 10 chunks",
			chunks: 50,
			f:      0, t: 10,
			limit:  50,
			expect: 10, top: 10, addrs: fill(1, 10),
		},
		{
			name:   "0-50, expect 50 chunks", 
			chunks: 50,
			f:      0, t: 50,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "1-50, expect 50 chunks",
			chunks: 50,
			f:      1, t: 50,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "0-60, expect 50 chunks", 
			chunks: 50,
			f:      0, t: 60,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
		{
			name:   "1-60, expect 50 chunks", 
			chunks: 50,
			f:      0, t: 60,
			limit:  50,
			expect: 50, top: 50, addrs: fill(1, 50),
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			base, db := newTestDB(t, nil)
			ps := pullstorage.New(db)
			var chunks []swarm.Chunk
			for i := 1; i <= tc.chunks; {
				c := stesting.GenerateTestRandomChunk()
				po := swarm.Proximity(c.Address().Bytes(), base)
				if po == 1 {
					chunks = append(chunks, c)
					i++
				}
			}
			ctx := context.Background()
			_, err := db.Put(ctx, storage.ModePutUpload, chunks...)
			if err != nil {
				t.Fatal(err)
			}
			chs, topmost, err := ps.IntervalChunks(ctx, 1, tc.f, tc.t, tc.limit)
			if err != nil {
				t.Fatal(err)
			}
			checkAddrs := make([]swarm.Address, len(tc.addrs))
			for i, v := range tc.addrs {
				checkAddrs[i] = chunks[v-1].Address()
			}
			for i, c := range chs {
				if !c.Equal(checkAddrs[i]) {
					t.Fatalf("chunk %d address mismatch", i)
				}
			}
			if topmost != tc.top {
				t.Fatalf("topmost mismatch, got %d want %d", topmost, tc.top)
			}
			if l := len(chs); l != tc.expect {
				t.Fatalf("expected %d chunks but got %d", tc.expect, l)
			}
		})
	}
}
func TestIntervalChunks_Localstore ( t * testing . T ) { fill := func ( f , t int ) ( ints [ ] int ) { for i := f ; i <= t ; i ++ { ints = append ( ints , i ) } return ints } for _ , tc := range [ ] struct { name string chunks int f , t uint64 limit int expect int top uint64 addrs [ ] int } { { name : " " , chunks : 50 , f : 0 , t : 1 , limit : 50 , expect : 1 , top : 1 , addrs : fill ( 1 , 1 ) , } , { name : " " , chunks : 50 , f : 1 , t : 1 , limit : 50 , expect : 1 , top : 1 , addrs : fill ( 1 , 1 ) , } , { name : " " , chunks : 50 , f : 2 , t : 2 , limit : 50 , expect : 1 , top : 2 , addrs : fill ( 2 , 2 ) , } , { name : " " , chunks : 50 , f : 0 , t : 10 , limit : 50 , expect : 10 , top : 10 , addrs : fill ( 1 , 10 ) , } , { name : " " , chunks : 50 , f : 0 , t : 10 , limit : 50 , expect : 10 , top : 10 , addrs : fill ( 1 , 10 ) , } , { name : " " , chunks : 50 , f : 0 , t : 50 , limit : 50 , expect : 50 , top : 50 , addrs : fill ( 1 , 50 ) , } , { name : " " , chunks : 50 , f : 1 , t : 50 , limit : 50 , expect : 50 , top : 50 , addrs : fill ( 1 , 50 ) , } , { name : " " , chunks : 50 , f : 0 , t : 60 , limit : 50 , expect : 50 , top : 50 , addrs : fill ( 1 , 50 ) , } , { name : " " , chunks : 50 , f : 0 , t : 60 , limit : 50 , expect : 50 , top : 50 , addrs : fill ( 1 , 50 ) , } , } { t . Run ( tc . name , func ( t * testing . T ) { base , db := newTestDB ( t , nil ) ps := pullstorage . New ( db ) var chunks [ ] swarm . Chunk for i := 1 ; i <= tc . chunks ; { c := stesting . GenerateTestRandomChunk ( ) po := swarm . Proximity ( c . Address ( ) . Bytes ( ) , base ) if po == 1 { chunks = append ( chunks , c ) i ++ } } ctx := context . Background ( ) _ , err := db . Put ( ctx , storage . ModePutUpload , chunks ... ) if err != nil { t . Fatal ( err ) } chs , topmost , err := ps . IntervalChunks ( ctx , 1 , tc . f , tc . t , tc . limit ) if err != nil { t . Fatal ( err ) } checkAddrs := make ( [ ] swarm . Address , len ( tc . addrs ) ) for i , v := range tc . addrs { checkAddrs [ i ] = chunks [ v - 1 ] . Address ( ) } for i , c := range chs { if ! c . Equal ( checkAddrs [ i ] ) { t . Fatalf ( " " , i ) } } if topmost != tc . top { t . Fatalf ( " " , topmost , tc . top ) } if l := len ( chs ) ; l != tc . expect { t . Fatalf ( " " , tc . expect , l ) } } ) } }
TestIntervalChunks_Localstore is an integration test with a real
localstore instance.
TestIntervalChunks_Localstore is an integration test with a real localstore instance .
// chunks // topmost // indexes of the generated chunk slice // intervals always >0 // intervals always >0 // intervals always >0 // hit the limit // hit the limit //always bin 1