Skip to content

Commit

Permalink
fix acceptance test
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 committed Sep 27, 2024
1 parent 6826022 commit e780e80
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions objstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMetricBucket_Close(t *testing.T) {
testutil.Equals(t, 7, promtest.CollectAndCount(bkt.metrics.opsFailures))
testutil.Equals(t, 7, promtest.CollectAndCount(bkt.metrics.opsDuration))

AcceptanceTest(t, bkt.WithExpectedErrs(bkt.IsObjNotFoundErr))
AcceptanceTest(t, bkt.WithExpectedErrs(bkt.IsObjNotFoundErr), true)
testutil.Equals(t, float64(9), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpIter)))
testutil.Equals(t, float64(2), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpAttributes)))
testutil.Equals(t, float64(3), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpGet)))
Expand All @@ -51,7 +51,7 @@ func TestMetricBucket_Close(t *testing.T) {

// Clear bucket, but don't clear metrics to ensure we use same.
bkt.bkt = NewInMemBucket()
AcceptanceTest(t, bkt)
AcceptanceTestWithoutNotFoundErr(t, bkt)
testutil.Equals(t, float64(18), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpIter)))
testutil.Equals(t, float64(4), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpAttributes)))
testutil.Equals(t, float64(6), promtest.ToFloat64(bkt.metrics.ops.WithLabelValues(OpGet)))
Expand Down
2 changes: 1 addition & 1 deletion objtesting/acceptance_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import (
// NOTE: This test assumes strong consistency, but in the same way it does not guarantee that if it passes, the
// used object store is strongly consistent.
func TestObjStore_AcceptanceTest_e2e(t *testing.T) {
ForeachStore(t, objstore.AcceptanceTest)
ForeachStore(t, objstore.AcceptanceTestWithoutNotFoundErr)
}
2 changes: 1 addition & 1 deletion prefixed_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPrefixedBucket_Acceptance(t *testing.T) {
"someprefix"}

for _, prefix := range prefixes {
AcceptanceTest(t, NewPrefixedBucket(NewInMemBucket(), prefix))
AcceptanceTestWithoutNotFoundErr(t, NewPrefixedBucket(NewInMemBucket(), prefix))
UsesPrefixTest(t, NewInMemBucket(), prefix)
}
}
Expand Down
18 changes: 13 additions & 5 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,32 @@ func (b noopInstrumentedBucket) ReaderWithExpectedErrs(IsOpFailureExpectedFunc)
return b
}

func AcceptanceTest(t *testing.T, bkt Bucket) {
func AcceptanceTestWithoutNotFoundErr(t *testing.T, bkt Bucket) {
AcceptanceTest(t, bkt, false)
}

func AcceptanceTest(t *testing.T, bkt Bucket, expectedNotFoundErr bool) {
ctx := context.Background()

_, err := bkt.Get(ctx, "")
testutil.NotOk(t, err)
testutil.Assert(t, !bkt.IsObjNotFoundErr(err), "expected user error got not found %s", err)

_, err = bkt.Get(ctx, "id1/obj_1.some")
testutil.NotOk(t, err)
testutil.Assert(t, bkt.IsObjNotFoundErr(err), "expected not found error got %s", err)
if !expectedNotFoundErr {
testutil.NotOk(t, err)
testutil.Assert(t, bkt.IsObjNotFoundErr(err), "expected not found error got %s", err)
}

ok, err := bkt.Exists(ctx, "id1/obj_1.some")
testutil.Ok(t, err)
testutil.Assert(t, !ok, "expected not exits")

_, err = bkt.Attributes(ctx, "id1/obj_1.some")
testutil.NotOk(t, err)
testutil.Assert(t, bkt.IsObjNotFoundErr(err), "expected not found error but got %s", err)
if !expectedNotFoundErr {
testutil.NotOk(t, err)
testutil.Assert(t, bkt.IsObjNotFoundErr(err), "expected not found error got %s", err)
}

// Upload first object.
testutil.Ok(t, bkt.Upload(ctx, "id1/obj_1.some", strings.NewReader("@test-data@")))
Expand Down

0 comments on commit e780e80

Please sign in to comment.