github.com/openshift/installer@v1.4.17/pkg/asset/machines/gcp/machines_test.go (about) 1 // Package gcp generates Machine objects for gcp. 2 package gcp 3 4 import ( 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "k8s.io/apimachinery/pkg/runtime" 10 11 machinev1 "github.com/openshift/api/machine/v1" 12 machineapi "github.com/openshift/api/machine/v1beta1" 13 "github.com/openshift/installer/pkg/types" 14 ) 15 16 func TestConfigMasters(t *testing.T) { 17 clusterID := "test" 18 testCases := []struct { 19 testCase string 20 publishingStrategy types.PublishingStrategy 21 expectedTargetPools []string 22 }{ 23 { 24 testCase: "External", 25 publishingStrategy: types.ExternalPublishingStrategy, 26 expectedTargetPools: []string{ 27 fmt.Sprintf("%s-api", clusterID), 28 }, 29 }, 30 { 31 testCase: "Internal", 32 publishingStrategy: types.InternalPublishingStrategy, 33 expectedTargetPools: nil, 34 }, 35 } 36 37 for _, tc := range testCases { 38 machines := []machineapi.Machine{ 39 { 40 Spec: machineapi.MachineSpec{ 41 ProviderSpec: machineapi.ProviderSpec{ 42 Value: &runtime.RawExtension{Object: &machineapi.GCPMachineProviderSpec{}}, 43 }, 44 }, 45 }, 46 { 47 Spec: machineapi.MachineSpec{ 48 ProviderSpec: machineapi.ProviderSpec{ 49 Value: &runtime.RawExtension{Object: &machineapi.GCPMachineProviderSpec{}}, 50 }, 51 }, 52 }, 53 } 54 controlPlaneMachineSet := &machinev1.ControlPlaneMachineSet{ 55 Spec: machinev1.ControlPlaneMachineSetSpec{ 56 Template: machinev1.ControlPlaneMachineSetTemplate{ 57 OpenShiftMachineV1Beta1Machine: &machinev1.OpenShiftMachineV1Beta1MachineTemplate{ 58 Spec: machineapi.MachineSpec{ 59 ProviderSpec: machineapi.ProviderSpec{ 60 Value: &runtime.RawExtension{ 61 Object: &machineapi.GCPMachineProviderSpec{}, 62 }, 63 }, 64 }, 65 }, 66 }, 67 }, 68 } 69 t.Run(tc.testCase, func(t *testing.T) { 70 err := ConfigMasters(machines, controlPlaneMachineSet, clusterID, tc.publishingStrategy) 71 assert.NoError(t, err) 72 for _, machine := range machines { 73 providerSpec := machine.Spec.ProviderSpec.Value.Object.(*machineapi.GCPMachineProviderSpec) 74 assert.Equal(t, providerSpec.TargetPools, tc.expectedTargetPools) 75 } 76 }) 77 } 78 }