From 6b5cf6dcb2475447c230562f434661e6e3487c3c Mon Sep 17 00:00:00 2001 From: DanHam Date: Tue, 20 Aug 2019 16:36:01 +0100 Subject: [PATCH] Should return an error when the box file is missing --- post-processor/vagrant-cloud/post-processor.go | 6 ++++++ post-processor/vagrant-cloud/post-processor_test.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/post-processor/vagrant-cloud/post-processor.go b/post-processor/vagrant-cloud/post-processor.go index 660a2761a..610c402b8 100644 --- a/post-processor/vagrant-cloud/post-processor.go +++ b/post-processor/vagrant-cloud/post-processor.go @@ -226,5 +226,11 @@ func providerFromBuilderName(name string) string { // Returns the Vagrant provider the box is intended for use with by // reading the metadata file packaged inside the box func providerFromVagrantBox(boxfile string) (providerName string, err error) { + f, err := os.Open(boxfile) + if err != nil { + return "", fmt.Errorf("Error attempting to open box file: %s", err) + } + defer f.Close() + return "", nil } diff --git a/post-processor/vagrant-cloud/post-processor_test.go b/post-processor/vagrant-cloud/post-processor_test.go index b9d8058a1..439f580df 100644 --- a/post-processor/vagrant-cloud/post-processor_test.go +++ b/post-processor/vagrant-cloud/post-processor_test.go @@ -197,3 +197,12 @@ func TestProviderFromBuilderName(t *testing.T) { t.Fatal("should convert provider") } } + +func TestProviderFromVagrantBox_missing_box(t *testing.T) { + boxfile := "i_dont_exist.box" + _, err := providerFromVagrantBox(boxfile) + if err == nil { + t.Fatal("Should have error as box file does not exist") + } + t.Logf("%s", err) +}