2014-08-25 18:48:20 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2015-07-23 21:56:32 +00:00
|
|
|
"io/ioutil"
|
2014-08-25 18:48:20 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-07-23 21:56:32 +00:00
|
|
|
const testFakeAccountFilePath = "./test-fixtures/fake_account.json"
|
|
|
|
|
|
|
|
func TestConfigLoadAndValidate_accountFile(t *testing.T) {
|
|
|
|
config := Config{
|
|
|
|
AccountFile: testFakeAccountFilePath,
|
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := config.loadAndValidate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigLoadAndValidate_accountFileContents(t *testing.T) {
|
|
|
|
contents, err := ioutil.ReadFile(testFakeAccountFilePath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
2014-08-25 18:48:20 +00:00
|
|
|
}
|
2015-07-23 21:56:32 +00:00
|
|
|
config := Config{
|
|
|
|
AccountFileContents: string(contents),
|
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
|
|
|
}
|
|
|
|
|
|
|
|
err = config.loadAndValidate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigLoadAndValidate_none(t *testing.T) {
|
|
|
|
config := Config{
|
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := config.loadAndValidate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2014-08-25 18:48:20 +00:00
|
|
|
|
2015-07-23 21:56:32 +00:00
|
|
|
func TestConfigLoadAndValidate_both(t *testing.T) {
|
|
|
|
config := Config{
|
|
|
|
AccountFile: testFakeAccountFilePath,
|
|
|
|
AccountFileContents: "{}",
|
|
|
|
Project: "my-gce-project",
|
|
|
|
Region: "us-central1",
|
2014-08-25 18:48:20 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 21:56:32 +00:00
|
|
|
if config.loadAndValidate() == nil {
|
|
|
|
t.Fatalf("expected error, but got nil")
|
2014-08-25 18:48:20 +00:00
|
|
|
}
|
|
|
|
}
|