From aee400836fbd9ca2510a3e739b06b8e6879cde0a Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 21 Aug 2019 13:18:56 +0100 Subject: [PATCH] Should return an error if the provider kv pair is not in the metadata file --- .../vagrant-cloud/post-processor_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/post-processor/vagrant-cloud/post-processor_test.go b/post-processor/vagrant-cloud/post-processor_test.go index b58bee261..c698db017 100644 --- a/post-processor/vagrant-cloud/post-processor_test.go +++ b/post-processor/vagrant-cloud/post-processor_test.go @@ -327,6 +327,26 @@ func TestProviderFromVagrantBox_metadata_bad_json(t *testing.T) { t.Logf("%s", err) } +func TestProviderFromVagrantBox_metadata_no_provider_key(t *testing.T) { + // Bad: Create a box with no 'provider' key in the metadata.json file + files := tarFiles{ + {"foo.txt", "This is a foo file"}, + {"bar.txt", "This is a bar file"}, + {"metadata.json", `{"cows":"moo"}`}, + } + boxfile, err := createBox(files) + if err != nil { + t.Fatalf("Error creating test box: %s", err) + } + defer os.Remove(boxfile.Name()) + + _, err = providerFromVagrantBox(boxfile.Name()) + if err == nil { + t.Fatalf("Should have error as box files metadata.json file is empty") + } + t.Logf("%s", err) +} + func TestProviderFromVagrantBox_metadata_provider_value_empty(t *testing.T) { // Bad: The boxes metadata.json file 'provider' key has an empty value files := tarFiles{