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-07-23 23:56:32 +02:00
|
|
|
const testFakeAccountFilePath = "./test-fixtures/fake_account.json"
|
|
|
|
|
2015-07-27 21:35:52 +02:00
|
|
|
func TestConfigLoadAndValidate_accountFilePath(t *testing.T) {
|
2015-07-23 23:56:32 +02:00
|
|
|
config := Config{
|
|
|
|
AccountFile: testFakeAccountFilePath,
|
|
|
|
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-07-23 23:56:32 +02:00
|
|
|
contents, err := ioutil.ReadFile(testFakeAccountFilePath)
|
|
|
|
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-07-27 21:35:52 +02:00
|
|
|
AccountFile: string(contents),
|
|
|
|
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-07-27 21:35:52 +02:00
|
|
|
AccountFile: "{this is not json}",
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|