2014-08-25 13:48:20 -05:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2015-07-23 16:56:32 -05:00
|
|
|
"io/ioutil"
|
2014-08-25 13:48:20 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-11-12 16:13:07 -06:00
|
|
|
const testFakeCredentialsPath = "./test-fixtures/fake_account.json"
|
2015-07-23 16:56:32 -05:00
|
|
|
|
2015-07-27 14:35:52 -05:00
|
|
|
func TestConfigLoadAndValidate_accountFilePath(t *testing.T) {
|
2015-07-23 16:56:32 -05:00
|
|
|
config := Config{
|
2015-11-12 16:13:07 -06:00
|
|
|
Credentials: testFakeCredentialsPath,
|
2015-07-23 16:56:32 -05:00
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := config.loadAndValidate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 14:35:52 -05:00
|
|
|
func TestConfigLoadAndValidate_accountFileJSON(t *testing.T) {
|
2015-11-12 16:13:07 -06:00
|
|
|
contents, err := ioutil.ReadFile(testFakeCredentialsPath)
|
2015-07-23 16:56:32 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
2014-08-25 13:48:20 -05:00
|
|
|
}
|
2015-07-23 16:56:32 -05:00
|
|
|
config := Config{
|
2015-11-12 16:13:07 -06:00
|
|
|
Credentials: string(contents),
|
2015-07-27 14:35:52 -05:00
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
2015-07-23 16:56:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
err = config.loadAndValidate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 14:35:52 -05:00
|
|
|
func TestConfigLoadAndValidate_accountFileJSONInvalid(t *testing.T) {
|
2015-07-23 16:56:32 -05:00
|
|
|
config := Config{
|
2015-11-12 16:13:07 -06:00
|
|
|
Credentials: "{this is not json}",
|
2015-07-27 14:35:52 -05:00
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
2014-08-25 13:48:20 -05:00
|
|
|
}
|
|
|
|
|
2015-07-23 16:56:32 -05:00
|
|
|
if config.loadAndValidate() == nil {
|
|
|
|
t.Fatalf("expected error, but got nil")
|
2014-08-25 13:48:20 -05:00
|
|
|
}
|
|
|
|
}
|