github.com/openshift/installer@v1.4.17/pkg/asset/manifests/operators_test.go (about) 1 package manifests 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "k8s.io/utils/pointer" 9 10 "github.com/openshift/installer/pkg/ipnet" 11 "github.com/openshift/installer/pkg/types" 12 vspheretypes "github.com/openshift/installer/pkg/types/vsphere" 13 ) 14 15 // TestRedactedInstallConfig tests the redactedInstallConfig function. 16 func TestRedactedInstallConfig(t *testing.T) { 17 createInstallConfig := func() *types.InstallConfig { 18 return &types.InstallConfig{ 19 ObjectMeta: metav1.ObjectMeta{ 20 Name: "test-cluster", 21 }, 22 SSHKey: "test-ssh-key", 23 BaseDomain: "test-domain", 24 Networking: &types.Networking{ 25 MachineNetwork: []types.MachineNetworkEntry{ 26 {CIDR: *ipnet.MustParseCIDR("1.2.3.4/5")}, 27 }, 28 NetworkType: "test-network-type", 29 ClusterNetwork: []types.ClusterNetworkEntry{ 30 { 31 CIDR: *ipnet.MustParseCIDR("1.2.3.4/5"), 32 HostPrefix: 6, 33 }, 34 }, 35 ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("1.2.3.4/5")}, 36 }, 37 ControlPlane: &types.MachinePool{ 38 Name: "control-plane", 39 Replicas: pointer.Int64Ptr(3), 40 Architecture: types.ArchitectureAMD64, 41 }, 42 Compute: []types.MachinePool{ 43 { 44 Name: "compute", 45 Replicas: pointer.Int64Ptr(3), 46 Architecture: types.ArchitectureAMD64, 47 }, 48 }, 49 Platform: types.Platform{ 50 VSphere: &vspheretypes.Platform{ 51 DeprecatedUsername: "test-username", 52 DeprecatedPassword: "test-password", 53 VCenters: []vspheretypes.VCenter{{ 54 Server: "test-server-1", 55 Port: 443, 56 Username: "", 57 Password: "", 58 Datacenters: []string{"test-datacenter"}, 59 }}, 60 FailureDomains: []vspheretypes.FailureDomain{{ 61 Name: "test-failuredomain", 62 Region: "test-region", 63 Zone: "test-zone", 64 Server: "test-server-1", 65 Topology: vspheretypes.Topology{ 66 Datacenter: "test-datacenter", 67 ComputeCluster: "test-computecluster", 68 Networks: []string{"test-network"}, 69 Datastore: "test-datastore", 70 ResourcePool: "test-resourcepool", 71 Folder: "test-folder", 72 }, 73 }}, 74 }, 75 }, 76 PullSecret: "test-pull-secret", 77 } 78 } 79 expectedConfig := createInstallConfig() 80 expectedYaml := `baseDomain: test-domain 81 compute: 82 - architecture: amd64 83 name: compute 84 platform: {} 85 replicas: 3 86 controlPlane: 87 architecture: amd64 88 name: control-plane 89 platform: {} 90 replicas: 3 91 metadata: 92 creationTimestamp: null 93 name: test-cluster 94 networking: 95 clusterNetwork: 96 - cidr: 1.2.3.4/5 97 hostPrefix: 6 98 machineNetwork: 99 - cidr: 1.2.3.4/5 100 networkType: test-network-type 101 serviceNetwork: 102 - 1.2.3.4/5 103 platform: 104 vsphere: 105 failureDomains: 106 - name: test-failuredomain 107 region: test-region 108 server: test-server-1 109 topology: 110 computeCluster: test-computecluster 111 datacenter: test-datacenter 112 datastore: test-datastore 113 folder: test-folder 114 networks: 115 - test-network 116 resourcePool: test-resourcepool 117 zone: test-zone 118 vcenters: 119 - datacenters: 120 - test-datacenter 121 password: "" 122 server: test-server-1 123 user: "" 124 pullSecret: "" 125 sshKey: test-ssh-key 126 ` 127 ic := createInstallConfig() 128 actualYaml, err := redactedInstallConfig(*ic) 129 if assert.NoError(t, err, "unexpected error") { 130 assert.Equal(t, expectedYaml, string(actualYaml), "unexpected yaml") 131 } 132 assert.Equal(t, expectedConfig, ic, "install config was unexpectedly modified") 133 }