Skip to content

Commit 042f0e5

Browse files
committed
add test
1 parent cfcdbd6 commit 042f0e5

File tree

3 files changed

+822
-175
lines changed

3 files changed

+822
-175
lines changed

internal/services/tem/blockedlist.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func ResourceBlockedListCreate(ctx context.Context, d *schema.ResourceData, m in
6161
return diag.FromErr(err)
6262
}
6363

64-
region, domainID, err := regional.ParseID(d.Get("domain_id").(string))
64+
_, domainID, err := regional.ParseID(d.Get("domain_id").(string))
6565
if err != nil {
6666
return diag.FromErr(err)
6767
}
@@ -70,7 +70,7 @@ func ResourceBlockedListCreate(ctx context.Context, d *schema.ResourceData, m in
7070
reason := d.Get("reason").(string)
7171
typeBlockedList := d.Get("type").(string)
7272

73-
_, err = api.BulkCreateBlocklists(&tem.BulkCreateBlocklistsRequest{
73+
resp, err := api.BulkCreateBlocklists(&tem.BulkCreateBlocklistsRequest{
7474
Emails: emails,
7575
Region: region,
7676
DomainID: domainID,
@@ -81,39 +81,43 @@ func ResourceBlockedListCreate(ctx context.Context, d *schema.ResourceData, m in
8181
return diag.FromErr(err)
8282
}
8383

84-
d.SetId(fmt.Sprintf("%s-%s", region, domainID))
84+
d.SetId(fmt.Sprintf("%s/%s", region, resp.Blocklists[0].ID))
8585

8686
return ResourceBlockedListRead(ctx, d, m)
8787
}
8888

8989
func ResourceBlockedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
90-
api, region, _, err := NewAPIWithRegionAndID(m, d.Id())
90+
api, region, domainID, err := NewAPIWithRegionAndID(m, d.Get("domain_id").(string))
9191
if err != nil {
9292
return diag.FromErr(err)
9393
}
9494

9595
blocklists, err := api.ListBlocklists(&tem.ListBlocklistsRequest{
9696
Region: region,
9797
Email: scw.StringPtr(d.Get("email").(string)),
98-
DomainID: d.Get("domain_id").(string),
98+
DomainID: domainID,
9999
}, scw.WithContext(ctx))
100100
if err != nil {
101101
if httperrors.Is404(err) {
102102
d.SetId("")
103+
103104
return nil
104105
}
106+
105107
return diag.FromErr(err)
106108
}
107109

108110
if len(blocklists.Blocklists) == 0 {
109111
d.SetId("")
112+
110113
return nil
111114
}
112115

113116
_ = d.Set("email", blocklists.Blocklists[0].Email)
114117
_ = d.Set("reason", blocklists.Blocklists[0].Reason)
115-
_ = d.Set("domain_id", blocklists.Blocklists[0].DomainID)
118+
_ = d.Set("domain_id", fmt.Sprintf("%s/%s", region, blocklists.Blocklists[0].DomainID))
116119
_ = d.Set("type", blocklists.Blocklists[0].Type)
120+
117121
return nil
118122
}
119123

@@ -130,6 +134,8 @@ func ResourceBlockedListDelete(ctx context.Context, d *schema.ResourceData, m in
130134
if err != nil && !httperrors.Is404(err) {
131135
return diag.FromErr(err)
132136
}
137+
133138
d.SetId("")
139+
134140
return nil
135141
}

internal/services/tem/blockedlist_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func TestAccBlockedList_Basic(t *testing.T) {
6969
})
7070
}
7171

72-
// Checks if the blocked email is present in Scaleway TEM API
7372
func isBlockedEmailPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
7473
return func(state *terraform.State) error {
7574
rs, ok := state.RootModule().Resources[n]
@@ -85,11 +84,10 @@ func isBlockedEmailPresent(tt *acctest.TestTools, n string) resource.TestCheckFu
8584
blockedEmail := rs.Primary.Attributes["email"]
8685

8786
blocklists, err := api.ListBlocklists(&temSDK.ListBlocklistsRequest{
88-
Region: scw.Region(region),
87+
Region: region,
8988
DomainID: domainID,
9089
Email: scw.StringPtr(blockedEmail),
9190
}, scw.WithContext(context.Background()))
92-
9391
if err != nil {
9492
return err
9593
}
@@ -102,7 +100,6 @@ func isBlockedEmailPresent(tt *acctest.TestTools, n string) resource.TestCheckFu
102100
}
103101
}
104102

105-
// Checks if the blocked email is properly destroyed
106103
func isBlockedEmailDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
107104
return func(state *terraform.State) error {
108105
for _, rs := range state.RootModule().Resources {
@@ -118,11 +115,10 @@ func isBlockedEmailDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
118115
blockedEmail := rs.Primary.Attributes["email"]
119116

120117
blocklists, err := api.ListBlocklists(&temSDK.ListBlocklistsRequest{
121-
Region: scw.Region(region),
118+
Region: region,
122119
DomainID: domainID,
123120
Email: scw.StringPtr(blockedEmail),
124121
}, scw.WithContext(context.Background()))
125-
126122
if err != nil {
127123
return err
128124
}

0 commit comments

Comments
 (0)