github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/backend/mock_backend.go (about)

     1  // Package backend contains implementation of various backend providers.
     2  /*
     3   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package backend
     6  
     7  import (
     8  	"context"
     9  	"io"
    10  	"math"
    11  	"net/http"
    12  
    13  	"github.com/NVIDIA/aistore/api/apc"
    14  	"github.com/NVIDIA/aistore/cmn"
    15  	"github.com/NVIDIA/aistore/cmn/cos"
    16  	"github.com/NVIDIA/aistore/core"
    17  	"github.com/NVIDIA/aistore/core/meta"
    18  )
    19  
    20  const mock = "mock-backend"
    21  
    22  type mockbp struct {
    23  	t core.TargetPut
    24  	base
    25  }
    26  
    27  // interface guard
    28  var _ core.Backend = (*mockbp)(nil)
    29  
    30  func NewDummyBackend(t core.TargetPut) (core.Backend, error) {
    31  	return &mockbp{
    32  		t:    t,
    33  		base: base{mock},
    34  	}, nil
    35  }
    36  
    37  func (*mockbp) MaxPageSize(*meta.Bck) uint { return math.MaxUint32 }
    38  
    39  func (*mockbp) HeadBucket(_ context.Context, bck *meta.Bck) (cos.StrKVs, int, error) {
    40  	return cos.StrKVs{}, http.StatusNotFound, cmn.NewErrRemoteBckOffline(bck.Bucket())
    41  }
    42  
    43  func (*mockbp) ListObjects(bck *meta.Bck, _ *apc.LsoMsg, _ *cmn.LsoRes) (int, error) {
    44  	return http.StatusNotFound, cmn.NewErrRemoteBckOffline(bck.Bucket())
    45  }
    46  
    47  // cannot fail - return empty list
    48  func (*mockbp) ListBuckets(cmn.QueryBcks) (bcks cmn.Bcks, ecode int, err error) {
    49  	return
    50  }
    51  
    52  func (*mockbp) HeadObj(_ context.Context, lom *core.LOM, _ *http.Request) (*cmn.ObjAttrs, int, error) {
    53  	return &cmn.ObjAttrs{}, http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
    54  }
    55  
    56  func (*mockbp) GetObj(_ context.Context, lom *core.LOM, _ cmn.OWT, _ *http.Request) (int, error) {
    57  	return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
    58  }
    59  
    60  func (*mockbp) GetObjReader(context.Context, *core.LOM, int64, int64) (res core.GetReaderResult) {
    61  	return
    62  }
    63  
    64  func (*mockbp) PutObj(_ io.ReadCloser, lom *core.LOM, _ *http.Request) (int, error) {
    65  	return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
    66  }
    67  
    68  func (*mockbp) DeleteObj(lom *core.LOM) (int, error) {
    69  	return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
    70  }