github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/core/mock/target_mock.go (about) 1 // Package mock provides a variety of mock implementations used for testing. 2 /* 3 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package mock 6 7 import ( 8 "context" 9 "net/http" 10 "net/url" 11 "time" 12 13 "github.com/NVIDIA/aistore/cmn" 14 "github.com/NVIDIA/aistore/core" 15 "github.com/NVIDIA/aistore/core/meta" 16 "github.com/NVIDIA/aistore/fs" 17 "github.com/NVIDIA/aistore/memsys" 18 ) 19 20 const mockID = "mock-id" 21 22 // TargetMock provides cluster.Target interface with mocked return values. 23 type TargetMock struct { 24 BO meta.Bowner 25 SO meta.Sowner 26 } 27 28 // interface guard 29 var _ core.Target = (*TargetMock)(nil) 30 31 func NewTarget(bo meta.Bowner) *TargetMock { 32 t := &TargetMock{BO: bo} 33 core.Tinit(t, NewStatsTracker(), false) 34 return t 35 } 36 37 func (t *TargetMock) Bowner() meta.Bowner { return t.BO } 38 func (t *TargetMock) Sowner() meta.Sowner { return t.SO } 39 40 func (*TargetMock) SID() string { return mockID } 41 func (*TargetMock) String() string { return "tmock" } 42 func (*TargetMock) Snode() *meta.Snode { return &meta.Snode{DaeID: mockID} } 43 func (*TargetMock) ClusterStarted() bool { return true } 44 func (*TargetMock) NodeStarted() bool { return true } 45 func (*TargetMock) DataClient() *http.Client { return http.DefaultClient } 46 func (*TargetMock) PageMM() *memsys.MMSA { return memsys.PageMM() } 47 func (*TargetMock) ByteMM() *memsys.MMSA { return memsys.ByteMM() } 48 49 func (*TargetMock) GetAllRunning(*core.AllRunningInOut, bool) {} 50 func (*TargetMock) PutObject(*core.LOM, *core.PutParams) error { return nil } 51 func (*TargetMock) FinalizeObj(*core.LOM, string, core.Xact, cmn.OWT) (int, error) { return 0, nil } 52 func (*TargetMock) EvictObject(*core.LOM) (int, error) { return 0, nil } 53 func (*TargetMock) DeleteObject(*core.LOM, bool) (int, error) { return 0, nil } 54 func (*TargetMock) Promote(*core.PromoteParams) (int, error) { return 0, nil } 55 func (*TargetMock) Backend(*meta.Bck) core.Backend { return nil } 56 func (*TargetMock) HeadObjT2T(*core.LOM, *meta.Snode) bool { return false } 57 func (*TargetMock) BMDVersionFixup(*http.Request, ...cmn.Bck) {} 58 func (*TargetMock) FSHC(error, string) {} 59 func (*TargetMock) OOS(*fs.CapStatus) fs.CapStatus { return fs.CapStatus{} } 60 61 func (*TargetMock) CopyObject(*core.LOM, core.DM, *core.CopyParams) (int64, error) { 62 return 0, nil 63 } 64 65 func (*TargetMock) GetCold(context.Context, *core.LOM, cmn.OWT) (int, error) { 66 return http.StatusOK, nil 67 } 68 69 func (*TargetMock) GetColdBlob(*core.BlobParams, *cmn.ObjAttrs) (core.Xact, error) { 70 return nil, nil 71 } 72 73 func (*TargetMock) Health(*meta.Snode, time.Duration, url.Values) ([]byte, int, error) { 74 return nil, 0, nil 75 }