@@ -54,33 +54,12 @@ func TestComponent(t *testing.T) {
5454
5555 // Setup phase: Create DNS zones for testing
5656 suite .Setup (t , func (t * testing.T , atm * helper.Atmos ) {
57- randomID := suite .GetRandomIdentifier ()
58- domainName := fmt .Sprintf ("example-%s.net" , randomID )
59-
60- // Deploy the primary DNS zone
61- inputs := map [string ]interface {}{
62- "domain_names" : []string {domainName },
63- }
64-
65- primaryDnsComponent := helper .NewAtmosComponent ("dns-primary" , "default-test" , inputs )
66- atm .Deploy (primaryDnsComponent )
67-
68- primaryZones := map [string ]zone {}
69- atm .OutputStruct (primaryDnsComponent , "zones" , & primaryZones )
70-
71- primaryDomains := make ([]string , 0 , len (primaryZones ))
72- for k := range primaryZones {
73- primaryDomains = append (primaryDomains , k )
74- }
75-
76- primaryDomainName := primaryDomains [0 ]
77-
7857 // Deploy the delegated DNS zone
79- inputs = map [string ]interface {}{
58+ inputs : = map [string ]interface {}{
8059 "zone_config" : []map [string ]interface {}{
8160 {
82- "subdomain" : randomID ,
83- "zone_name" : primaryDomainName ,
61+ "subdomain" : suite . GetRandomIdentifier () ,
62+ "zone_name" : "components.cptest.test-automation.app" ,
8463 },
8564 },
8665 }
@@ -89,31 +68,16 @@ func TestComponent(t *testing.T) {
8968
9069 // Teardown phase: Destroy the DNS zones created during setup
9170 suite .TearDown (t , func (t * testing.T , atm * helper.Atmos ) {
92- dnsPrimaryComponent := helper .NewAtmosComponent ("dns-primary" , "default-test" , map [string ]interface {}{})
93-
94- primaryZones := map [string ]zone {}
95- atm .OutputStruct (dnsPrimaryComponent , "zones" , & primaryZones )
96-
97- primaryDomains := make ([]string , 0 , len (primaryZones ))
98- for k := range primaryZones {
99- primaryDomains = append (primaryDomains , k )
100- }
101-
102- primaryDomainName := primaryDomains [0 ]
103-
104- randomID := suite .GetRandomIdentifier ()
105-
71+ // Deploy the delegated DNS zone
10672 inputs := map [string ]interface {}{
10773 "zone_config" : []map [string ]interface {}{
10874 {
109- "subdomain" : randomID ,
110- "zone_name" : primaryDomainName ,
75+ "subdomain" : suite . GetRandomIdentifier () ,
76+ "zone_name" : "components.cptest.test-automation.app" ,
11177 },
11278 },
11379 }
114-
115- atm .GetAndDestroy ("dns-delegated" , "default-test" , inputs )
116- atm .GetAndDestroy ("dns-primary" , "default-test" , map [string ]interface {}{})
80+ atm .GetAndDeploy ("dns-delegated" , "default-test" , inputs )
11781 })
11882
11983 // Test phase: Validate the functionality of the ALB component
@@ -194,6 +158,12 @@ func TestComponent(t *testing.T) {
194158
195159 schemaExistsInRdsInstance := aws .GetWhetherSchemaExistsInRdsPostgresInstance (t , dbUrl , int32 (dbPort ), adminUsername , adminUserPassword , databaseName )
196160 assert .True (t , schemaExistsInRdsInstance )
161+
162+ schemaExistsInRdsInstance = aws .GetWhetherSchemaExistsInRdsPostgresInstance (t , masterHostname , int32 (dbPort ), adminUsername , adminUserPassword , databaseName )
163+ assert .True (t , schemaExistsInRdsInstance )
164+
165+ schemaExistsInRdsInstance = aws .GetWhetherSchemaExistsInRdsPostgresInstance (t , replicasHostname , int32 (dbPort ), adminUsername , adminUserPassword , databaseName )
166+ assert .True (t , schemaExistsInRdsInstance )
197167 })
198168
199169 // Test phase: Validate the functionality of the ALB component
@@ -232,7 +202,7 @@ func TestComponent(t *testing.T) {
232202 assert .Equal (t , expectedMasterHostname , masterHostname )
233203
234204 ssmKeyPaths := atm .OutputList (component , "ssm_key_paths" )
235- assert .Equal (t , 6 , len (ssmKeyPaths ))
205+ assert .Equal (t , 7 , len (ssmKeyPaths ))
236206
237207 kmsKeyArn := atm .Output (component , "kms_key_arn" )
238208 assert .NotEmpty (t , kmsKeyArn )
@@ -253,6 +223,23 @@ func TestComponent(t *testing.T) {
253223
254224 masterHostnameDNSRecord := aws .GetRoute53Record (t , delegatedDomainNZoneId , masterHostname , "CNAME" , awsRegion )
255225 assert .Equal (t , * masterHostnameDNSRecord .ResourceRecords [0 ].Value , configMap ["endpoint" ])
226+
227+ passwordSSMKey , ok := configMap ["password_ssm_key" ].(string )
228+ assert .True (t , ok , "password_ssm_key should be a string" )
229+
230+ adminUserPassword := aws .GetParameter (t , awsRegion , passwordSSMKey )
231+
232+ dbUrl , ok := configMap ["endpoint" ].(string )
233+ assert .True (t , ok , "endpoint should be a string" )
234+
235+ dbPort , ok := inputs ["database_port" ].(int )
236+ assert .True (t , ok , "database_port should be an int" )
237+
238+ schemaExistsInRdsInstance := aws .GetWhetherSchemaExistsInRdsPostgresInstance (t , dbUrl , int32 (dbPort ), adminUsername , adminUserPassword , databaseName )
239+ assert .True (t , schemaExistsInRdsInstance )
240+
241+ schemaExistsInRdsInstance = aws .GetWhetherSchemaExistsInRdsPostgresInstance (t , masterHostname , int32 (dbPort ), adminUsername , adminUserPassword , databaseName )
242+ assert .True (t , schemaExistsInRdsInstance )
256243 })
257244 })
258245}
0 commit comments