github.com/openshift/installer@v1.4.17/pkg/asset/ignition/machine/master_ignition_customizations_test.go (about) 1 package machine 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/openshift/installer/pkg/asset" 10 "github.com/openshift/installer/pkg/asset/ignition" 11 "github.com/openshift/installer/pkg/asset/installconfig" 12 "github.com/openshift/installer/pkg/asset/tls" 13 "github.com/openshift/installer/pkg/ipnet" 14 "github.com/openshift/installer/pkg/types" 15 "github.com/openshift/installer/pkg/types/aws" 16 ) 17 18 // TestMasterIgnitionCustomizationsGenerate tests generating the master ignition check asset. 19 func TestMasterIgnitionCustomizationsGenerate(t *testing.T) { 20 cases := []struct { 21 name string 22 customize bool 23 assetExpected bool 24 }{ 25 { 26 name: "not customized", 27 customize: false, 28 assetExpected: false, 29 }, 30 { 31 name: "pointer customized", 32 customize: true, 33 assetExpected: true, 34 }, 35 } 36 37 for _, tc := range cases { 38 t.Run(tc.name, func(t *testing.T) { 39 installConfig := installconfig.MakeAsset( 40 &types.InstallConfig{ 41 Networking: &types.Networking{ 42 ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")}, 43 }, 44 Platform: types.Platform{ 45 AWS: &aws.Platform{ 46 Region: "us-east", 47 }, 48 }, 49 }) 50 51 rootCA := &tls.RootCA{} 52 err := rootCA.Generate(context.Background(), nil) 53 assert.NoError(t, err, "unexpected error generating root CA") 54 55 parents := asset.Parents{} 56 parents.Add(installConfig, rootCA) 57 58 master := &Master{} 59 err = master.Generate(context.Background(), parents) 60 assert.NoError(t, err, "unexpected error generating master asset") 61 62 if tc.customize == true { 63 // Modify the master config, emulating a customization to the pointer 64 master.Config.Storage.Files = append(master.Config.Storage.Files, 65 ignition.FileFromString("/etc/foo", "root", 0644, "foo")) 66 } 67 68 parents.Add(master) 69 masterIgnCheck := &MasterIgnitionCustomizations{} 70 err = masterIgnCheck.Generate(context.Background(), parents) 71 assert.NoError(t, err, "unexpected error generating master ignition check asset") 72 73 actualFiles := masterIgnCheck.Files() 74 if tc.assetExpected == true { 75 assert.Equal(t, 1, len(actualFiles), "unexpected number of files in master state") 76 assert.Equal(t, masterMachineConfigFileName, actualFiles[0].Filename, "unexpected name for master ignition config") 77 } else { 78 assert.Equal(t, 0, len(actualFiles), "unexpected number of files in master state") 79 } 80 }) 81 } 82 }