From dff91a0a8dd54b0d7210adc73068835dee5db4a3 Mon Sep 17 00:00:00 2001 From: Dimitrios Karagiannis Date: Wed, 6 Nov 2019 12:13:48 +0000 Subject: [PATCH] Set api_endpoint via env var for acceptance tests 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 --- megaport/provider_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/megaport/provider_test.go b/megaport/provider_test.go index 2e4fb26..91a750f 100644 --- a/megaport/provider_test.go +++ b/megaport/provider_test.go @@ -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) } }