github.com/angdraug/packer@v1.3.2/common/floppy_config_test.go (about) 1 package common 2 3 import ( 4 "testing" 5 ) 6 7 func TestNilFloppies(t *testing.T) { 8 c := FloppyConfig{} 9 errs := c.Prepare(nil) 10 if len(errs) != 0 { 11 t.Fatal("nil floppies array should not fail") 12 } 13 14 if len(c.FloppyFiles) > 0 { 15 t.Fatal("struct should not have floppy files") 16 } 17 } 18 19 func TestEmptyArrayFloppies(t *testing.T) { 20 c := FloppyConfig{ 21 FloppyFiles: make([]string, 0), 22 } 23 24 errs := c.Prepare(nil) 25 if len(errs) != 0 { 26 t.Fatal("empty floppies array should never fail") 27 } 28 29 if len(c.FloppyFiles) > 0 { 30 t.Fatal("struct should not have floppy files") 31 } 32 } 33 34 func TestExistingFloppyFile(t *testing.T) { 35 c := FloppyConfig{ 36 FloppyFiles: []string{"floppy_config.go"}, 37 } 38 39 errs := c.Prepare(nil) 40 if len(errs) != 0 { 41 t.Fatal("array with existing floppies should not fail") 42 } 43 } 44 45 func TestNonExistingFloppyFile(t *testing.T) { 46 c := FloppyConfig{ 47 FloppyFiles: []string{"floppy_config.foo"}, 48 } 49 50 errs := c.Prepare(nil) 51 if len(errs) == 0 { 52 t.Fatal("array with non existing floppies should return errors") 53 } 54 } 55 56 func TestMultiErrorFloppyFiles(t *testing.T) { 57 c := FloppyConfig{ 58 FloppyFiles: []string{"floppy_config.foo", "floppy_config.go", "floppy_config.bar", "floppy_config_test.go", "floppy_config.baz"}, 59 } 60 61 errs := c.Prepare(nil) 62 if len(errs) == 0 { 63 t.Fatal("array with non existing floppies should return errors") 64 } 65 66 expectedErrors := 3 67 if count := len(errs); count != expectedErrors { 68 t.Fatalf("array with %v non existing floppy should return %v errors but it is returning %v", expectedErrors, expectedErrors, count) 69 } 70 }