From 46d297c7bd48b4bf9f15e2da19b847489731caef Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Dec 2013 17:54:48 -0800 Subject: [PATCH] builder/googlecompute: client secrets tests --- builder/googlecompute/client_secrets.go | 2 ++ builder/googlecompute/client_secrets_test.go | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 builder/googlecompute/client_secrets_test.go diff --git a/builder/googlecompute/client_secrets.go b/builder/googlecompute/client_secrets.go index 6203313b8..cbe071514 100644 --- a/builder/googlecompute/client_secrets.go +++ b/builder/googlecompute/client_secrets.go @@ -22,9 +22,11 @@ func loadClientSecrets(path string) (*clientSecrets, error) { if err != nil { return nil, err } + err = json.Unmarshal(secretBytes, &cs) if err != nil { return nil, err } + return cs, nil } diff --git a/builder/googlecompute/client_secrets_test.go b/builder/googlecompute/client_secrets_test.go new file mode 100644 index 000000000..584aa0ce1 --- /dev/null +++ b/builder/googlecompute/client_secrets_test.go @@ -0,0 +1,31 @@ +package googlecompute + +import ( + "io/ioutil" + "testing" +) + +func testClientSecretsFile(t *testing.T) string { + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + defer tf.Close() + + if _, err := tf.Write([]byte(testClientSecretsContent)); err != nil { + t.Fatalf("err: %s", err) + } + + return tf.Name() +} + +func TestLoadClientSecrets(t *testing.T) { + _, err := loadClientSecrets(testClientSecretsFile(t)) + if err != nil { + t.Fatalf("err: %s", err) + } +} + +// This is just some dummy data that doesn't actually work (it was revoked +// a long time ago). +const testClientSecretsContent = `{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","client_email":"774313886706-eorlsj0r4eqkh5e7nvea5fuf59ifr873@developer.gserviceaccount.com","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/774313886706-eorlsj0r4eqkh5e7nvea5fuf59ifr873@developer.gserviceaccount.com","client_id":"774313886706-eorlsj0r4eqkh5e7nvea5fuf59ifr873.apps.googleusercontent.com","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"}}`