Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <yb532204897@gmail.com>
  • Loading branch information
yeya24 committed Oct 31, 2020
1 parent 7be1882 commit 5e3289c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pkg/replicate/scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func testMeta(ulid ulid.ULID) *metadata.Meta {
}

func TestReplicationSchemeAll(t *testing.T) {
testBlockID := testULID(0)
var cases = []struct {
name string
selector labels.Selector
blockIDs []string
prepare func(ctx context.Context, t *testing.T, originBucket, targetBucket *objstore.InMemBucket)
assert func(ctx context.Context, t *testing.T, originBucket, targetBucket *objstore.InMemBucket)
}{
Expand Down Expand Up @@ -291,6 +293,35 @@ func TestReplicationSchemeAll(t *testing.T) {
testutil.Equals(t, expected, got)
},
},
{
name: "BlockIDs",
blockIDs: []string{testBlockID.String()},
prepare: func(ctx context.Context, t *testing.T, originBucket, targetBucket *objstore.InMemBucket) {
meta := testMeta(testBlockID)

b, err := json.Marshal(meta)
testutil.Ok(t, err)
_ = originBucket.Upload(ctx, path.Join(testBlockID.String(), "meta.json"), bytes.NewReader(b))
_ = originBucket.Upload(ctx, path.Join(testBlockID.String(), "chunks", "000001"), bytes.NewReader(nil))
_ = originBucket.Upload(ctx, path.Join(testBlockID.String(), "index"), bytes.NewReader(nil))

ulid := testULID(1)
meta = testMeta(ulid)

b, err = json.Marshal(meta)
testutil.Ok(t, err)
_ = originBucket.Upload(ctx, path.Join(ulid.String(), "meta.json"), bytes.NewReader(b))
_ = originBucket.Upload(ctx, path.Join(ulid.String(), "chunks", "000001"), bytes.NewReader(nil))
_ = originBucket.Upload(ctx, path.Join(ulid.String(), "index"), bytes.NewReader(nil))
},
assert: func(ctx context.Context, t *testing.T, originBucket, targetBucket *objstore.InMemBucket) {
expected := 3
got := len(targetBucket.Objects())
if got != expected {
t.Fatalf("TargetBucket should have one block made up of three objects replicated. Got %d but expected %d objects.", got, expected)
}
},
},
}

for _, c := range cases {
Expand All @@ -311,7 +342,7 @@ func TestReplicationSchemeAll(t *testing.T) {
selector = c.selector
}

filter := NewBlockFilter(logger, selector, []compact.ResolutionLevel{compact.ResolutionLevelRaw}, []int{1}).Filter
filter := NewBlockFilter(logger, selector, []compact.ResolutionLevel{compact.ResolutionLevelRaw}, []int{1}, c.blockIDs).Filter
fetcher, err := block.NewMetaFetcher(logger, 32, objstore.WithNoopInstr(originBucket), "", nil, nil, nil)
testutil.Ok(t, err)

Expand Down

0 comments on commit 5e3289c

Please sign in to comment.