fix tests
This commit is contained in:
parent
1f3e85185e
commit
efcc6af06c
@ -37,12 +37,12 @@ func (c *BuildCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
|
func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
|
||||||
var cfg *BuildArgs
|
var cfg BuildArgs
|
||||||
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars)
|
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars)
|
||||||
flags.Usage = func() { c.Ui.Say(c.Help()) }
|
flags.Usage = func() { c.Ui.Say(c.Help()) }
|
||||||
cfg.AddFlagSets(flags)
|
cfg.AddFlagSets(flags)
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
return cfg, 1
|
return &cfg, 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.ParallelBuilds < 1 {
|
if cfg.ParallelBuilds < 1 {
|
||||||
@ -52,10 +52,10 @@ func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
|
|||||||
args = flags.Args()
|
args = flags.Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
flags.Usage()
|
flags.Usage()
|
||||||
return cfg, 1
|
return &cfg, 1
|
||||||
}
|
}
|
||||||
cfg.Path = args[0]
|
cfg.Path = args[0]
|
||||||
return cfg, 0
|
return &cfg, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Meta) GetConfigFromHCL(path string) (packer.BuildGetter, int) {
|
func (m *Meta) GetConfigFromHCL(path string) (packer.BuildGetter, int) {
|
||||||
@ -374,7 +374,7 @@ Options:
|
|||||||
-force Force a build to continue if artifacts exist, deletes existing artifacts.
|
-force Force a build to continue if artifacts exist, deletes existing artifacts.
|
||||||
-machine-readable Produce machine-readable output.
|
-machine-readable Produce machine-readable output.
|
||||||
-on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
|
-on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
|
||||||
-parallel=false Disable parallelization. (Default: true)
|
-parallel-builds=1 Disable parallelization. (Default: true)
|
||||||
-parallel-builds=1 Number of builds to run in parallel. 0 means no limit (Default: 0)
|
-parallel-builds=1 Number of builds to run in parallel. 0 means no limit (Default: 0)
|
||||||
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
|
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
|
||||||
-var 'key=value' Variable for templates, can be used multiple times.
|
-var 'key=value' Variable for templates, can be used multiple times.
|
||||||
|
@ -18,32 +18,32 @@ func TestBuildCommand_RunContext_CtxCancel(t *testing.T) {
|
|||||||
expected int
|
expected int
|
||||||
}{
|
}{
|
||||||
{"cancel 1 pending build - parallel=true",
|
{"cancel 1 pending build - parallel=true",
|
||||||
[]string{"-parallel=true", filepath.Join(testFixture("parallel"), "1lock-5wg.json")},
|
[]string{"-parallel-builds=10", filepath.Join(testFixture("parallel"), "1lock-5wg.json")},
|
||||||
5,
|
5,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{"cancel in the middle with 2 pending builds - parallel=true",
|
{"cancel in the middle with 2 pending builds - parallel=true",
|
||||||
[]string{"-parallel=true", filepath.Join(testFixture("parallel"), "2lock-4wg.json")},
|
[]string{"-parallel-builds=10", filepath.Join(testFixture("parallel"), "2lock-4wg.json")},
|
||||||
4,
|
4,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{"cancel 1 locked build - debug - parallel=true",
|
{"cancel 1 locked build - debug - parallel=true",
|
||||||
[]string{"-parallel=true", "-debug=true", filepath.Join(testFixture("parallel"), "1lock.json")},
|
[]string{"-parallel-builds=10", "-debug=true", filepath.Join(testFixture("parallel"), "1lock.json")},
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{"cancel 2 locked builds - debug - parallel=true",
|
{"cancel 2 locked builds - debug - parallel=true",
|
||||||
[]string{"-parallel=true", "-debug=true", filepath.Join(testFixture("parallel"), "2lock.json")},
|
[]string{"-parallel-builds=10", "-debug=true", filepath.Join(testFixture("parallel"), "2lock.json")},
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{"cancel 1 locked build - debug - parallel=false",
|
{"cancel 1 locked build - debug - parallel=false",
|
||||||
[]string{"-parallel=false", "-debug=true", filepath.Join(testFixture("parallel"), "1lock.json")},
|
[]string{"-parallel-builds=1", "-debug=true", filepath.Join(testFixture("parallel"), "1lock.json")},
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{"cancel 2 locked builds - debug - parallel=false",
|
{"cancel 2 locked builds - debug - parallel=false",
|
||||||
[]string{"-parallel=false", "-debug=true", filepath.Join(testFixture("parallel"), "2lock.json")},
|
[]string{"-parallel-builds=1", "-debug=true", filepath.Join(testFixture("parallel"), "2lock.json")},
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ func TestBuildWithCleanupScript(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
filepath.Join(testFixture("cleanup-script"), "template.json"),
|
filepath.Join(testFixture("cleanup-script"), "template.json"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ func TestBuildParallel_1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
fmt.Sprintf("-parallel=true"),
|
fmt.Sprintf("-parallel-builds=10"),
|
||||||
filepath.Join(testFixture("parallel"), "1lock-5wg.json"),
|
filepath.Join(testFixture("parallel"), "1lock-5wg.json"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ func TestBuildOnlyFileCommaFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
"-only=chocolate,vanilla",
|
"-only=chocolate,vanilla",
|
||||||
filepath.Join(testFixture("build-only"), "template.json"),
|
filepath.Join(testFixture("build-only"), "template.json"),
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ func TestBuildStdin(t *testing.T) {
|
|||||||
defer func() { os.Stdin = stdin }()
|
defer func() { os.Stdin = stdin }()
|
||||||
|
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
if code := c.Run([]string{"-parallel=false", "-"}); code != 0 {
|
if code := c.Run([]string{"-parallel-builds=1", "-"}); code != 0 {
|
||||||
fatalCommand(t, c.Meta)
|
fatalCommand(t, c.Meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ func TestBuildOnlyFileMultipleFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
"-only=chocolate",
|
"-only=chocolate",
|
||||||
"-only=cherry",
|
"-only=cherry",
|
||||||
"-only=apple", // ignored
|
"-only=apple", // ignored
|
||||||
@ -345,7 +345,7 @@ func TestBuildEverything(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
`-except=`,
|
`-except=`,
|
||||||
filepath.Join(testFixture("build-only"), "template.json"),
|
filepath.Join(testFixture("build-only"), "template.json"),
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
"-except=chocolate,vanilla",
|
"-except=chocolate,vanilla",
|
||||||
filepath.Join(testFixture("build-only"), "template.json"),
|
filepath.Join(testFixture("build-only"), "template.json"),
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ func testHCLOnlyExceptFlags(t *testing.T, args, present, notPresent []string) {
|
|||||||
|
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
finalArgs := []string{"-parallel=false"}
|
finalArgs := []string{"-parallel-builds=1"}
|
||||||
finalArgs = append(finalArgs, args...)
|
finalArgs = append(finalArgs, args...)
|
||||||
finalArgs = append(finalArgs, testFixture("hcl-only-except"))
|
finalArgs = append(finalArgs, testFixture("hcl-only-except"))
|
||||||
|
|
||||||
@ -482,7 +482,7 @@ func TestBuildWithNonExistingBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-parallel=false",
|
"-parallel-builds=1",
|
||||||
`-except=`,
|
`-except=`,
|
||||||
filepath.Join(testFixture("build-only"), "not-found.json"),
|
filepath.Join(testFixture("build-only"), "not-found.json"),
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{fields{defaultMeta},
|
{fields{defaultMeta},
|
||||||
args{[]string{"-parallel=true", "file.json"}},
|
args{[]string{"-parallel-builds=10", "file.json"}},
|
||||||
BuildArgs{
|
BuildArgs{
|
||||||
MetaArgs: MetaArgs{Path: "file.json"},
|
MetaArgs: MetaArgs{Path: "file.json"},
|
||||||
ParallelBuilds: math.MaxInt64,
|
ParallelBuilds: math.MaxInt64,
|
||||||
@ -652,7 +652,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{fields{defaultMeta},
|
{fields{defaultMeta},
|
||||||
args{[]string{"-parallel=false", "file.json"}},
|
args{[]string{"-parallel-builds=1", "file.json"}},
|
||||||
BuildArgs{
|
BuildArgs{
|
||||||
MetaArgs: MetaArgs{Path: "file.json"},
|
MetaArgs: MetaArgs{Path: "file.json"},
|
||||||
ParallelBuilds: 1,
|
ParallelBuilds: 1,
|
||||||
@ -670,7 +670,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{fields{defaultMeta},
|
{fields{defaultMeta},
|
||||||
args{[]string{"-parallel=false", "-parallel-builds=5", "otherfile.json"}},
|
args{[]string{"-parallel-builds=1", "-parallel-builds=5", "otherfile.json"}},
|
||||||
BuildArgs{
|
BuildArgs{
|
||||||
MetaArgs: MetaArgs{Path: "otherfile.json"},
|
MetaArgs: MetaArgs{Path: "otherfile.json"},
|
||||||
ParallelBuilds: 5,
|
ParallelBuilds: 5,
|
||||||
|
@ -41,9 +41,6 @@ func ConfigType(args ...string) (string, error) {
|
|||||||
|
|
||||||
// NewMetaArgs parses cli args and put possible values
|
// NewMetaArgs parses cli args and put possible values
|
||||||
func (ma *MetaArgs) AddFlagSets(fs *flag.FlagSet) {
|
func (ma *MetaArgs) AddFlagSets(fs *flag.FlagSet) {
|
||||||
if ma == nil {
|
|
||||||
ma = &MetaArgs{}
|
|
||||||
}
|
|
||||||
fs.Var((*sliceflag.StringFlag)(&ma.Only), "only", "")
|
fs.Var((*sliceflag.StringFlag)(&ma.Only), "only", "")
|
||||||
fs.Var((*sliceflag.StringFlag)(&ma.Except), "except", "")
|
fs.Var((*sliceflag.StringFlag)(&ma.Except), "except", "")
|
||||||
fs.Var((*kvflag.Flag)(&ma.Vars), "var", "")
|
fs.Var((*kvflag.Flag)(&ma.Vars), "var", "")
|
||||||
@ -60,9 +57,6 @@ type MetaArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ba *BuildArgs) AddFlagSets(flags *flag.FlagSet) {
|
func (ba *BuildArgs) AddFlagSets(flags *flag.FlagSet) {
|
||||||
if ba == nil {
|
|
||||||
ba = &BuildArgs{}
|
|
||||||
}
|
|
||||||
flags.BoolVar(&ba.Color, "color", true, "")
|
flags.BoolVar(&ba.Color, "color", true, "")
|
||||||
flags.BoolVar(&ba.Debug, "debug", false, "")
|
flags.BoolVar(&ba.Debug, "debug", false, "")
|
||||||
flags.BoolVar(&ba.Force, "force", false, "")
|
flags.BoolVar(&ba.Force, "force", false, "")
|
||||||
@ -89,9 +83,6 @@ type BuildArgs struct {
|
|||||||
type ConsoleArgs struct{ MetaArgs }
|
type ConsoleArgs struct{ MetaArgs }
|
||||||
|
|
||||||
func (fa *FixArgs) AddFlagSets(flags *flag.FlagSet) {
|
func (fa *FixArgs) AddFlagSets(flags *flag.FlagSet) {
|
||||||
if fa == nil {
|
|
||||||
fa = &FixArgs{}
|
|
||||||
}
|
|
||||||
flags.BoolVar(&fa.Validate, "validate", true, "")
|
flags.BoolVar(&fa.Validate, "validate", true, "")
|
||||||
|
|
||||||
fa.MetaArgs.AddFlagSets(flags)
|
fa.MetaArgs.AddFlagSets(flags)
|
||||||
@ -104,9 +95,6 @@ type FixArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (va *ValidateArgs) AddFlagSets(flags *flag.FlagSet) {
|
func (va *ValidateArgs) AddFlagSets(flags *flag.FlagSet) {
|
||||||
if va == nil {
|
|
||||||
va = &ValidateArgs{}
|
|
||||||
}
|
|
||||||
flags.BoolVar(&va.SyntaxOnly, "syntax-only", true, "")
|
flags.BoolVar(&va.SyntaxOnly, "syntax-only", true, "")
|
||||||
|
|
||||||
va.MetaArgs.AddFlagSets(flags)
|
va.MetaArgs.AddFlagSets(flags)
|
||||||
|
@ -52,11 +52,6 @@ artifacts that are created will be outputted at the end of the build.
|
|||||||
attribute is specified within the configuration. `-only` does not apply to
|
attribute is specified within the configuration. `-only` does not apply to
|
||||||
post-processors.
|
post-processors.
|
||||||
|
|
||||||
- `-parallel=false` - /!\ Deprecated, use `-parallel-builds=1` instead,
|
|
||||||
setting `-parallel-builds=N` to more that 0 will ignore the `-parallel`
|
|
||||||
setting. Set `-parallel=false` to disable parallelization of multiple
|
|
||||||
builders (on by default).
|
|
||||||
|
|
||||||
- `-parallel-builds=N` - Limit the number of builds to run in parallel, 0
|
- `-parallel-builds=N` - Limit the number of builds to run in parallel, 0
|
||||||
means no limit (defaults to 0).
|
means no limit (defaults to 0).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user