Should return an error if the metadata file is empty

This commit is contained in:
DanHam 2019-08-21 12:55:28 +01:00
parent a9e22a6bb2
commit d1327fe422
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 21 additions and 2 deletions

View File

@ -287,9 +287,28 @@ func TestProviderFromVagrantBox_no_metadata(t *testing.T) {
t.Logf("%s", err)
}
func TestProviderFromVagrantBox_metadata_empty(t *testing.T) {
// Bad: Create a box with an empty metadata.json file
files := tarFiles{
{"foo.txt", "This is a foo file"},
{"bar.txt", "This is a bar file"},
{"metadata.json", ""},
}
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_ok(t *testing.T) {
// Good: The box contains the metadata.json file with the required
// 'provider' key/value
// Good: The boxes metadata.json file has the 'provider' key/value pair
expectedProvider := "virtualbox"
files := tarFiles{
{"foo.txt", "This is a foo file"},