Skip to content

Commit 50173cd

Browse files
committed
test: add multiple test
1 parent d0184a7 commit 50173cd

File tree

5 files changed

+7832
-461
lines changed

5 files changed

+7832
-461
lines changed

internal/services/domain/domains_registration.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func ResourceDomainsRegistration() *schema.Resource {
2121
UpdateContext: resourceDomainsRegistrationUpdate,
2222
DeleteContext: resourceDomainsRegistrationDelete,
2323
Timeouts: &schema.ResourceTimeout{
24-
Create: schema.DefaultTimeout(defaultDomainRecordTimeout),
25-
Read: schema.DefaultTimeout(defaultDomainRecordTimeout),
26-
Update: schema.DefaultTimeout(defaultDomainRecordTimeout),
27-
Delete: schema.DefaultTimeout(defaultDomainRecordTimeout),
28-
Default: schema.DefaultTimeout(defaultDomainRecordTimeout),
24+
Create: schema.DefaultTimeout(defaultDomainRegistrationTimeout),
25+
Read: schema.DefaultTimeout(defaultDomainRegistrationTimeout),
26+
Update: schema.DefaultTimeout(defaultDomainRegistrationTimeout),
27+
Delete: schema.DefaultTimeout(defaultDomainRegistrationTimeout),
28+
Default: schema.DefaultTimeout(defaultDomainRegistrationTimeout),
2929
},
3030
Importer: &schema.ResourceImporter{
3131
StateContext: schema.ImportStatePassthroughContext,
@@ -503,7 +503,7 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
503503

504504
computedDnssec := false
505505

506-
if firstResp.Dnssec.Status == "enabeld" || firstResp.Dnssec.Status == "enabling" {
506+
if firstResp.Dnssec.Status == "enabled" {
507507
computedDnssec = true
508508
}
509509

@@ -575,6 +575,10 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
575575
}
576576
}
577577
}
578+
_, err = waitForAutoRenewStatus(ctx, registrarAPI, domainName, d.Timeout(schema.TimeoutUpdate))
579+
if err != nil {
580+
return diag.FromErr(err)
581+
}
578582
}
579583
}
580584

@@ -613,6 +617,10 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
613617
}
614618
}
615619
}
620+
_, err = waitForDNSSECStatus(ctx, registrarAPI, domainName, d.Timeout(schema.TimeoutUpdate))
621+
if err != nil {
622+
return diag.FromErr(err)
623+
}
616624
}
617625
}
618626

internal/services/domain/domains_registration_test.go

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ func TestAccDomainRegistration_SingleDomainWithUpdate(t *testing.T) {
8585
})
8686
}
8787

