forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
69 lines (57 loc) · 1.37 KB
/
main_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
package main
import (
"math/rand"
"reflect"
"strings"
"testing"
"github.com/mitchellh/cli"
"github.com/mitchellh/packer/command"
)
func TestExcludeHelpFunc(t *testing.T) {
commands := map[string]cli.CommandFactory{
"build": func() (cli.Command, error) {
return &command.BuildCommand{
Meta: command.Meta{},
}, nil
},
"fix": func() (cli.Command, error) {
return &command.FixCommand{
Meta: command.Meta{},
}, nil
},
}
helpFunc := excludeHelpFunc(commands, []string{"fix"})
helpText := helpFunc(commands)
if strings.Contains(helpText, "fix") {
t.Fatalf("Found fix in help text even though we excluded it: \n\n%s\n\n", helpText)
}
}
func TestExtractMachineReadable(t *testing.T) {
var args, expected, result []string
var mr bool
// Not
args = []string{"foo", "bar", "baz"}
result, mr = extractMachineReadable(args)
expected = []string{"foo", "bar", "baz"}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("bad: %#v", result)
}
if mr {
t.Fatal("should not be mr")
}
// Yes
args = []string{"foo", "-machine-readable", "baz"}
result, mr = extractMachineReadable(args)
expected = []string{"foo", "baz"}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("bad: %#v", result)
}
if !mr {
t.Fatal("should be mr")
}
}
func TestRandom(t *testing.T) {
if rand.Intn(9999999) == 8498210 {
t.Fatal("math.rand is not seeded properly")
}
}