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