builder/googlecompute: Tests added

This commit is contained in:
Lars Wander 2016-11-03 12:45:52 -04:00
parent d70e783455
commit 7f474d8f78
3 changed files with 75 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package googlecompute
import (
"errors"
"strings"
"testing"
"time"
@ -210,3 +211,33 @@ func TestStepCreateInstance_errorTimeout(t *testing.T) {
_, ok = state.GetOk("instance_name")
assert.False(t, ok, "State should not have an instance name.")
}
func TestCreateInstanceMetadata(t *testing.T) {
state := testState(t)
c := state.Get("config").(*Config)
image := StubImage("test-image", "test-project", []string{}, 100)
key := "abcdefgh12345678"
// create our metadata
metadata, err := c.createInstanceMetadata(image, key)
assert.True(t, err == nil, "Metadata creation should have succeeded.")
// ensure our key is listed
assert.True(t, strings.Contains(metadata["sshKeys"], key), "Instance metadata should contain provided key")
}
func TestCreateInstanceMetadata_noPublicKey(t *testing.T) {
state := testState(t)
c := state.Get("config").(*Config)
image := StubImage("test-image", "test-project", []string{}, 100)
sshKeys := c.Metadata["sshKeys"]
// create our metadata
metadata, err := c.createInstanceMetadata(image, "")
assert.True(t, err == nil, "Metadata creation should have succeeded.")
// ensure the ssh metadata hasn't changed
assert.Equal(t, metadata["sshKeys"], sshKeys, "Instance metadata should not have been modified")
}

View File

@ -12,6 +12,23 @@ func TestStepCreateSSHKey_impl(t *testing.T) {
var _ multistep.Step = new(StepCreateSSHKey)
}
func TestStepCreateSSHKey_privateKey(t *testing.T) {
state := testState(t)
step := new(StepCreateSSHKey)
step.PrivateKeyFile = "test-fixtures/fake-key"
defer step.Cleanup(state)
// run the step
if action := step.Run(state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)
}
// Verify that we have a public/private key
if _, ok := state.GetOk("ssh_private_key"); !ok {
t.Fatal("should have key")
}
}
func TestStepCreateSSHKey(t *testing.T) {
state := testState(t)
step := new(StepCreateSSHKey)

View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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