From f8617b264131ba5a7fa081b31026c735bdee4b96 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 7 Jul 2013 09:14:16 -0700 Subject: [PATCH] builder/virtualbox: test the configuration /cc @sgirones --- builder/virtualbox/builder_test.go | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/builder/virtualbox/builder_test.go b/builder/virtualbox/builder_test.go index a2f5b5bb1..6b94eeefe 100644 --- a/builder/virtualbox/builder_test.go +++ b/builder/virtualbox/builder_test.go @@ -141,6 +141,82 @@ func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) { } } +func TestBuilderPrepare_GuestAdditionsSHA256(t *testing.T) { + var b Builder + config := testConfig() + + delete(config, "guest_additions_sha256") + err := b.Prepare(config) + if err != nil { + t.Fatalf("bad err: %s", err) + } + + if b.config.GuestAdditionsSHA256 != "" { + t.Fatalf("bad: %s", b.config.GuestAdditionsSHA256) + } + + config["guest_additions_sha256"] = "FOO" + b = Builder{} + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.GuestAdditionsSHA256 != "foo" { + t.Fatalf("bad size: %s", b.config.GuestAdditionsSHA256) + } +} + +func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) { + var b Builder + config := testConfig() + + config["guest_additions_url"] = "" + err := b.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + if b.config.GuestAdditionsURL != "" { + t.Fatalf("should be empty: %s", b.config.GuestAdditionsURL) + } + + config["guest_additions_url"] = "i/am/a/file/that/doesnt/exist" + err = b.Prepare(config) + if err == nil { + t.Error("should have error") + } + + config["guest_additions_url"] = "file:i/am/a/file/that/doesnt/exist" + err = b.Prepare(config) + if err == nil { + t.Error("should have error") + } + + config["guest_additions_url"] = "http://www.packer.io" + err = b.Prepare(config) + if err != nil { + t.Errorf("should not have error: %s", err) + } + + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("error tempfile: %s", err) + } + defer os.Remove(tf.Name()) + + config["guest_additions_url"] = tf.Name() + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.GuestAdditionsURL != "file://"+tf.Name() { + t.Fatalf("guest_additions_url should be modified: %s", b.config.GuestAdditionsURL) + } +} + + func TestBuilderPrepare_HTTPPort(t *testing.T) { var b Builder config := testConfig()