sigs.k8s.io/cluster-api@v1.7.1/cmd/clusterctl/internal/test/fake_variable_client.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 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 test 18 19 import ( 20 "github.com/pkg/errors" 21 ) 22 23 // FakeVariableClient provides a VariableClient backed by a map. 24 type FakeVariableClient struct { 25 variables map[string]string 26 } 27 28 func (f FakeVariableClient) Get(key string) (string, error) { 29 if val, ok := f.variables[key]; ok { 30 return val, nil 31 } 32 return "", errors.Errorf("value for variable %q is not set", key) 33 } 34 35 func (f FakeVariableClient) Set(key, value string) { 36 f.variables[key] = value 37 } 38 39 func (f *FakeVariableClient) WithVar(key, value string) *FakeVariableClient { 40 f.variables[key] = value 41 return f 42 } 43 44 func NewFakeVariableClient() *FakeVariableClient { 45 return &FakeVariableClient{ 46 variables: map[string]string{}, 47 } 48 }