Skip to content

Commit

Permalink
Set api_endpoint via env var for acceptance tests
Browse files Browse the repository at this point in the history
This is the recommended way to override the endpoint for providers
currently. Invoking the provider's Configure during init() or in the
TestCase's PreCheck func does not persist across the lifecycle of a
TestCase.

See https://discuss.hashicorp.com/t/provider-configuration-in-tests/3730

Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Nov 6, 2019
1 parent 91a6227 commit dff91a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions megaport/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func testAccPreCheck(t *testing.T) {
if os.Getenv("MEGAPORT_TOKEN") == "" {
t.Fatal("MEGAPORT_TOKEN must be set for acceptance tests")
}
err := testAccProvider.Configure(terraform.NewResourceConfigRaw(
map[string]interface{}{"api_endpoint": api.EndpointStaging}))
if err != nil {
if err := os.Setenv("MEGAPORT_API_ENDPOINT", api.EndpointStaging); err != nil {
t.Fatal(err)
}
if err := testAccProvider.Configure(terraform.NewResourceConfigRaw(nil)); err != nil {
t.Fatal(err)
}
}

0 comments on commit dff91a0

Please sign in to comment.