sigs.k8s.io/cluster-api@v1.7.1/cmd/clusterctl/client/config/variables_client_test.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 config 18 19 import ( 20 "testing" 21 22 . "github.com/onsi/gomega" 23 24 "sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test" 25 ) 26 27 // Ensures FakeReader implements the Reader interface. 28 var _ Reader = &test.FakeReader{} 29 30 // Ensures the FakeVariableClient implements VariablesClient. 31 var _ VariablesClient = &test.FakeVariableClient{} 32 33 func Test_variables_Get(t *testing.T) { 34 reader := test.NewFakeReader().WithVar("foo", "bar") 35 36 type args struct { 37 key string 38 } 39 tests := []struct { 40 name string 41 args args 42 want string 43 wantErr bool 44 }{ 45 { 46 name: "Returns value if the variable exists", 47 args: args{ 48 key: "foo", 49 }, 50 want: "bar", 51 wantErr: false, 52 }, 53 { 54 name: "Returns error if the variable does not exist", 55 args: args{ 56 key: "baz", 57 }, 58 wantErr: true, 59 }, 60 } 61 for _, tt := range tests { 62 t.Run(tt.name, func(t *testing.T) { 63 g := NewWithT(t) 64 p := &variablesClient{ 65 reader: reader, 66 } 67 got, err := p.Get(tt.args.key) 68 if tt.wantErr { 69 g.Expect(err).To(HaveOccurred()) 70 return 71 } 72 73 g.Expect(err).ToNot(HaveOccurred()) 74 g.Expect(got).To(Equal(tt.want)) 75 }) 76 } 77 }