Compare commits
2 Commits
master
...
example-te
Author | SHA1 | Date | |
---|---|---|---|
|
fd3cc596c7 | ||
|
708f9cdfbd |
@ -95,6 +95,8 @@ func TestHelperProcess(*testing.T) {
|
|||||||
os.Exit((&BuildCommand{Meta: commandMeta()}).Run(args))
|
os.Exit((&BuildCommand{Meta: commandMeta()}).Run(args))
|
||||||
case "hcl2_upgrade":
|
case "hcl2_upgrade":
|
||||||
os.Exit((&HCL2UpgradeCommand{Meta: commandMeta()}).Run(args))
|
os.Exit((&HCL2UpgradeCommand{Meta: commandMeta()}).Run(args))
|
||||||
|
case "version":
|
||||||
|
os.Exit((&VersionCommand{Meta: commandMeta()}).Run(args))
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd)
|
fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
|
@ -1,11 +1,37 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/version"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVersionCommand_implements(t *testing.T) {
|
func TestVersionCommand_implements(t *testing.T) {
|
||||||
var _ cli.Command = &VersionCommand{}
|
var _ cli.Command = &VersionCommand{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_version(t *testing.T) {
|
||||||
|
tc := []struct {
|
||||||
|
command []string
|
||||||
|
env []string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{[]string{"version"}, nil, fmt.Sprintf("Packer v%s", version.FormattedVersion()) + "\n"},
|
||||||
|
{[]string{"version", "&"}, nil, fmt.Sprintf("Packer v%s", version.FormattedVersion()) + "\n"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tc {
|
||||||
|
t.Run(fmt.Sprintf("packer %s", tc.command), func(t *testing.T) {
|
||||||
|
p := helperCommand(t, tc.command...)
|
||||||
|
bs, err := p.Output()
|
||||||
|
fmt.Println(err)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%v: %s", err, bs)
|
||||||
|
}
|
||||||
|
assert.Equal(t, tc.expected, string(bs))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2
main.go
2
main.go
@ -470,3 +470,5 @@ func init() {
|
|||||||
// Seed the random number generator
|
// Seed the random number generator
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var backgroundCheckFn func(int) (bool, error)
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -67,3 +68,11 @@ func TestRandom(t *testing.T) {
|
|||||||
t.Fatal("math.rand is not seeded properly")
|
t.Fatal("math.rand is not seeded properly")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleWrappedMain() {
|
||||||
|
os.Setenv("PACKER_WRAP_COOKIE", "49C22B1A-3A93-4C98-97FA-E07D18C787B5")
|
||||||
|
backgroundCheckFn = func(_ int) (bool, error) { return true, nil }
|
||||||
|
os.Args = []string{"packer", "version"}
|
||||||
|
wrappedMain()
|
||||||
|
//Output: Packer v1.7.2-dev
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user