github.com/openshift/installer@v1.4.17/pkg/asset/agent/joiner/addnodesconfig_test.go (about) 1 package joiner 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 "github.com/stretchr/testify/assert" 8 9 "github.com/openshift/installer/pkg/asset" 10 "github.com/openshift/installer/pkg/asset/mock" 11 ) 12 13 func TestAddNodesConfig_Load(t *testing.T) { 14 cases := []struct { 15 name string 16 addNodesParamsData string 17 nodesConfigData string 18 expectedError string 19 }{ 20 { 21 name: "default", 22 nodesConfigData: `hosts: 23 - hostname: master-0 24 interfaces: 25 - name: eth0 26 macAddress: 00:ef:29:72:b9:771`, 27 }, 28 { 29 name: "empty nodes-config.yaml", 30 expectedError: "hosts: Required value: at least one host must be defined", 31 }, 32 { 33 name: "ssh key", 34 nodesConfigData: `hosts: 35 - hostname: master-0 36 interfaces: 37 - name: eth0 38 macAddress: 00:ef:29:72:b9:771 39 sshKey: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q=="`, 40 }, 41 { 42 name: "invalid ssh key", 43 nodesConfigData: `hosts: 44 - hostname: master-0 45 interfaces: 46 - name: eth0 47 macAddress: 00:ef:29:72:b9:771 48 sshKey: "not a valid ssh key"`, 49 expectedError: "sshKey: Invalid value: \"not a valid ssh key\": ssh: no key found", 50 }, 51 } 52 for _, tc := range cases { 53 t.Run(tc.name, func(t *testing.T) { 54 mockCtrl := gomock.NewController(t) 55 defer mockCtrl.Finish() 56 57 if tc.addNodesParamsData == "" { 58 tc.addNodesParamsData = "{}" 59 } 60 61 fileFetcher := mock.NewMockFileFetcher(mockCtrl) 62 fileFetcher.EXPECT().FetchByName(addNodesParamsFile). 63 Return( 64 &asset.File{ 65 Filename: addNodesParamsFile, 66 Data: []byte(tc.addNodesParamsData)}, 67 nil, 68 ) 69 fileFetcher.EXPECT().FetchByName(nodesConfigFilename). 70 Return( 71 &asset.File{ 72 Filename: nodesConfigFilename, 73 Data: []byte(tc.nodesConfigData)}, 74 nil, 75 ) 76 77 addNodesConfig := &AddNodesConfig{} 78 _, err := addNodesConfig.Load(fileFetcher) 79 if tc.expectedError != "" { 80 assert.Equal(t, tc.expectedError, err.Error()) 81 } else { 82 assert.NoError(t, err) 83 } 84 }) 85 } 86 }