github.com/rothwerx/packer@v0.9.0/builder/vmware/vmx/builder_test.go (about)

     1  package vmx
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"reflect"
     7  	"testing"
     8  )
     9  
    10  func TestBuilderPrepare_FloppyFiles(t *testing.T) {
    11  	var b Builder
    12  
    13  	tf, err := ioutil.TempFile("", "packer")
    14  	if err != nil {
    15  		t.Fatalf("err: %s", err)
    16  	}
    17  	tf.Close()
    18  	defer os.Remove(tf.Name())
    19  
    20  	config := testConfig(t)
    21  	config["source_path"] = tf.Name()
    22  
    23  	delete(config, "floppy_files")
    24  	warns, err := b.Prepare(config)
    25  	if len(warns) > 0 {
    26  		t.Fatalf("bad: %#v", warns)
    27  	}
    28  	if err != nil {
    29  		t.Fatalf("bad err: %s", err)
    30  	}
    31  
    32  	if len(b.config.FloppyFiles) != 0 {
    33  		t.Fatalf("bad: %#v", b.config.FloppyFiles)
    34  	}
    35  
    36  	config["floppy_files"] = []string{"foo", "bar"}
    37  	b = Builder{}
    38  	warns, err = b.Prepare(config)
    39  	if len(warns) > 0 {
    40  		t.Fatalf("bad: %#v", warns)
    41  	}
    42  	if err != nil {
    43  		t.Fatalf("should not have error: %s", err)
    44  	}
    45  
    46  	expected := []string{"foo", "bar"}
    47  	if !reflect.DeepEqual(b.config.FloppyFiles, expected) {
    48  		t.Fatalf("bad: %#v", b.config.FloppyFiles)
    49  	}
    50  }