github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/imagetranslation/fake_source.go (about) 1 /* 2 Copyright 2017 Mirantis 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package imagetranslation 18 19 import ( 20 "context" 21 22 "github.com/Mirantis/virtlet/pkg/api/virtlet.k8s/v1" 23 ) 24 25 type objectConfig struct { 26 name string 27 translation v1.ImageTranslation 28 } 29 30 var _ TranslationConfig = objectConfig{} 31 32 // Name implements TranslationConfig Name 33 func (c objectConfig) ConfigName() string { 34 return c.name 35 } 36 37 // Payload implements TranslationConfig Payload 38 func (c objectConfig) Payload() (v1.ImageTranslation, error) { 39 return c.translation, nil 40 } 41 42 type fakeConfigSource struct { 43 configs map[string]v1.ImageTranslation 44 } 45 46 var _ ConfigSource = fakeConfigSource{} 47 48 // Configs implements ConfigSource Configs 49 func (cs fakeConfigSource) Configs(ctx context.Context) ([]TranslationConfig, error) { 50 var result []TranslationConfig 51 for name, tr := range cs.configs { 52 result = append(result, objectConfig{name: name, translation: tr}) 53 } 54 return result, nil 55 } 56 57 // Description implements ConfigSource Description 58 func (cs fakeConfigSource) Description() string { 59 return "fake config source" 60 } 61 62 // NewFakeConfigSource is a factory for a fake config source 63 func NewFakeConfigSource(configs map[string]v1.ImageTranslation) ConfigSource { 64 return &fakeConfigSource{configs: configs} 65 }