github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/cmd/lhsmd/agent/fileid/testing.go (about) 1 // Copyright (c) 2018 DDN. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package fileid 6 7 import "fmt" 8 9 type ( 10 fileMap map[string][]byte 11 12 testManager struct { 13 files fileMap 14 } 15 ) 16 17 func (m *testManager) update(p string, fileID []byte) error { 18 return m.set(p, fileID) 19 } 20 21 func (m *testManager) set(p string, fileID []byte) error { 22 m.files[p] = fileID 23 24 return nil 25 } 26 27 func (m *testManager) get(p string) ([]byte, error) { 28 if attr, ok := m.files[p]; ok { 29 return attr, nil 30 } 31 return nil, fmt.Errorf("%s was not found in fileAttr map", p) 32 } 33 34 // EnableTestMode swaps out the real implementation for a test-friendly 35 // mock. 36 func EnableTestMode() { 37 UUID = Attribute{&testManager{ 38 files: make(fileMap), 39 }} 40 Hash = Attribute{&testManager{ 41 files: make(fileMap), 42 }} 43 URL = Attribute{&testManager{ 44 files: make(fileMap), 45 }} 46 } 47 48 // DisableTestMode re-enables normal operation. 49 func DisableTestMode() { 50 defaultAttrs() 51 }