github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/core/mock/bmd_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  	"github.com/NVIDIA/aistore/api/apc"
     9  	"github.com/NVIDIA/aistore/cmn"
    10  	"github.com/NVIDIA/aistore/cmn/debug"
    11  	"github.com/NVIDIA/aistore/core/meta"
    12  )
    13  
    14  type BownerMock struct {
    15  	meta.BMD
    16  }
    17  
    18  // interface guard
    19  var _ meta.Bowner = (*BownerMock)(nil)
    20  
    21  func (r BownerMock) Get() *meta.BMD { return &r.BMD }
    22  
    23  func NewBaseBownerMock(bcks ...*meta.Bck) *BownerMock {
    24  	var (
    25  		providers  = make(meta.Providers)
    26  		namespaces = make(meta.Namespaces)
    27  		buckets    = make(meta.Buckets)
    28  	)
    29  	providers[apc.AIS] = namespaces
    30  	debug.Assert(cmn.NsGlobalUname == cmn.NsGlobal.Uname())
    31  	namespaces[cmn.NsGlobalUname] = buckets
    32  
    33  	owner := &BownerMock{BMD: meta.BMD{Version: 1, Providers: providers}}
    34  	for _, bck := range bcks {
    35  		bck.Props.BID = bck.MaskBID(owner.BMD.Version)
    36  		owner.Add(bck)
    37  	}
    38  	return owner
    39  }