Add tests for overriding DigitalOcean API URL.
This commit is contained in:
parent
afa7377d63
commit
0c80f77f52
|
@ -62,7 +62,7 @@ func (c *Config) Client() (*CombinedConfig, error) {
|
|||
|
||||
userAgent := fmt.Sprintf("Terraform/%s", terraform.VersionString())
|
||||
|
||||
do, err := godo.New(oauth2.NewClient(oauth2.NoContext, tokenSrc), godo.SetUserAgent(userAgent))
|
||||
godoClient, err := godo.New(oauth2.NewClient(oauth2.NoContext, tokenSrc), godo.SetUserAgent(userAgent))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -71,16 +71,16 @@ func (c *Config) Client() (*CombinedConfig, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.BaseURL = apiURL
|
||||
godoClient.BaseURL = apiURL
|
||||
|
||||
if logging.IsDebugOrHigher() {
|
||||
do.OnRequestCompleted(logRequestAndResponse)
|
||||
godoClient.OnRequestCompleted(logRequestAndResponse)
|
||||
}
|
||||
|
||||
log.Printf("[INFO] DigitalOcean Client configured for URL: %s", do.BaseURL.String())
|
||||
log.Printf("[INFO] DigitalOcean Client configured for URL: %s", godoClient.BaseURL.String())
|
||||
|
||||
return &CombinedConfig{
|
||||
client: do,
|
||||
client: godoClient,
|
||||
accessID: c.AccessID,
|
||||
secretKey: c.SecretKey,
|
||||
}, nil
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -33,3 +34,50 @@ func testAccPreCheck(t *testing.T) {
|
|||
t.Fatal("DIGITALOCEAN_TOKEN must be set for acceptance tests")
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLOverride(t *testing.T) {
|
||||
customEndpoint := "https://mock-api.internal.example.com/"
|
||||
|
||||
rawProvider := Provider()
|
||||
raw := map[string]interface{}{
|
||||
"token": "12345",
|
||||
"api_endpoint": customEndpoint,
|
||||
}
|
||||
|
||||
rawConfig, err := config.NewRawConfig(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = rawProvider.Configure(terraform.NewResourceConfig(rawConfig))
|
||||
meta := rawProvider.(*schema.Provider).Meta()
|
||||
if meta == nil {
|
||||
t.Fatalf("Expected metadata, got nil: err: %s", err)
|
||||
}
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
if client.BaseURL.String() != customEndpoint {
|
||||
t.Fatalf("Expected %s, got %s", customEndpoint, client.BaseURL.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLDefault(t *testing.T) {
|
||||
rawProvider := Provider()
|
||||
raw := map[string]interface{}{
|
||||
"token": "12345",
|
||||
}
|
||||
|
||||
rawConfig, err := config.NewRawConfig(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = rawProvider.Configure(terraform.NewResourceConfig(rawConfig))
|
||||
meta := rawProvider.(*schema.Provider).Meta()
|
||||
if meta == nil {
|
||||
t.Fatalf("Expected metadata, got nil: err: %s", err)
|
||||
}
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
if client.BaseURL.String() != "https://api.digitalocean.com" {
|
||||
t.Fatalf("Expected %s, got %s", "https://api.digitalocean.com", client.BaseURL.String())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue