github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/google/config_test.go (about)

     1  package google
     2  
     3  import (
     4  	"io/ioutil"
     5  	"testing"
     6  )
     7  
     8  const testFakeCredentialsPath = "./test-fixtures/fake_account.json"
     9  
    10  func TestConfigLoadAndValidate_accountFilePath(t *testing.T) {
    11  	config := Config{
    12  		Credentials: testFakeCredentialsPath,
    13  		Project:     "my-gce-project",
    14  		Region:      "us-central1",
    15  	}
    16  
    17  	err := config.loadAndValidate()
    18  	if err != nil {
    19  		t.Fatalf("error: %v", err)
    20  	}
    21  }
    22  
    23  func TestConfigLoadAndValidate_accountFileJSON(t *testing.T) {
    24  	contents, err := ioutil.ReadFile(testFakeCredentialsPath)
    25  	if err != nil {
    26  		t.Fatalf("error: %v", err)
    27  	}
    28  	config := Config{
    29  		Credentials: string(contents),
    30  		Project:     "my-gce-project",
    31  		Region:      "us-central1",
    32  	}
    33  
    34  	err = config.loadAndValidate()
    35  	if err != nil {
    36  		t.Fatalf("error: %v", err)
    37  	}
    38  }
    39  
    40  func TestConfigLoadAndValidate_accountFileJSONInvalid(t *testing.T) {
    41  	config := Config{
    42  		Credentials: "{this is not json}",
    43  		Project:     "my-gce-project",
    44  		Region:      "us-central1",
    45  	}
    46  
    47  	if config.loadAndValidate() == nil {
    48  		t.Fatalf("expected error, but got nil")
    49  	}
    50  }