|
| 1 | +package defaults |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + "github.com/openshift/installer/pkg/types" |
| 9 | + "github.com/openshift/installer/pkg/types/aws" |
| 10 | +) |
| 11 | + |
| 12 | +func TestSetMachinePoolDefaults(t *testing.T) { |
| 13 | + cases := []struct { |
| 14 | + name string |
| 15 | + pool *aws.MachinePool |
| 16 | + role string |
| 17 | + expected *aws.MachinePool |
| 18 | + }{ |
| 19 | + { |
| 20 | + name: "nil pool", |
| 21 | + pool: nil, |
| 22 | + role: types.MachinePoolComputeRoleName, |
| 23 | + expected: nil, |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "empty pool - worker pool sets gp3", |
| 27 | + pool: &aws.MachinePool{}, |
| 28 | + role: types.MachinePoolComputeRoleName, |
| 29 | + expected: &aws.MachinePool{ |
| 30 | + EC2RootVolume: aws.EC2RootVolume{ |
| 31 | + Type: aws.VolumeTypeGp3, |
| 32 | + Size: defaultRootVolumeSize, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "empty pool - control plane pool sets gp3", |
| 38 | + pool: &aws.MachinePool{}, |
| 39 | + role: types.MachinePoolControlPlaneRoleName, |
| 40 | + expected: &aws.MachinePool{ |
| 41 | + EC2RootVolume: aws.EC2RootVolume{ |
| 42 | + Type: aws.VolumeTypeGp3, |
| 43 | + Size: defaultRootVolumeSize, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "empty pool - arbiter pool sets gp3", |
| 49 | + pool: &aws.MachinePool{}, |
| 50 | + role: types.MachinePoolArbiterRoleName, |
| 51 | + expected: &aws.MachinePool{ |
| 52 | + EC2RootVolume: aws.EC2RootVolume{ |
| 53 | + Type: aws.VolumeTypeGp3, |
| 54 | + Size: defaultRootVolumeSize, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "empty pool - edge pool sets gp2", |
| 60 | + pool: &aws.MachinePool{}, |
| 61 | + role: types.MachinePoolEdgeRoleName, |
| 62 | + expected: &aws.MachinePool{ |
| 63 | + EC2RootVolume: aws.EC2RootVolume{ |
| 64 | + Type: aws.VolumeTypeGp2, |
| 65 | + Size: defaultRootVolumeSize, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "pool with existing volume type - should not override", |
| 71 | + pool: &aws.MachinePool{ |
| 72 | + EC2RootVolume: aws.EC2RootVolume{ |
| 73 | + Type: aws.VolumeTypeGp2, |
| 74 | + Size: defaultRootVolumeSize, |
| 75 | + }, |
| 76 | + }, |
| 77 | + role: types.MachinePoolComputeRoleName, |
| 78 | + expected: &aws.MachinePool{ |
| 79 | + EC2RootVolume: aws.EC2RootVolume{ |
| 80 | + Type: aws.VolumeTypeGp2, |
| 81 | + Size: defaultRootVolumeSize, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + } |
| 86 | + |
| 87 | + for _, tc := range cases { |
| 88 | + t.Run(tc.name, func(t *testing.T) { |
| 89 | + SetMachinePoolDefaults(tc.pool, tc.role) |
| 90 | + assert.Equal(t, tc.expected, tc.pool, "unexpected machine pool defaults") |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments