-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(org_user): deprecating resource, new datasource (#1484)
- Loading branch information
1 parent
294745f
commit 0dd160c
Showing
6 changed files
with
167 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 54 additions & 11 deletions
65
internal/sdkprovider/service/organization/organization_user_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
package organization_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
acc "github.com/aiven/terraform-provider-aiven/internal/acctest" | ||
) | ||
|
||
func TestAccAivenOrganizationUserDataSource_basic(t *testing.T) { | ||
func TestAccAivenOrganizationUserDataSource_using_email(t *testing.T) { | ||
orgID := os.Getenv("AIVEN_ORG_ID") | ||
email := os.Getenv("AIVEN_ORG_USER_EMAIL") | ||
|
||
if orgID == "" || email == "" { | ||
t.Skip("Skipping test due to missing AIVEN_ORG_ID or AIVEN_ORG_USER_EMAIL environment variable") | ||
} | ||
|
||
datasourceName := "data.aiven_organization_user.member" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOrganizationUserDataResourceByEmail(orgID, email), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(datasourceName, "user_email"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "create_time"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAivenOrganizationUserDataSource_using_userid(t *testing.T) { | ||
orgID := os.Getenv("AIVEN_ORG_ID") | ||
userID := os.Getenv("AIVEN_ORG_USER_ID") | ||
|
||
if orgID == "" || userID == "" { | ||
t.Skip("Skipping test due to missing AIVEN_ORG_ID or AIVEN_ORG_USER_ID environment variable") | ||
} | ||
|
||
datasourceName := "data.aiven_organization_user.member" | ||
resourceName := "aiven_organization_user.foo" | ||
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOrganizationUserResource(rName), | ||
Config: testAccOrganizationUserDataResourceByUserID(orgID, userID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair( | ||
datasourceName, "organization_id", resourceName, "organization_id", | ||
), | ||
resource.TestCheckResourceAttrPair(datasourceName, "user_email", resourceName, "user_email"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "create_time", resourceName, "create_time"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "accepted", resourceName, "accepted"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "user_id"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "create_time"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccOrganizationUserDataResourceByUserID(orgID, userID string) string { | ||
return fmt.Sprintf(` | ||
data "aiven_organization_user" "member" { | ||
organization_id = "%s" | ||
user_id = "%s" | ||
}`, orgID, userID) | ||
} | ||
|
||
func testAccOrganizationUserDataResourceByEmail(orgID, email string) string { | ||
return fmt.Sprintf(` | ||
data "aiven_organization_user" "member" { | ||
organization_id = "%s" | ||
user_email = "%s" | ||
}`, orgID, email) | ||
} |