Skip to content

Commit 1c34cdb

Browse files
authored
Fixing the site_v3 resource tests (#521)
1 parent 8ee1891 commit 1c34cdb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

incapsula/resource_site_v3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func resourceSiteV3() *schema.Resource {
2323
log.Printf("[DEBUG] Starting to import site v3. Parameters: %s\n", d.Id())
2424

2525
if len(idSlice) != 2 || idSlice[0] == "" || idSlice[1] == "" {
26-
return nil, fmt.Errorf("unexpected format of ID (%q), expected site_id or account_id/site_id", d.Id())
26+
return nil, fmt.Errorf("unexpected format of ID (%q), expected account_id/site_id", d.Id())
2727
}
2828

2929
err := d.Set("account_id", idSlice[0])
@@ -34,7 +34,7 @@ func resourceSiteV3() *schema.Resource {
3434

3535
_, err = strconv.Atoi(idSlice[1])
3636
if err != nil {
37-
return nil, fmt.Errorf("unexpected format of ID (%q), expected site_id or account_id/site_id", d.Id())
37+
return nil, fmt.Errorf("unexpected format of ID (%q), expected account_id/site_id", d.Id())
3838
}
3939

4040
d.SetId(idSlice[1])

incapsula/resource_site_v3_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestIncapsulaSiteV3_Basic(t *testing.T) {
4444
ResourceName: siteV3ResourceName,
4545
ImportState: true,
4646
ImportStateVerify: true,
47+
ImportStateIdFunc: testSiteV3Importer,
4748
},
4849
},
4950
})
@@ -90,3 +91,16 @@ func testCheckIncapsulaSiteV3ConfigBasic(name string, siteType string) string {
9091
siteType,
9192
)
9293
}
94+
95+
func testSiteV3Importer(s *terraform.State) (string, error) {
96+
for _, rs := range s.RootModule().Resources {
97+
98+
accountId1, err := strconv.Atoi(rs.Primary.Attributes["account_id"])
99+
if err != nil {
100+
return "", fmt.Errorf("Error parsing API ID %v to int", rs.Primary.Attributes["id"])
101+
}
102+
103+
return fmt.Sprintf("%d/%s", accountId1, rs.Primary.ID), nil
104+
}
105+
return "", fmt.Errorf("Error finding an Site V3")
106+
}

0 commit comments

Comments
 (0)