88-
func TestAccDomainRegistration_MultipleDomainsNoUpdate(t *testing.T) {
88+
func TestAccDomainRegistration_MultipleDomainsUpdate(t *testing.T) {
8989
tt := acctest.NewTestTools(t)
9090
defer tt.Cleanup()
9191

92-
domainName1 := "test-multiple-1.com"
93-
domainName2 := "test-multiple-2.com"
94-
domainName3 := "test-multiple-3.com"
92+
domainName1 := "test-multiple-118.com"
93+
domainName2 := "test-multiple-119.com"
94+
domainName3 := "test-multiple-120.com"
9595

9696
resource.ParallelTest(t, resource.TestCase{
9797
PreCheck: func() { acctest.PreCheck(t) },
@@ -122,14 +122,77 @@ func TestAccDomainRegistration_MultipleDomainsNoUpdate(t *testing.T) {
122122
`, domainName1, domainName2, domainName3),
123123
Check: resource.ComposeTestCheckFunc(
124124
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "domain_names.0", domainName1),
125-
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "domain_names.0", domainName2),
126-
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "domain_names.0", domainName3),
125+
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "domain_names.1", domainName2),
126+
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "domain_names.2", domainName3),
127+
),
128+
},
129+
{
130+
Config: fmt.Sprintf(`
131+
resource "scaleway_domain_domains_registration" "multi" {
132+
domain_names = ["%s", "%s", "%s"]
133+
duration_in_years = 1
134+
135+
owner_contact {
136+
firstname = "John"
137+
lastname = "DOE"
138+
139+
phone_number = "+1.23456789"
140+
address_line_1 = "123 Main Street"
141+
city = "Paris"
142+
zip = "75001"
143+
country = "FR"
144+
legal_form = "individual"
145+
vat_identification_code = "FR12345678901"
146+
company_identification_code = "123456789"
147+
}
148+
149+
auto_renew = true
150+
dnssec = true
151+
}
152+
`, domainName1, domainName2, domainName3),
153+
Check: resource.ComposeTestCheckFunc(
154+
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "auto_renew", "true"),
155+
resource.TestCheckResourceAttr("scaleway_domain_domains_registration.multi", "dnssec", "true"),
156+
testAccCheckDomainStatus(tt, domainSDK.DomainFeatureStatusEnabled.String(), domainSDK.DomainFeatureStatusEnabled.String()),
127157
),
128158
},
129159
},
130160
})
131161
}
132162

163+
func testAccCheckDomainStatus(tt *acctest.TestTools, expectedAutoRenew, expectedDNSSEC string) resource.TestCheckFunc {
164+
return func(state *terraform.State) error {
165+
for _, rs := range state.RootModule().Resources {
166+
if rs.Type != "scaleway_domain_domains_registration" {
167+
continue
168+
}
169+
170+
registrarAPI := domain.NewRegistrarDomainAPI(tt.Meta)
171+
domainNames, err := domain.ExtractDomainsFromTaskID(nil, rs.Primary.ID, registrarAPI)
172+
if err != nil {
173+
return fmt.Errorf("error extracting domains: %w", err)
174+
}
175+
176+
for _, domainName := range domainNames {
177+
domainResp, getErr := registrarAPI.GetDomain(&domainSDK.RegistrarAPIGetDomainRequest{
178+
Domain: domainName,
179+
})
180+
if getErr != nil {
181+
return fmt.Errorf("failed to get details for domain %s: %w", domainName, getErr)
182+
}
183+
184+
if domainResp.AutoRenewStatus.String() != expectedAutoRenew {
185+
return fmt.Errorf("domain %s has auto_renew status %s, expected %s", domainName, domainResp.AutoRenewStatus, expectedAutoRenew)
186+
}
187+
if domainResp.Dnssec.Status.String() != expectedDNSSEC {
188+
return fmt.Errorf("domain %s has dnssec status %s, expected %s", domainName, domainResp.Dnssec.Status.String(), expectedDNSSEC)
189+
}
190+
}
191+
}
192+
return nil
193+
}
194+
}
195+
133196
func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
134197
return func(state *terraform.State) error {
135198
for _, rs := range state.RootModule().Resources {

internal/services/domain/testdata/domain-registration-multiple-domains-no-update.cassette.yaml

Lines changed: 495 additions & 446 deletions
Large diffs are not rendered by default.

internal/services/domain/testdata/domain-registration-multiple-domains-update.cassette.yaml

Lines changed: 7226 additions & 0 deletions
Large diffs are not rendered by default.

internal/services/domain/waiters.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
)
1111

1212
const (
13-
defaultDomainRecordTimeout = 5 * time.Minute
14-
defaultDomainZoneTimeout = 5 * time.Minute
15-
defaultDomainZoneRetryInterval = 5 * time.Second
13+
defaultDomainRecordTimeout = 5 * time.Minute
14+
defaultDomainZoneTimeout = 5 * time.Minute
15+
defaultDomainZoneRetryInterval = 5 * time.Second
16+
defaultDomainRegistrationTimeout = 30 * time.Minute
1617
)
1718

1819
func waitForDNSZone(ctx context.Context, domainAPI *domain.API, dnsZone string, timeout time.Duration) (*domain.DNSZone, error) {
@@ -54,3 +55,27 @@ func waitForDomainsRegistration(ctx context.Context, api *domain.RegistrarAPI, d
5455
RetryInterval: &retryInterval,
5556
}, scw.WithContext(ctx))
5657
}
58+
59+
func waitForAutoRenewStatus(ctx context.Context, api *domain.RegistrarAPI, domainName string, timeout time.Duration) (*domain.Domain, error) {
60+
retryInterval := defaultWaitDomainsRegistrationRetryInterval
61+
if transport.DefaultWaitRetryInterval != nil {
62+
retryInterval = *transport.DefaultWaitRetryInterval
63+
}
64+
return api.WaitForAutoRenewStatus(&domain.WaitForAutoRenewStatusRequest{
65+
Domain: domainName,
66+
Timeout: scw.TimeDurationPtr(timeout),
67+
RetryInterval: &retryInterval,
68+
}, scw.WithContext(ctx))
69+
}
70+
71+
func waitForDNSSECStatus(ctx context.Context, api *domain.RegistrarAPI, domainName string, timeout time.Duration) (*domain.Domain, error) {
72+
retryInterval := defaultWaitDomainsRegistrationRetryInterval
73+
if transport.DefaultWaitRetryInterval != nil {
74+
retryInterval = *transport.DefaultWaitRetryInterval
75+
}
76+
return api.WaitForDNSSECStatus(&domain.WaitForDNSSECStatusRequest{
77+
Domain: domainName,
78+
Timeout: scw.TimeDurationPtr(timeout),
79+
RetryInterval: &retryInterval,
80+
}, scw.WithContext(ctx))
81+
}

0 commit comments

Comments
 (0)