mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Paul Hinze](/assets/img/avatar_default.png)
Building on the work in #3846, shifting the Google provider's configuration option from `account_file` to `credentials`.
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package google
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
const testFakeCredentialsPath = "./test-fixtures/fake_account.json"
|
|
|
|
func TestConfigLoadAndValidate_accountFilePath(t *testing.T) {
|
|
config := Config{
|
|
Credentials: testFakeCredentialsPath,
|
|
Project: "my-gce-project",
|
|
Region: "us-central1",
|
|
}
|
|
|
|
err := config.loadAndValidate()
|
|
if err != nil {
|
|
t.Fatalf("error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigLoadAndValidate_accountFileJSON(t *testing.T) {
|
|
contents, err := ioutil.ReadFile(testFakeCredentialsPath)
|
|
if err != nil {
|
|
t.Fatalf("error: %v", err)
|
|
}
|
|
config := Config{
|
|
Credentials: string(contents),
|
|
Project: "my-gce-project",
|
|
Region: "us-central1",
|
|
}
|
|
|
|
err = config.loadAndValidate()
|
|
if err != nil {
|
|
t.Fatalf("error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigLoadAndValidate_accountFileJSONInvalid(t *testing.T) {
|
|
config := Config{
|
|
Credentials: "{this is not json}",
|
|
Project: "my-gce-project",
|
|
Region: "us-central1",
|
|
}
|
|
|
|
if config.loadAndValidate() == nil {
|
|
t.Fatalf("expected error, but got nil")
|
|
}
|
|
}
|