2015-07-13 17:57:35 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-07-13 22:32:28 -04:00
|
|
|
func TestValidateCommandOKVersion(t *testing.T) {
|
2015-07-13 17:57:35 -04:00
|
|
|
c := &ValidateCommand{
|
|
|
|
Meta: testMetaFile(t),
|
|
|
|
}
|
|
|
|
args := []string{
|
|
|
|
filepath.Join(testFixture("validate"), "template.json"),
|
|
|
|
}
|
|
|
|
|
2015-07-13 22:32:28 -04:00
|
|
|
// This should pass with a valid configuration version
|
|
|
|
c.CoreConfig.Version = "102.0.0"
|
2015-07-13 17:57:35 -04:00
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
fatalCommand(t, c.Meta)
|
|
|
|
}
|
2015-07-13 22:32:28 -04:00
|
|
|
}
|
2015-07-13 17:57:35 -04:00
|
|
|
|
2015-07-13 22:32:28 -04:00
|
|
|
func TestValidateCommandBadVersion(t *testing.T) {
|
|
|
|
c := &ValidateCommand{
|
|
|
|
Meta: testMetaFile(t),
|
2015-07-13 17:57:35 -04:00
|
|
|
}
|
2015-07-13 22:32:28 -04:00
|
|
|
args := []string{
|
|
|
|
filepath.Join(testFixture("validate"), "template.json"),
|
2015-07-13 17:57:35 -04:00
|
|
|
}
|
2015-07-13 22:32:28 -04:00
|
|
|
|
|
|
|
// 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)
|
2015-07-13 17:57:35 -04:00
|
|
|
}
|
2015-07-13 22:32:28 -04:00
|
|
|
t.Log(stdout)
|
2015-07-13 17:57:35 -04:00
|
|
|
}
|