github.com/rsyabuta/packer@v1.1.4-0.20180119234903-5ef0c2280f0b/command/validate_test.go (about)

     1  package command
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  func TestValidateCommandOKVersion(t *testing.T) {
     9  	c := &ValidateCommand{
    10  		Meta: testMetaFile(t),
    11  	}
    12  	args := []string{
    13  		filepath.Join(testFixture("validate"), "template.json"),
    14  	}
    15  
    16  	// This should pass with a valid configuration version
    17  	c.CoreConfig.Version = "102.0.0"
    18  	if code := c.Run(args); code != 0 {
    19  		fatalCommand(t, c.Meta)
    20  	}
    21  }
    22  
    23  func TestValidateCommandBadVersion(t *testing.T) {
    24  	c := &ValidateCommand{
    25  		Meta: testMetaFile(t),
    26  	}
    27  	args := []string{
    28  		filepath.Join(testFixture("validate"), "template.json"),
    29  	}
    30  
    31  	// This should fail with an invalid configuration version
    32  	c.CoreConfig.Version = "100.0.0"
    33  	if code := c.Run(args); code != 1 {
    34  		t.Errorf("Expected exit code 1")
    35  	}
    36  
    37  	stdout, stderr := outputCommand(t, c.Meta)
    38  	expected := `Error initializing core: This template requires Packer version 101.0.0 or higher; using 100.0.0
    39  `
    40  	if stderr != expected {
    41  		t.Fatalf("Expected:\n%s\nFound:\n%s\n", expected, stderr)
    42  	}
    43  	t.Log(stdout)
    44  }