-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to pass envvar for acctest org (#37)
* Add ability to pass envvar for acctest org This fixes failing test (by updating default) but also gives a way to test against other orgs more easily. * Fix typo
- Loading branch information
Showing
9 changed files
with
86 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Package envvar contains constants and defaults for various environment | ||
// variables for the provider. | ||
package envvar | ||
|
||
import "os" | ||
|
||
// Acceptance test related environment variables | ||
const ( | ||
AccTestOrganization = "ACCTEST_DOCKER_ORG" | ||
) | ||
|
||
// defaults is a map of pre-configured defaults for each envvar | ||
var defaults = map[string]string{ | ||
AccTestOrganization: "dockerterraform", | ||
} | ||
|
||
// GetWithDefault returns the value of the environment variable or the | ||
// pre-configured default if empty. | ||
func GetWithDefault(key string) string { | ||
ret := os.Getenv(key) | ||
if len(ret) > 0 { | ||
return ret | ||
} | ||
return defaults[key] | ||
} |
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,32 +1,36 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/docker/terraform-provider-docker/internal/envvar" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestOrgDataSource(t *testing.T) { | ||
org := envvar.GetWithDefault(envvar.AccTestOrganization) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
Config: testOrgExampleDataSourceConfig, | ||
Config: testOrgExampleDataSourceConfig(org), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.docker_org.test", "id", "dockerhackathon"), | ||
resource.TestCheckResourceAttr("data.docker_org.test", "id", org), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testOrgExampleDataSourceConfig = ` | ||
func testOrgExampleDataSourceConfig(org string) string { | ||
return fmt.Sprintf(` | ||
provider "docker" { | ||
host = "hub-stage.docker.com" | ||
} | ||
data "docker_org" "test" { | ||
org_name = "dockerhackathon" | ||
org_name = "%[1]s" | ||
}`, org) | ||
} | ||
` |
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,22 +1,26 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/docker/terraform-provider-docker/internal/envvar" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccOrgMemberResource(t *testing.T) { | ||
org := envvar.GetWithDefault(envvar.AccTestOrganization) | ||
teamName := "test" + randString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testOrgMemberResourceConfig(), | ||
Config: testOrgMemberResourceConfig(org, teamName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("docker_org_member.test", "invite_id"), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "org_name", "dockerhackathon"), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "team_name", "test"), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "org_name", org), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "team_name", teamName), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "user_name", "[email protected]"), | ||
resource.TestCheckResourceAttr("docker_org_member.test", "role", "member"), | ||
), | ||
|
@@ -31,17 +35,21 @@ func TestAccOrgMemberResource(t *testing.T) { | |
}) | ||
} | ||
|
||
func testOrgMemberResourceConfig() string { | ||
return ` | ||
func testOrgMemberResourceConfig(org string, team string) string { | ||
return fmt.Sprintf(` | ||
provider "docker" { | ||
host = "hub-stage.docker.com" | ||
} | ||
resource "docker_org_team" "testing" { | ||
org_name = "%[1]s" | ||
team_name = "%[2]s" | ||
} | ||
resource "docker_org_member" "test" { | ||
org_name = "dockerhackathon" | ||
team_name = "test" | ||
org_name = docker_org_team.testing.org_name | ||
team_name = docker_org_team.testing.team_name | ||
user_name = "[email protected]" | ||
role = "member" | ||
} | ||
` | ||
}`, org, team) | ||
} |
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