forked from NVIDIA/aistore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend_mock.go
69 lines (53 loc) · 2.08 KB
/
backend_mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Package backend contains implementation of various backend providers.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package backend
import (
"context"
"io"
"math"
"net/http"
"github.com/artashesbalabekyan/aistore/api/apc"
"github.com/artashesbalabekyan/aistore/cluster"
"github.com/artashesbalabekyan/aistore/cluster/meta"
"github.com/artashesbalabekyan/aistore/cmn"
"github.com/artashesbalabekyan/aistore/cmn/cos"
)
const mock = "mock-backend"
type mockBP struct {
t cluster.TargetPut
}
// interface guard
var _ cluster.BackendProvider = (*mockBP)(nil)
func NewDummyBackend(t cluster.TargetPut) (cluster.BackendProvider, error) { return &mockBP{t: t}, nil }
func (*mockBP) Provider() string { return mock }
func (*mockBP) MaxPageSize() uint { return math.MaxUint32 }
func (*mockBP) CreateBucket(*meta.Bck) (int, error) {
return http.StatusBadRequest, cmn.NewErrUnsupp("create", mock+" bucket")
}
func (*mockBP) HeadBucket(_ ctx, bck *meta.Bck) (cos.StrKVs, int, error) {
return cos.StrKVs{}, http.StatusNotFound, cmn.NewErrRemoteBckOffline(bck.Bucket())
}
func (*mockBP) ListObjects(bck *meta.Bck, _ *apc.LsoMsg, _ *cmn.LsoResult) (int, error) {
return http.StatusNotFound, cmn.NewErrRemoteBckOffline(bck.Bucket())
}
// cannot fail - return empty list
func (*mockBP) ListBuckets(cmn.QueryBcks) (bcks cmn.Bcks, errCode int, err error) {
return
}
func (*mockBP) HeadObj(_ ctx, lom *cluster.LOM) (*cmn.ObjAttrs, int, error) {
return &cmn.ObjAttrs{}, http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
}
func (*mockBP) GetObj(_ ctx, lom *cluster.LOM, _ cmn.OWT) (int, error) {
return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
}
func (*mockBP) GetObjReader(context.Context, *cluster.LOM) (io.ReadCloser, *cos.Cksum, int, error) {
return nil, nil, 0, nil
}
func (*mockBP) PutObj(_ io.ReadCloser, lom *cluster.LOM) (int, error) {
return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
}
func (*mockBP) DeleteObj(lom *cluster.LOM) (int, error) {
return http.StatusNotFound, cmn.NewErrRemoteBckNotFound(lom.Bucket())
}