Commit 9ebd44a9 authored by Tom Hite's avatar Tom Hite

Merge branch 'master' of http://github.com/mitchellh/packer

parents 5e9b0350 934e1247
## 0.3.10 (unreleased)
IMPROVEMENTS:
* post-processor/vagrant: support instance-store AMIs built by Packer. [GH-502]
BUG FIXES:
* builder/all: timeout waiting for SSH connection is a failure. [GH-491]
* builder/amazon: Scrub sensitive data from the logs. [GH-521]
* builder/amazon: Handle the situation where an EC2 instance might not
be immediately available. [GH-522]
* builder/digitalocean: don't panic if erroneous API response doesn't
contain error message. [GH-492]
* builder/digitalocean: scrub API keys from config debug output [GH-516]
* builder/virtualbox: error if VirtualBox version cant be detected. [GH-488]
* builder/virtualbox: detect if vboxdrv isn't properly setup. [GH-488]
* builder/virtualbox: sleep a bit before export to ensure the sesssion
is unlocked. [GH-512]
* communicator/ssh: Fix issue where a panic could arise from a nil
dereference. [GH-525]
* provisioner/shell: Won't block on certain scripts on Windows anymore.
[GH-507]
## 0.3.9 (October 2, 2013)
......
......@@ -143,7 +143,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return errs
}
log.Printf("Config: %+v", b.config)
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
return nil
}
......
package common
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"testing"
)
func TestArtifact_Impl(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var actual packer.Artifact
assert.Implementor(&Artifact{}, &actual, "should be an Artifact")
var _ packer.Artifact = new(Artifact)
}
func TestArtifactId(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
expected := `east:foo,west:bar`
amis := make(map[string]string)
......@@ -27,12 +21,12 @@ func TestArtifactId(t *testing.T) {
}
result := a.Id()
assert.Equal(result, expected, "should match output")
if result != expected {
t.Fatalf("bad: %s", result)
}
}
func TestArtifactString(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
expected := `AMIs were created:
east: foo
......@@ -44,5 +38,7 @@ west: bar`
a := &Artifact{Amis: amis}
result := a.String()
assert.Equal(result, expected, "should match output")
if result != expected {
t.Fatalf("bad: %s", result)
}
}
package common
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/goamz/ec2"
"reflect"
"testing"
)
func TestBlockDevice(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
ec2Mapping := []ec2.BlockDeviceMapping{
ec2.BlockDeviceMapping{
DeviceName: "/dev/sdb",
......@@ -36,6 +34,11 @@ func TestBlockDevice(t *testing.T) {
LaunchMappings: []BlockDevice{blockDevice},
}
assert.Equal(ec2Mapping, blockDevices.BuildAMIDevices(), "should match output")
assert.Equal(ec2Mapping, blockDevices.BuildLaunchDevices(), "should match output")
if !reflect.DeepEqual(ec2Mapping, blockDevices.BuildAMIDevices()) {
t.Fatalf("bad: %#v", ec2Mapping)
}
if !reflect.DeepEqual(ec2Mapping, blockDevices.BuildLaunchDevices()) {
t.Fatalf("bad: %#v", ec2Mapping)
}
}
......@@ -62,11 +62,16 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := conn.Instances([]string{i.InstanceId}, ec2.NewFilter())
if err != nil {
if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
// Set this to nil as if we didn't find anything.
resp = nil
} else {
log.Printf("Error on InstanceStateRefresh: %s", err)
return nil, "", err
}
}
if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
if resp == nil || len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
......
package common
import (
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/packer"
"log"
"time"
......@@ -35,7 +34,7 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
// Create the group
ui.Say("Creating temporary security group for this instance...")
groupName := fmt.Sprintf("packer %s", hex.EncodeToString(identifier.NewUUID().Raw()))
groupName := fmt.Sprintf("packer %s", uuid.TimeOrderedUUID())
log.Printf("Temporary group name: %s", groupName)
group := ec2.SecurityGroup{
Name: groupName,
......
......@@ -56,7 +56,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return errs
}
log.Printf("Config: %+v", b.config)
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
return nil
}
......
......@@ -159,7 +159,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return errs
}
log.Printf("Config: %+v", b.config)
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
return nil
}
......
......@@ -164,7 +164,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return errs
}
log.Printf("Config: %+v", b.config)
common.ScrubConfig(b.config, b.config.ClientID, b.config.APIKey)
return nil
}
......
package digitalocean
import (
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/packer"
)
......@@ -21,7 +20,7 @@ func (s *stepCreateDroplet) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Creating droplet...")
// Some random droplet name as it's temporary
name := fmt.Sprintf("packer-%s", hex.EncodeToString(identifier.NewUUID().Raw()))
name := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
// Create the droplet based on configuration
dropletId, err := client.CreateDroplet(name, c.SizeID, c.ImageID, c.RegionID, sshKeyId)
......
package digitalocean
import (
"cgl.tideland.biz/identifier"
"code.google.com/p/go.crypto/ssh"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/hex"
"encoding/pem"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/packer"
"log"
)
......@@ -43,7 +42,7 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
pub_sshformat := string(ssh.MarshalAuthorizedKey(pub))
// The name of the public key on DO
name := fmt.Sprintf("packer-%s", hex.EncodeToString(identifier.NewUUID().Raw()))
name := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
// Create the key!
keyId, err := client.CreateKey(name, pub_sshformat)
......
package openstack
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"testing"
)
func TestArtifact_Impl(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var actual packer.Artifact
assert.Implementor(&Artifact{}, &actual, "should be an Artifact")
var _ packer.Artifact = new(Artifact)
}
func TestArtifactId(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
expected := `b8cdf55b-c916-40bd-b190-389ec144c4ed`
a := &Artifact{
......@@ -23,17 +17,19 @@ func TestArtifactId(t *testing.T) {
}
result := a.Id()
assert.Equal(result, expected, "should match output")
if result != expected {
t.Fatalf("bad: %s", result)
}
}
func TestArtifactString(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
expected := "An image was created: b8cdf55b-c916-40bd-b190-389ec144c4ed"
a := &Artifact{
ImageId: "b8cdf55b-c916-40bd-b190-389ec144c4ed",
}
result := a.String()
assert.Equal(result, expected, "should match output")
if result != expected {
t.Fatalf("bad: %s", result)
}
}
......@@ -51,7 +51,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return errs
}
log.Printf("Config: %+v", b.config)
log.Println(common.ScrubConfig(b.config), b.config.Password)
return nil
}
......
package openstack
import (
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/packer"
"github.com/rackspace/gophercloud"
"log"
......@@ -19,7 +18,7 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating temporary keypair for this instance...")
keyName := fmt.Sprintf("packer %s", hex.EncodeToString(identifier.NewUUID().Raw()))
keyName := fmt.Sprintf("packer %s", uuid.TimeOrderedUUID())
log.Printf("temporary keypair name: %s", keyName)
keyResp, err := csp.CreateKeyPair(gophercloud.NewKeyPair{Name: keyName})
if err != nil {
......
......@@ -4,7 +4,9 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"path/filepath"
"time"
)
// This step cleans up forwarded ports and exports the VM to an OVF.
......@@ -21,6 +23,10 @@ func (s *stepExport) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
// Wait a second to ensure VM is really shutdown.
log.Println("1 second timeout to ensure VM is really shutdown")
time.Sleep(1 * time.Second)
// Clear out the Packer-created forwarding rule
ui.Say("Preparing to export machine...")
ui.Message(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state.Get("sshHostPort")))
......
......@@ -2,7 +2,6 @@ package build
import (
"bytes"
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"testing"
)
......@@ -23,33 +22,33 @@ func testEnvironment() packer.Environment {
}
func TestCommand_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var actual packer.Command
assert.Implementor(new(Command), &actual, "should be a Command")
var _ packer.Command = new(Command)
}
func TestCommand_Run_NoArgs(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
command := new(Command)
result := command.Run(testEnvironment(), make([]string, 0))
assert.Equal(result, 1, "no args should error")
if result != 1 {
t.Fatalf("bad: %d", result)
}
}
func TestCommand_Run_MoreThanOneArg(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
command := new(Command)
args := []string{"one", "two"}
result := command.Run(testEnvironment(), args)
assert.Equal(result, 1, "More than one arg should fail")
if result != 1 {
t.Fatalf("bad: %d", result)
}
}
func TestCommand_Run_MissingFile(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
command := new(Command)
args := []string{"i-better-not-exist"}
result := command.Run(testEnvironment(), args)
assert.Equal(result, 1, "a non-existent file should error")
if result != 1 {
t.Fatalf("bad: %d", result)
}
}
......@@ -12,6 +12,16 @@ import (
"strings"
)
// ScrubConfig is a helper that returns a string representation of
// any struct with the given values stripped out.
func ScrubConfig(target interface{}, values ...string) string {
conf := fmt.Sprintf("Config: %+v", target)
for _, value := range values {
conf = strings.Replace(conf, value, "<Filtered>", -1)
}
return conf
}
// CheckUnusedConfig is a helper that makes sure that the there are no
// unused configuration keys, properly ignoring keys that don't matter.
func CheckUnusedConfig(md *mapstructure.Metadata) *packer.MultiError {
......
......@@ -159,3 +159,20 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
}
}
}
func TestScrubConfig(t *testing.T) {
type Inner struct {
Baz string
}
type Local struct {
Foo string
Bar string
Inner
}
c := Local{"foo", "bar", Inner{"bar"}}
expect := "Config: {Foo:foo Bar:<Filtered> Inner:{Baz:<Filtered>}}"
conf := ScrubConfig(c, c.Bar)
if conf != expect {
t.Fatalf("got %s, expected %s", conf, expect)
}
}
package uuid
import (
"fmt"
"math/rand"
"time"
)
// Generates a time ordered UUID. Top 32 bits are a timestamp,
// bottom 96 are random.
func TimeOrderedUUID() string {
unix := uint32(time.Now().UTC().Unix())
rand1 := rand.Uint32()
rand2 := rand.Uint32()
rand3 := rand.Uint32()
return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
unix,
uint16(rand1>>16),
uint16(rand1&0xffff),
uint16(rand2>>16),
uint16(rand2&0xffff),
rand3)
}
package uuid
import (
"testing"
)
func TestTimeOrderedUuid(t *testing.T) {
uuid := TimeOrderedUUID()
if len(uuid) != 36 {
t.Fatalf("bad: %s", uuid)
}
}
......@@ -238,6 +238,14 @@ func (c *comm) reconnect() (err error) {
log.Printf("reconnecting to TCP connection for SSH")
c.conn, err = c.config.Connection()
if err != nil {
// Explicitly set this to the REAL nil. Connection() can return
// a nil implementation of net.Conn which will make the
// "if c.conn == nil" check fail above. Read here for more information
// on this psychotic language feature:
//
// http://golang.org/doc/faq#nil_error
c.conn = nil
log.Printf("reconnection error: %s", err)
return
}
......
package packer
import (
"cgl.tideland.biz/asserts"
"reflect"
"testing"
)
......@@ -41,32 +40,43 @@ func testDefaultPackerConfig() map[string]interface{} {
}
}
func TestBuild_Name(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
build := testBuild()
assert.Equal(build.Name(), "test", "should have a name")
if build.Name() != "test" {
t.Fatalf("bad: %s", build.Name())
}
}
func TestBuild_Prepare(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
packerConfig := testDefaultPackerConfig()
build := testBuild()
builder := build.builder.(*TestBuilder)
build.Prepare(nil)
assert.True(builder.prepareCalled, "prepare should be called")
assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42")
if !builder.prepareCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(builder.prepareConfig, []interface{}{42, packerConfig}) {
t.Fatalf("bad: %#v", builder.prepareConfig)
}
coreProv := build.provisioners[0]
prov := coreProv.provisioner.(*MockProvisioner)
assert.True(prov.PrepCalled, "prepare should be called")
assert.Equal(prov.PrepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config")
if !prov.PrepCalled {
t.Fatal("prep should be called")
}
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig}) {
t.Fatalf("bad: %#v", prov.PrepConfigs)
}
corePP := build.postProcessors[0][0]
pp := corePP.processor.(*TestPostProcessor)
assert.True(pp.configCalled, "config should be called")
assert.Equal(pp.configVal, []interface{}{make(map[string]interface{}), packerConfig}, "config should have right value")
if !pp.configCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(pp.configVal, []interface{}{make(map[string]interface{}), packerConfig}) {
t.Fatalf("bad: %#v", pp.configVal)
}
}
func TestBuild_Prepare_Twice(t *testing.T) {
......@@ -90,8 +100,6 @@ func TestBuild_Prepare_Twice(t *testing.T) {
}
func TestBuild_Prepare_Debug(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
packerConfig := testDefaultPackerConfig()
packerConfig[DebugConfigKey] = true
......@@ -100,13 +108,21 @@ func TestBuild_Prepare_Debug(t *testing.T) {
build.SetDebug(true)
build.Prepare(nil)
assert.True(builder.prepareCalled, "prepare should be called")
assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42")
if !builder.prepareCalled {
t.Fatalf("should be called")
}
if !reflect.DeepEqual(builder.prepareConfig, []interface{}{42, packerConfig}) {
t.Fatalf("bad: %#v", builder.prepareConfig)
}
coreProv := build.provisioners[0]
prov := coreProv.provisioner.(*MockProvisioner)
assert.True(prov.PrepCalled, "prepare should be called")
assert.Equal(prov.PrepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config")
if !prov.PrepCalled {
t.Fatal("prepare should be called")
}
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig}) {
t.Fatalf("bad: %#v", prov.PrepConfigs)
}
}
func TestBuildPrepare_variables_default(t *testing.T) {
......@@ -186,37 +202,49 @@ func TestBuildPrepare_variablesRequired(t *testing.T) {
}
func TestBuild_Run(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
cache := &TestCache{}
ui := testUi()
build := testBuild()
build.Prepare(nil)
artifacts, err := build.Run(ui, cache)
assert.Nil(err, "should not error")
assert.Equal(len(artifacts), 2, "should have two artifacts")
if err != nil {
t.Fatalf("err: %s", err)
}
if len(artifacts) != 2 {
t.Fatalf("bad: %#v", artifacts)
}
// Verify builder was run
builder := build.builder.(*TestBuilder)
assert.True(builder.runCalled, "run should be called")
if !builder.runCalled {
t.Fatal("should be called")
}
// Verify hooks are disapatchable
dispatchHook := builder.runHook
dispatchHook.Run("foo", nil, nil, 42)
hook := build.hooks["foo"][0].(*MockHook)
assert.True(hook.RunCalled, "run should be called")
assert.Equal(hook.RunData, 42, "should have correct data")
if !hook.RunCalled {
t.Fatal("should be called")
}
if hook.RunData != 42 {
t.Fatalf("bad: %#v", hook.RunData)
}
// Verify provisioners run
dispatchHook.Run(HookProvision, nil, nil, 42)
prov := build.provisioners[0].provisioner.(*MockProvisioner)
assert.True(prov.ProvCalled, "provision should be called")
if !prov.ProvCalled {
t.Fatal("should be called")
}
// Verify post-processor was run
pp := build.postProcessors[0][0].processor.(*TestPostProcessor)
assert.True(pp.ppCalled, "post processor should be called")
if !pp.ppCalled {
t.Fatal("should be called")
}
}
func TestBuild_Run_Artifacts(t *testing.T) {
......@@ -356,23 +384,26 @@ func TestBuild_Run_Artifacts(t *testing.T) {
}
func TestBuild_RunBeforePrepare(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
defer func() {
p := recover()
assert.NotNil(p, "should panic")
assert.Equal(p.(string), "Prepare must be called first", "right panic")
if p == nil {
t.Fatal("should panic")
}
if p.(string) != "Prepare must be called first" {
t.Fatalf("bad: %s", p.(string))
}
}()
testBuild().Run(testUi(), &TestCache{})
}
func TestBuild_Cancel(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
build := testBuild()
build.Cancel()
builder := build.builder.(*TestBuilder)
assert.True(builder.cancelCalled, "cancel should be called")
if !builder.cancelCalled {
t.Fatal("cancel should be called")
}
}
......@@ -2,9 +2,8 @@ package packer
import (
"bytes"
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/packer/common/uuid"
"strconv"
"text/template"
"time"
......@@ -94,5 +93,5 @@ func templateTimestamp() string {
}
func templateUuid() string {
return hex.EncodeToString(identifier.NewUUID().Raw())
return uuid.TimeOrderedUUID()
}
......@@ -80,7 +80,7 @@ func TestConfigTemplateProcess_uuid(t *testing.T) {
t.Fatalf("err: %s", err)
}
if len(result) != 32 {
if len(result) != 36 {
t.Fatalf("err: %s", result)
}
}
......
This diff is collapsed.
package packer
import (
"cgl.tideland.biz/asserts"
"sync"
"testing"
"time"
......@@ -42,12 +41,7 @@ func (h *CancelHook) Cancel() {
}
func TestDispatchHook_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var r Hook
c := &DispatchHook{}
assert.Implementor(c, &r, "should be a Hook")
var _ Hook = new(DispatchHook)
}
func TestDispatchHook_Run_NoHooks(t *testing.T) {
......@@ -57,8 +51,6 @@ func TestDispatchHook_Run_NoHooks(t *testing.T) {
}
func TestDispatchHook_Run(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
hook := &MockHook{}
mapping := make(map[string][]Hook)
......@@ -66,9 +58,15 @@ func TestDispatchHook_Run(t *testing.T) {
dh := &DispatchHook{Mapping: mapping}
dh.Run("foo", nil, nil, 42)
assert.True(hook.RunCalled, "run should be called")
assert.Equal(hook.RunName, "foo", "should be proper event")
assert.Equal(hook.RunData, 42, "should be correct data")
if !hook.RunCalled {
t.Fatal("should be called")
}
if hook.RunName != "foo" {
t.Fatalf("bad: %s", hook.RunName)
}
if hook.RunData != 42 {
t.Fatalf("bad: %#v", hook.RunData)
}
}
func TestDispatchHook_cancel(t *testing.T) {
......
package packer
import (
"cgl.tideland.biz/asserts"
"errors"
"testing"
)
......@@ -15,8 +14,6 @@ func TestMultiError_Impl(t *testing.T) {
}
func TestMultiErrorError(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
expected := `2 error(s) occurred:
* foo
......@@ -28,7 +25,9 @@ func TestMultiErrorError(t *testing.T) {
}
multi := &MultiError{errors}
assert.Equal(multi.Error(), expected, "should have proper error")
if multi.Error() != expected {
t.Fatalf("bad: %s", multi.Error())
}
}
func TestMultiErrorAppend_MultiError(t *testing.T) {
......
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
......@@ -30,8 +30,6 @@ func (testArtifact) Destroy() error {
}
func TestArtifactRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
a := new(testArtifact)
......@@ -42,21 +40,29 @@ func TestArtifactRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
aClient := Artifact(client)
// Test
assert.Equal(aClient.BuilderId(), "bid", "should have correct builder ID")
assert.Equal(aClient.Files(), []string{"a", "b"}, "should have correct builder ID")
assert.Equal(aClient.Id(), "id", "should have correct builder ID")
assert.Equal(aClient.String(), "string", "should have correct builder ID")
}
if aClient.BuilderId() != "bid" {
t.Fatalf("bad: %s", aClient.BuilderId())
}
func TestArtifact_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
if !reflect.DeepEqual(aClient.Files(), []string{"a", "b"}) {
t.Fatalf("bad: %#v", aClient.Files())
}
var r packer.Artifact
a := Artifact(nil)
if aClient.Id() != "id" {
t.Fatalf("bad: %s", aClient.Id())
}
assert.Implementor(a, &r, "should be an Artifact")
if aClient.String() != "string" {
t.Fatalf("bad: %s", aClient.String())
}
}
func TestArtifact_Implements(t *testing.T) {
var _ packer.Artifact = Artifact(nil)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"errors"
"github.com/mitchellh/packer/packer"
"net/rpc"
......@@ -60,8 +59,6 @@ func (b *testBuild) Cancel() {
}
func TestBuildRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
b := new(testBuild)
......@@ -72,16 +69,23 @@ func TestBuildRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
bClient := Build(client)
// Test Name
bClient.Name()
assert.True(b.nameCalled, "name should be called")
if !b.nameCalled {
t.Fatal("name should be called")
}
// Test Prepare
bClient.Prepare(map[string]string{"foo": "bar"})
assert.True(b.prepareCalled, "prepare should be called")
if !b.prepareCalled {
t.Fatal("prepare should be called")
}
if len(b.prepareVars) != 1 {
t.Fatalf("bad vars: %#v", b.prepareVars)
}
......@@ -94,44 +98,65 @@ func TestBuildRPC(t *testing.T) {
cache := new(testCache)
ui := new(testUi)
artifacts, err := bClient.Run(ui, cache)
assert.True(b.runCalled, "run should be called")
assert.Nil(err, "should not error")
assert.Equal(len(artifacts), 1, "should have one artifact")
assert.Equal(artifacts[0].BuilderId(), "bid", "should have proper builder id")
if !b.runCalled {
t.Fatal("run should be called")
}
if err != nil {
t.Fatalf("err: %s", err)
}
if len(artifacts) != 1 {
t.Fatalf("bad: %#v", artifacts)
}
if artifacts[0].BuilderId() != "bid" {
t.Fatalf("bad: %#v", artifacts)
}
// Test the UI given to run, which should be fully functional
if b.runCalled {
b.runCache.Lock("foo")
assert.True(cache.lockCalled, "lock should be called")
if !cache.lockCalled {
t.Fatal("lock shuld be called")
}
b.runUi.Say("format")
assert.True(ui.sayCalled, "say should be called")
assert.Equal(ui.sayMessage, "format", "message should be correct")
if !ui.sayCalled {
t.Fatal("say should be called")
}
if ui.sayMessage != "format" {
t.Fatalf("bad: %#v", ui.sayMessage)
}
}
// Test run with an error
b.errRunResult = true
_, err = bClient.Run(ui, cache)
assert.NotNil(err, "should not nil")
if err == nil {
t.Fatal("should error")
}
// Test SetDebug
bClient.SetDebug(true)
assert.True(b.setDebugCalled, "should be called")
if !b.setDebugCalled {
t.Fatal("should be called")
}
// Test SetForce
bClient.SetForce(true)
assert.True(b.setForceCalled, "should be called")
if !b.setForceCalled {
t.Fatal("should be called")
}
// Test Cancel
bClient.Cancel()
assert.True(b.cancelCalled, "cancel should be called")
if !b.cancelCalled {
t.Fatal("should be called")
}
}
func TestBuild_ImplementsBuild(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var realBuild packer.Build
b := Build(nil)
assert.Implementor(b, &realBuild, "should be a Build")
var _ packer.Build = Build(nil)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"errors"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
......@@ -49,8 +49,6 @@ func (b *testBuilder) Cancel() {
}
func TestBuilderRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
b := new(testBuilder)
......@@ -61,60 +59,88 @@ func TestBuilderRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
// Test Prepare
config := 42
bClient := Builder(client)
bClient.Prepare(config)
assert.True(b.prepareCalled, "prepare should be called")
assert.Equal(b.prepareConfig, []interface{}{42}, "prepare should be called with right arg")
if !b.prepareCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(b.prepareConfig, []interface{}{42}) {
t.Fatalf("bad: %#v", b.prepareConfig)
}
// Test Run
cache := new(testCache)
hook := &packer.MockHook{}
ui := &testUi{}
artifact, err := bClient.Run(ui, hook, cache)
assert.Nil(err, "should have no error")
assert.True(b.runCalled, "runs hould be called")
if err != nil {
t.Fatalf("err: %s", err)
}
if !b.runCalled {
t.Fatal("run should be called")
}
if b.runCalled {
b.runCache.Lock("foo")
assert.True(cache.lockCalled, "lock should be called")
if !cache.lockCalled {
t.Fatal("should be called")
}
b.runHook.Run("foo", nil, nil, nil)
assert.True(hook.RunCalled, "run should be called")
if !hook.RunCalled {
t.Fatal("should be called")
}
b.runUi.Say("format")
assert.True(ui.sayCalled, "say should be called")
assert.Equal(ui.sayMessage, "format", "message should be correct")
if !ui.sayCalled {
t.Fatal("say should be called")
}
assert.Equal(artifact.Id(), testBuilderArtifact.Id(), "should have artifact Id")
if ui.sayMessage != "format" {
t.Fatalf("bad: %s", ui.sayMessage)
}
if artifact.Id() != testBuilderArtifact.Id() {
t.Fatalf("bad: %s", artifact.Id())
}
}
// Test run with nil result
b.nilRunResult = true
artifact, err = bClient.Run(ui, hook, cache)
assert.Nil(artifact, "should be nil")
assert.Nil(err, "should have no error")
if artifact != nil {
t.Fatalf("bad: %#v", artifact)
}
if err != nil {
t.Fatalf("bad: %#v", err)
}
// Test with an error
b.errRunResult = true
b.nilRunResult = false
artifact, err = bClient.Run(ui, hook, cache)
assert.Nil(artifact, "should be nil")
assert.NotNil(err, "should have error")
if artifact != nil {
t.Fatalf("bad: %#v", artifact)
}
if err == nil {
t.Fatal("should have error")
}
// Test Cancel
bClient.Cancel()
assert.True(b.cancelCalled, "cancel should be called")
if !b.cancelCalled {
t.Fatal("cancel should be called")
}
}
func TestBuilder_ImplementsBuilder(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var realBuilder packer.Builder
b := Builder(nil)
assert.Implementor(b, &realBuilder, "should be a Builder")
var _ packer.Builder = Builder(nil)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
......@@ -49,8 +48,6 @@ func TestCache_Implements(t *testing.T) {
}
func TestCacheRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
c := new(testCache)
......@@ -61,26 +58,44 @@ func TestCacheRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
rpcClient, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("bad: %s", err)
}
client := Cache(rpcClient)
// Test Lock
client.Lock("foo")
assert.True(c.lockCalled, "should be called")
assert.Equal(c.lockKey, "foo", "should have proper key")
if !c.lockCalled {
t.Fatal("should be called")
}
if c.lockKey != "foo" {
t.Fatalf("bad: %s", c.lockKey)
}
// Test Unlock
client.Unlock("foo")
assert.True(c.unlockCalled, "should be called")
assert.Equal(c.unlockKey, "foo", "should have proper key")
if !c.unlockCalled {
t.Fatal("should be called")
}
if c.unlockKey != "foo" {
t.Fatalf("bad: %s", c.unlockKey)
}
// Test RLock
client.RLock("foo")
assert.True(c.rlockCalled, "should be called")
assert.Equal(c.rlockKey, "foo", "should have proper key")
if !c.rlockCalled {
t.Fatal("should be called")
}
if c.rlockKey != "foo" {
t.Fatalf("bad: %s", c.rlockKey)
}
// Test RUnlock
client.RUnlock("foo")
assert.True(c.runlockCalled, "should be called")
assert.Equal(c.runlockKey, "foo", "should have proper key")
if !c.runlockCalled {
t.Fatal("should be called")
}
if c.runlockKey != "foo" {
t.Fatalf("bad: %s", c.runlockKey)
}
}
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
......@@ -29,8 +29,6 @@ func (tc *TestCommand) Synopsis() string {
}
func TestRPCCommand(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the command
command := new(TestCommand)
......@@ -42,37 +40,45 @@ func TestRPCCommand(t *testing.T) {
// Create the command client over RPC and run some methods to verify
// we get the proper behavior.
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be no error")
if err != nil {
t.Fatalf("err: %s", err)
}
clientComm := Command(client)
//Test Help
help := clientComm.Help()
assert.Equal(help, "bar", "helps hould be correct")
if help != "bar" {
t.Fatalf("bad: %s", help)
}
// Test run
runArgs := []string{"foo", "bar"}
testEnv := &testEnvironment{}
exitCode := clientComm.Run(testEnv, runArgs)
assert.Equal(command.runArgs, runArgs, "Correct args should be sent")
assert.Equal(exitCode, 0, "Exit code should be correct")
if !reflect.DeepEqual(command.runArgs, runArgs) {
t.Fatalf("bad: %#v", command.runArgs)
}
if exitCode != 0 {
t.Fatalf("bad: %d", exitCode)
}
if command.runEnv == nil {
t.Fatal("runEnv should not be nil")
}
assert.NotNil(command.runEnv, "should have an env")
if command.runEnv != nil {
command.runEnv.Ui()
assert.True(testEnv.uiCalled, "UI should be called on env")
if !testEnv.uiCalled {
t.Fatal("ui should be called")
}
// Test Synopsis
synopsis := clientComm.Synopsis()
assert.Equal(synopsis, "foo", "Synopsis should be correct")
if synopsis != "foo" {
t.Fatalf("bad: %#v", synopsis)
}
}
func TestCommand_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var r packer.Command
c := Command(nil)
assert.Implementor(c, &r, "should be a Builder")
var _ packer.Command = Command(nil)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
......@@ -65,8 +65,6 @@ func (e *testEnvironment) Ui() packer.Ui {
}
func TestEnvironmentRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
e := &testEnvironment{}
......@@ -77,49 +75,70 @@ func TestEnvironmentRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
eClient := &Environment{client}
// Test Builder
builder, _ := eClient.Builder("foo")
assert.True(e.builderCalled, "Builder should be called")
assert.Equal(e.builderName, "foo", "Correct name for Builder")
if !e.builderCalled {
t.Fatal("builder should be called")
}
if e.builderName != "foo" {
t.Fatalf("bad: %#v", e.builderName)
}
builder.Prepare(nil)
assert.True(testEnvBuilder.prepareCalled, "Prepare should be called")
if !testEnvBuilder.prepareCalled {
t.Fatal("should be called")
}
// Test Cache
cache := eClient.Cache()
cache.Lock("foo")
assert.True(testEnvCache.lockCalled, "lock should be called")
if !testEnvCache.lockCalled {
t.Fatal("should be called")
}
// Test Cli
cliArgs := []string{"foo", "bar"}
result, _ := eClient.Cli(cliArgs)
assert.True(e.cliCalled, "CLI should be called")
assert.Equal(e.cliArgs, cliArgs, "args should match")
assert.Equal(result, 42, "result shuld be 42")
if !e.cliCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(e.cliArgs, cliArgs) {
t.Fatalf("bad: %#v", e.cliArgs)
}
if result != 42 {
t.Fatalf("bad: %#v", result)
}
// Test Provisioner
_, _ = eClient.Provisioner("foo")
assert.True(e.provCalled, "provisioner should be called")
assert.Equal(e.provName, "foo", "should have proper name")
if !e.provCalled {
t.Fatal("should be called")
}
if e.provName != "foo" {
t.Fatalf("bad: %s", e.provName)
}
// Test Ui
ui := eClient.Ui()
assert.True(e.uiCalled, "Ui should've been called")
if !e.uiCalled {
t.Fatal("should be called")
}
// Test calls on the Ui
ui.Say("format")
assert.True(testEnvUi.sayCalled, "Say should be called")
assert.Equal(testEnvUi.sayMessage, "format", "message should match")
if !testEnvUi.sayCalled {
t.Fatal("should be called")
}
if testEnvUi.sayMessage != "format" {
t.Fatalf("bad: %#v", testEnvUi.sayMessage)
}
}
func TestEnvironment_ImplementsEnvironment(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var realVar packer.Environment
e := &Environment{nil}
assert.Implementor(e, &realVar, "should be an Environment")
var _ packer.Environment = new(Environment)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"errors"
"testing"
)
func TestBasicError_ImplementsError(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var r error
e := &BasicError{""}
assert.Implementor(e, &r, "should be an error")
var _ error = new(BasicError)
}
func TestBasicError_MatchesMessage(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
err := errors.New("foo")
wrapped := NewBasicError(err)
assert.Equal(wrapped.Error(), err.Error(), "should have the same error")
if wrapped.Error() != err.Error() {
t.Fatalf("bad: %#v", wrapped.Error())
}
}
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
......@@ -11,8 +10,6 @@ import (
)
func TestHookRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the UI to test
h := new(packer.MockHook)
......@@ -23,27 +20,28 @@ func TestHookRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
hClient := Hook(client)
// Test Run
ui := &testUi{}
hClient.Run("foo", ui, nil, 42)
assert.True(h.RunCalled, "run should be called")
if !h.RunCalled {
t.Fatal("should be called")
}
// Test Cancel
hClient.Cancel()
assert.True(h.CancelCalled, "cancel should be called")
if !h.CancelCalled {
t.Fatal("should be called")
}
}
func TestHook_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var r packer.Hook
h := &hook{nil}
assert.Implementor(h, &r, "should be a Hook")
var _ packer.Hook = new(hook)
}
func TestHook_cancelWhileRun(t *testing.T) {
......
package rpc
import (
"cgl.tideland.biz/asserts"
"net"
"strings"
"testing"
......@@ -13,21 +12,27 @@ func addrPort(address net.Addr) string {
}
func Test_netListenerInRange(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Open up port 10000 so that we take up a port
L1000, err := net.Listen("tcp", "127.0.0.1:11000")
defer L1000.Close()
assert.Nil(err, "should be able to bind to port 10000")
if err != nil {
t.Fatalf("bad: %s", err)
}
if err == nil {
// Verify it selects an open port
L := netListenerInRange(11000, 11005)
assert.NotNil(L, "should have a listener")
assert.Equal(addrPort(L.Addr()), "11001", "should bind to open port")
if L == nil {
t.Fatal("L should not be nil")
}
if addrPort(L.Addr()) != "11001" {
t.Fatalf("bad: %s", L.Addr())
}
// Returns nil if there are no open ports
L = netListenerInRange(11000, 11000)
assert.Nil(L, "should not get a listener")
if L != nil {
t.Fatalf("bad: %#v", L)
}
}
}
package rpc
import (
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
func TestProvisionerRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the interface to test
p := new(packer.MockProvisioner)
......@@ -20,23 +18,33 @@ func TestProvisionerRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
assert.Nil(err, "should be able to connect")
if err != nil {
t.Fatalf("err: %s", err)
}
// Test Prepare
config := 42
pClient := Provisioner(client)
pClient.Prepare(config)
assert.True(p.PrepCalled, "prepare should be called")
assert.Equal(p.PrepConfigs, []interface{}{42}, "prepare should be called with right arg")
if !p.PrepCalled {
t.Fatal("should be called")
}
if !reflect.DeepEqual(p.PrepConfigs, []interface{}{42}) {
t.Fatalf("bad: %#v", p.PrepConfigs)
}
// Test Provision
ui := &testUi{}
comm := &packer.MockCommunicator{}
pClient.Provision(ui, comm)
assert.True(p.ProvCalled, "provision should be called")
if !p.ProvCalled {
t.Fatal("should be called")
}
p.ProvUi.Say("foo")
assert.True(ui.sayCalled, "say should be called")
if !ui.sayCalled {
t.Fatal("should be called")
}
// Test Cancel
pClient.Cancel()
......@@ -46,10 +54,5 @@ func TestProvisionerRPC(t *testing.T) {
}
func TestProvisioner_Implements(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
var r packer.Provisioner
p := Provisioner(nil)
assert.Implementor(p, &r, "should be a provisioner")
var _ packer.Provisioner = Provisioner(nil)
}
package rpc
import (
"cgl.tideland.biz/asserts"
"net/rpc"
"reflect"
"testing"
......@@ -49,8 +48,6 @@ func (u *testUi) Say(message string) {
}
func TestUiRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
// Create the UI to test
ui := new(testUi)
......@@ -69,19 +66,33 @@ func TestUiRPC(t *testing.T) {
// Basic error and say tests
result, err := uiClient.Ask("query")
assert.Nil(err, "should not error")
assert.True(ui.askCalled, "ask should be called")
assert.Equal(ui.askQuery, "query", "should be correct")
assert.Equal(result, "foo", "should have correct result")
if err != nil {
t.Fatalf("err: %s", err)
}
if !ui.askCalled {
t.Fatal("should be called")
}
if ui.askQuery != "query" {
t.Fatalf("bad: %s", ui.askQuery)
}
if result != "foo" {
t.Fatalf("bad: %#v", result)
}
uiClient.Error("message")
assert.Equal(ui.errorMessage, "message", "message should be correct")
if ui.errorMessage != "message" {
t.Fatalf("bad: %#v", ui.errorMessage)
}
uiClient.Message("message")
assert.Equal(ui.messageMessage, "message", "message should be correct")
if ui.messageMessage != "message" {
t.Fatalf("bad: %#v", ui.errorMessage)
}
uiClient.Say("message")
assert.Equal(ui.sayMessage, "message", "message should be correct")
if ui.sayMessage != "message" {
t.Fatalf("bad: %#v", ui.errorMessage)
}
uiClient.Machine("foo", "bar", "baz")
if !ui.machineCalled {
......
This diff is collapsed.
......@@ -2,7 +2,6 @@ package packer
import (
"bytes"
"cgl.tideland.biz/asserts"
"strings"
"testing"
)
......@@ -38,25 +37,40 @@ func TestColoredUi(t *testing.T) {
}
func TestTargettedUi(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi()
targettedUi := &TargettedUi{
Target: "foo",
Ui: bufferUi,
}
var actual, expected string
targettedUi.Say("foo")
assert.Equal(readWriter(bufferUi), "==> foo: foo\n", "should have prefix")
actual = readWriter(bufferUi)
expected = "==> foo: foo\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
targettedUi.Message("foo")
assert.Equal(readWriter(bufferUi), " foo: foo\n", "should have prefix")
actual = readWriter(bufferUi)
expected = " foo: foo\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
targettedUi.Error("bar")
assert.Equal(readWriter(bufferUi), "==> foo: bar\n", "should have prefix")
actual = readWriter(bufferUi)
expected = "==> foo: bar\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
targettedUi.Say("foo\nbar")
assert.Equal(readWriter(bufferUi), "==> foo: foo\n==> foo: bar\n", "should multiline")
actual = readWriter(bufferUi)
expected = "==> foo: foo\n==> foo: bar\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
}
func TestColoredUi_ImplUi(t *testing.T) {
......@@ -84,27 +98,42 @@ func TestBasicUi_ImplUi(t *testing.T) {
}
func TestBasicUi_Error(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi()
var actual, expected string
bufferUi.Error("foo")
assert.Equal(readWriter(bufferUi), "foo\n", "basic output")
actual = readWriter(bufferUi)
expected = "foo\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
bufferUi.Error("5")
assert.Equal(readWriter(bufferUi), "5\n", "formatting")
actual = readWriter(bufferUi)
expected = "5\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
}
func TestBasicUi_Say(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi()
var actual, expected string
bufferUi.Say("foo")
assert.Equal(readWriter(bufferUi), "foo\n", "basic output")
actual = readWriter(bufferUi)
expected = "foo\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
bufferUi.Say("5")
assert.Equal(readWriter(bufferUi), "5\n", "formatting")
actual = readWriter(bufferUi)
expected = "5\n"
if actual != expected {
t.Fatalf("bad: %#v", actual)
}
}
func TestMachineReadableUi_ImplUi(t *testing.T) {
......
......@@ -13,6 +13,7 @@ import (
var builtins = map[string]string{
"mitchellh.amazonebs": "aws",
"mitchellh.amazon.instance": "aws",
"mitchellh.virtualbox": "virtualbox",
"mitchellh.vmware": "vmware",
}
......
......@@ -54,5 +54,12 @@ func (r *UnixReader) Read(p []byte) (n int, err error) {
// token returned will be "one\n".
func scanUnixLine(data []byte, atEOF bool) (advance int, token []byte, err error) {
advance, token, err = bufio.ScanLines(data, atEOF)
return advance, append(token, "\n"...), err
if advance == 0 {
// If we reached the end of a line without a newline, then
// just return as it is. Otherwise the Scanner will keep trying
// to scan, blocking forever.
return
}
return advance, append(token, '\n'), err
}
......@@ -18,24 +18,24 @@ func TestUnixReader(t *testing.T) {
input := "one\r\ntwo\n\r\nthree\r\n"
expected := "one\ntwo\n\nthree\n"
r := &UnixReader{
Reader: bytes.NewReader([]byte(input)),
}
result := new(bytes.Buffer)
if _, err := io.Copy(result, r); err != nil {
t.Fatalf("err: %s", err)
}
if result.String() != expected {
t.Fatalf("bad: %#v", result.String())
}
unixReaderTest(t, input, expected)
}
func TestUnixReader_unixOnly(t *testing.T) {
input := "\none\n\ntwo\nthree\n\n"
expected := "\none\n\ntwo\nthree\n\n"
unixReaderTest(t, input, expected)
}
func TestUnixReader_readsLastLine(t *testing.T) {
input := "one\ntwo"
expected := "one\ntwo\n"
unixReaderTest(t, input, expected)
}
func unixReaderTest(t *testing.T, input string, expected string) {
r := &UnixReader{
Reader: bytes.NewReader([]byte(input)),
}
......
......@@ -28,11 +28,16 @@ Ubuntu to self-install. Still, the example serves to show the basic configuratio
"iso_checksum": "2cbe868812a871242cdcdd8f2fd6feb9",
"iso_checksum_type": "md5",
"ssh_username": "packer",
"ssh_password": "packer",
"ssh_wait_timeout": "30s",
"shutdown_command": "shutdown -P now"
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
}
</pre>
It is important to add a `shutdown_command`. By default Packer halts the
virtual machine and the file system may not be sync'd. Thus, changes made in a
provisioner might not be saved.
## Configuration Reference
There are many configuration options available for the VirtualBox builder.
......
......@@ -39,7 +39,7 @@ Optional:
[salt bootstrap](https://github.com/saltstack/salt-bootstrap) to install
salt. Set this to true to skip this step.
* `boostrap_args` (string) - Arguments to send to the bootstrap script. Usage
* `bootstrap_args` (string) - Arguments to send to the bootstrap script. Usage
is somewhat documented on [github](https://github.com/saltstack/salt-bootstrap),
but the [script itself](https://github.com/saltstack/salt-bootstrap/blob/develop/bootstrap-salt.sh)
has more detailed usage instructions. By default, no arguments are sent to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment