Updated test to verify expected behavior
This commit is contained in:
parent
78174dae4e
commit
b3eacc5c2b
|
@ -20,6 +20,13 @@ func fatalCommand(t *testing.T, m Meta) {
|
||||||
err.String())
|
err.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func outputCommand(t *testing.T, m Meta) (string, string) {
|
||||||
|
ui := m.Ui.(*packer.BasicUi)
|
||||||
|
out := ui.Writer.(*bytes.Buffer)
|
||||||
|
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||||
|
return out.String(), err.String()
|
||||||
|
}
|
||||||
|
|
||||||
func testFixture(n string) string {
|
func testFixture(n string) string {
|
||||||
return filepath.Join(fixturesDir, n)
|
return filepath.Join(fixturesDir, n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"content":"chocolate"
|
"content":"chocolate"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"min_packer_version":"0.8.0"
|
"min_packer_version":"101.0.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,28 +5,40 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateCommand(t *testing.T) {
|
func TestValidateCommandOKVersion(t *testing.T) {
|
||||||
c := &ValidateCommand{
|
c := &ValidateCommand{
|
||||||
Meta: testMetaFile(t),
|
Meta: testMetaFile(t),
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
filepath.Join(testFixture("validate"), "template.json"),
|
filepath.Join(testFixture("validate"), "template.json"),
|
||||||
}
|
}
|
||||||
|
|
||||||
defer cleanup()
|
// This should pass with a valid configuration version
|
||||||
|
c.CoreConfig.Version = "102.0.0"
|
||||||
if code := c.Run(args); code != 0 {
|
if code := c.Run(args); code != 0 {
|
||||||
fatalCommand(t, c.Meta)
|
fatalCommand(t, c.Meta)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !fileExists("chocolate.txt") {
|
|
||||||
t.Error("Expected to find chocolate.txt")
|
func TestValidateCommandBadVersion(t *testing.T) {
|
||||||
}
|
c := &ValidateCommand{
|
||||||
if !fileExists("vanilla.txt") {
|
Meta: testMetaFile(t),
|
||||||
t.Error("Expected to find vanilla.txt")
|
}
|
||||||
}
|
args := []string{
|
||||||
if fileExists("cherry.txt") {
|
filepath.Join(testFixture("validate"), "template.json"),
|
||||||
t.Error("Expected NOT to find cherry.txt")
|
}
|
||||||
}
|
|
||||||
|
// This should fail with an invalid configuration version
|
||||||
|
c.CoreConfig.Version = "100.0.0"
|
||||||
|
if code := c.Run(args); code != 1 {
|
||||||
|
t.Errorf("Expected exit code 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout, stderr := outputCommand(t, c.Meta)
|
||||||
|
expected := `Error initializing core: This template requires Packer version 101.0.0 or higher; using 100.0.0
|
||||||
|
`
|
||||||
|
if stderr != expected {
|
||||||
|
t.Fatalf("Expected:\n%s\nFound:\n%s\n", expected, stderr)
|
||||||
|
}
|
||||||
|
t.Log(stdout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,8 +246,7 @@ func (c *Core) validate() error {
|
||||||
|
|
||||||
if versionActual.LessThan(versionMin) {
|
if versionActual.LessThan(versionMin) {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"This template requires a minimum Packer version of %s,\n"+
|
"This template requires Packer version %s or higher; using %s",
|
||||||
"but version %s is running.",
|
|
||||||
versionMin,
|
versionMin,
|
||||||
versionActual)
|
versionActual)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue