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