|
9 | 9 | "testing"
|
10 | 10 |
|
11 | 11 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
12 | 13 |
|
13 | 14 | "github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
|
14 | 15 | "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
@@ -105,12 +106,20 @@ func TestAccGithubRepositories(t *testing.T) {
|
105 | 106 | "github_repository.test", "name",
|
106 | 107 | oldName,
|
107 | 108 | ),
|
| 109 | + resource.ComposeTestCheckFunc( |
| 110 | + testCheckResourceAttrContains("github_repository.test", "full_name", |
| 111 | + oldName), |
| 112 | + ), |
108 | 113 | ),
|
109 | 114 | "after": resource.ComposeTestCheckFunc(
|
110 | 115 | resource.TestCheckResourceAttr(
|
111 | 116 | "github_repository.test", "name",
|
112 | 117 | newName,
|
113 | 118 | ),
|
| 119 | + resource.ComposeTestCheckFunc( |
| 120 | + testCheckResourceAttrContains("github_repository.test", "full_name", |
| 121 | + newName), |
| 122 | + ), |
114 | 123 | ),
|
115 | 124 | }
|
116 | 125 |
|
@@ -1426,3 +1435,23 @@ func TestResourceGithubParseFullName(t *testing.T) {
|
1426 | 1435 | _, _, ok = resourceGithubParseFullName(resourceDataLike(map[string]interface{}{"full_name": "malformed"}))
|
1427 | 1436 | assert.False(t, ok)
|
1428 | 1437 | }
|
| 1438 | + |
| 1439 | +func testCheckResourceAttrContains(resourceName, attributeName, substring string) resource.TestCheckFunc { |
| 1440 | + return func(s *terraform.State) error { |
| 1441 | + rs, ok := s.RootModule().Resources[resourceName] |
| 1442 | + if !ok { |
| 1443 | + return fmt.Errorf("Resource not found: %s", resourceName) |
| 1444 | + } |
| 1445 | + |
| 1446 | + value, ok := rs.Primary.Attributes[attributeName] |
| 1447 | + if !ok { |
| 1448 | + return fmt.Errorf("Attribute not found: %s", attributeName) |
| 1449 | + } |
| 1450 | + |
| 1451 | + if !strings.Contains(value, substring) { |
| 1452 | + return fmt.Errorf("Attribute '%s' does not contain '%s'", value, substring) |
| 1453 | + } |
| 1454 | + |
| 1455 | + return nil |
| 1456 | + } |
| 1457 | +} |
0 commit comments