github.com/hashicorp/packer@v1.14.3/packer_test/dag_tests/malformed_dep_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/packer/packer_test/common/check"
     7  )
     8  
     9  type malformedDepTestCase struct {
    10  	name          string
    11  	command       string
    12  	templatePath  string
    13  	useSequential bool
    14  }
    15  
    16  func genMalformedDepTestCases() []malformedDepTestCase {
    17  	retVals := []malformedDepTestCase{}
    18  
    19  	for _, cmd := range []string{"build", "validate"} {
    20  		for _, template := range []string{"./templates/malformed_data_dep.pkr.hcl", "./templates/malformed_local_dep.pkr.hcl"} {
    21  			for _, seq := range []bool{true, false} {
    22  				retVals = append(retVals, malformedDepTestCase{
    23  					name: fmt.Sprintf("Malformed dep packer %s --use-sequential-evaluation=%t %s",
    24  						cmd, seq, template),
    25  					command:       cmd,
    26  					templatePath:  template,
    27  					useSequential: seq,
    28  				})
    29  			}
    30  		}
    31  	}
    32  
    33  	return retVals
    34  }
    35  
    36  func (ts *PackerDAGTestSuite) TestMalformedDependency() {
    37  	pluginDir := ts.MakePluginDir()
    38  	defer pluginDir.Cleanup()
    39  
    40  	for _, tc := range genMalformedDepTestCases() {
    41  		ts.Run(tc.name, func() {
    42  			ts.PackerCommand().UsePluginDir(pluginDir).
    43  				SetArgs(tc.command,
    44  					fmt.Sprintf("--use-sequential-evaluation=%t", tc.useSequential),
    45  					tc.templatePath).
    46  				Assert(check.MustFail())
    47  		})
    48  	}
    49  }