@@ -28,7 +28,7 @@ func TestMetricBucket_Close(t *testing.T) {
28
28
testutil .Equals (t , 7 , promtest .CollectAndCount (bkt .metrics .opsFailures ))
29
29
testutil .Equals (t , 7 , promtest .CollectAndCount (bkt .metrics .opsDuration ))
30
30
31
- AcceptanceTest (t , bkt .WithExpectedErrs (bkt .IsObjNotFoundErr ))
31
+ AcceptanceTest (t , bkt .WithExpectedErrs (bkt .IsObjNotFoundErr ), true )
32
32
testutil .Equals (t , float64 (9 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpIter )))
33
33
testutil .Equals (t , float64 (2 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpAttributes )))
34
34
testutil .Equals (t , float64 (3 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpGet )))
@@ -51,7 +51,7 @@ func TestMetricBucket_Close(t *testing.T) {
51
51
52
52
// Clear bucket, but don't clear metrics to ensure we use same.
53
53
bkt .bkt = NewInMemBucket ()
54
- AcceptanceTest (t , bkt )
54
+ AcceptanceTestWithoutNotFoundErr (t , bkt )
55
55
testutil .Equals (t , float64 (18 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpIter )))
56
56
testutil .Equals (t , float64 (4 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpAttributes )))
57
57
testutil .Equals (t , float64 (6 ), promtest .ToFloat64 (bkt .metrics .ops .WithLabelValues (OpGet )))
@@ -537,6 +537,54 @@ func TestDownloadDir_CleanUp(t *testing.T) {
537
537
testutil .Assert (t , os .IsNotExist (err ))
538
538
}
539
539
540
+ func TestBucketExpectedErrNoReturnError (t * testing.T ) {
541
+ expectedErr := errors .New ("test error" )
542
+
543
+ bucket := WrapWithMetrics (& mockBucket {
544
+ get : func (_ context.Context , _ string ) (io.ReadCloser , error ) {
545
+ return nil , expectedErr
546
+ },
547
+ getRange : func (ctx context.Context , name string , off , length int64 ) (io.ReadCloser , error ) {
548
+ return nil , expectedErr
549
+ },
550
+ upload : func (ctx context.Context , name string , r io.Reader ) error {
551
+ return expectedErr
552
+ },
553
+ iter : func (ctx context.Context , dir string , f func (string ) error , options ... IterOption ) error {
554
+ return expectedErr
555
+ },
556
+ attributes : func (ctx context.Context , name string ) (ObjectAttributes , error ) {
557
+ return ObjectAttributes {}, expectedErr
558
+ },
559
+ exists : func (ctx context.Context , name string ) (bool , error ) {
560
+ return false , expectedErr
561
+ },
562
+ }, nil , "" ).WithExpectedErrs (func (err error ) bool {
563
+ return errors .Is (err , expectedErr )
564
+ })
565
+
566
+ // Expect no error to be returned since the error is expected.
567
+ _ , err := bucket .Get (context .Background (), "" )
568
+ testutil .Ok (t , err )
569
+
570
+ _ , err = bucket .GetRange (context .Background (), "" , 1 , 2 )
571
+ testutil .Ok (t , err )
572
+
573
+ err = bucket .Upload (context .Background (), "" , nil )
574
+ testutil .Ok (t , err )
575
+
576
+ err = bucket .Iter (context .Background (), "" , func (s string ) error {
577
+ return nil
578
+ })
579
+ testutil .Ok (t , err )
580
+
581
+ _ , err = bucket .Exists (context .Background (), "" )
582
+ testutil .Ok (t , err )
583
+
584
+ _ , err = bucket .Attributes (context .Background (), "" )
585
+ testutil .Ok (t , err )
586
+ }
587
+
540
588
// unreliableBucket implements Bucket and returns an error on every n-th Get.
541
589
type unreliableBucket struct {
542
590
Bucket
@@ -570,9 +618,12 @@ func (r *mockReader) Close() error {
570
618
type mockBucket struct {
571
619
Bucket
572
620
573
- upload func (ctx context.Context , name string , r io.Reader ) error
574
- get func (ctx context.Context , name string ) (io.ReadCloser , error )
575
- getRange func (ctx context.Context , name string , off , length int64 ) (io.ReadCloser , error )
621
+ upload func (ctx context.Context , name string , r io.Reader ) error
622
+ get func (ctx context.Context , name string ) (io.ReadCloser , error )
623
+ getRange func (ctx context.Context , name string , off , length int64 ) (io.ReadCloser , error )
624
+ iter func (ctx context.Context , dir string , f func (string ) error , options ... IterOption ) error
625
+ attributes func (ctx context.Context , name string ) (ObjectAttributes , error )
626
+ exists func (ctx context.Context , name string ) (bool , error )
576
627
}
577
628
578
629
func (b * mockBucket ) Upload (ctx context.Context , name string , r io.Reader ) error {
@@ -596,6 +647,27 @@ func (b *mockBucket) GetRange(ctx context.Context, name string, off, length int6
596
647
return nil , errors .New ("GetRange has not been mocked" )
597
648
}
598
649
650
+ func (b * mockBucket ) Iter (ctx context.Context , dir string , f func (string ) error , options ... IterOption ) error {
651
+ if b .iter != nil {
652
+ return b .iter (ctx , dir , f , options ... )
653
+ }
654
+ return errors .New ("Iter has not been mocked" )
655
+ }
656
+
657
+ func (b * mockBucket ) Exists (ctx context.Context , name string ) (bool , error ) {
658
+ if b .exists != nil {
659
+ return b .exists (ctx , name )
660
+ }
661
+ return false , errors .New ("Exists has not been mocked" )
662
+ }
663
+
664
+ func (b * mockBucket ) Attributes (ctx context.Context , name string ) (ObjectAttributes , error ) {
665
+ if b .attributes != nil {
666
+ return b .attributes (ctx , name )
667
+ }
668
+ return ObjectAttributes {}, errors .New ("Attributes has not been mocked" )
669
+ }
670
+
599
671
func Test_TryToGetSizeLimitedReader (t * testing.T ) {
600
672
b := & bytes.Buffer {}
601
673
r := io .LimitReader (b , 1024 )
0 commit comments