fix tests

This commit is contained in:
Adrien Delorme 2020-05-08 17:46:33 +02:00
parent 1f3e85185e
commit efcc6af06c
7 changed files with 23 additions and 40 deletions

View File

@ -37,12 +37,12 @@ func (c *BuildCommand) Run(args []string) int {
}
func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
var cfg *BuildArgs
var cfg BuildArgs
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars)
flags.Usage = func() { c.Ui.Say(c.Help()) }
cfg.AddFlagSets(flags)
if err := flags.Parse(args); err != nil {
return cfg, 1
return &cfg, 1
}
if cfg.ParallelBuilds < 1 {
@ -52,10 +52,10 @@ func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
args = flags.Args()
if len(args) != 1 {
flags.Usage()
return cfg, 1
return &cfg, 1
}
cfg.Path = args[0]
return cfg, 0
return &cfg, 0
}
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.
-machine-readable Produce machine-readable output.
-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)
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
-var 'key=value' Variable for templates, can be used multiple times.

View File

@ -18,32 +18,32 @@ func TestBuildCommand_RunContext_CtxCancel(t *testing.T) {
expected int
}{
{"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,
1,
},
{"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,
1,
},
{"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,
1,
},
{"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,
1,
},
{"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,
1,
},
{"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,
1,
},

View File

@ -11,7 +11,7 @@ func TestBuildWithCleanupScript(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
filepath.Join(testFixture("cleanup-script"), "template.json"),
}

View File

@ -95,7 +95,7 @@ func TestBuildParallel_1(t *testing.T) {
}
args := []string{
fmt.Sprintf("-parallel=true"),
fmt.Sprintf("-parallel-builds=10"),
filepath.Join(testFixture("parallel"), "1lock-5wg.json"),
}

View File

@ -224,7 +224,7 @@ func TestBuildOnlyFileCommaFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
"-only=chocolate,vanilla",
filepath.Join(testFixture("build-only"), "template.json"),
}
@ -266,7 +266,7 @@ func TestBuildStdin(t *testing.T) {
defer func() { os.Stdin = stdin }()
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)
}
@ -284,7 +284,7 @@ func TestBuildOnlyFileMultipleFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
"-only=chocolate",
"-only=cherry",
"-only=apple", // ignored
@ -345,7 +345,7 @@ func TestBuildEverything(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
`-except=`,
filepath.Join(testFixture("build-only"), "template.json"),
}
@ -370,7 +370,7 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
"-except=chocolate,vanilla",
filepath.Join(testFixture("build-only"), "template.json"),
}
@ -401,7 +401,7 @@ func testHCLOnlyExceptFlags(t *testing.T, args, present, notPresent []string) {
defer cleanup()
finalArgs := []string{"-parallel=false"}
finalArgs := []string{"-parallel-builds=1"}
finalArgs = append(finalArgs, args...)
finalArgs = append(finalArgs, testFixture("hcl-only-except"))
@ -482,7 +482,7 @@ func TestBuildWithNonExistingBuilder(t *testing.T) {
}
args := []string{
"-parallel=false",
"-parallel-builds=1",
`-except=`,
filepath.Join(testFixture("build-only"), "not-found.json"),
}
@ -643,7 +643,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
0,
},
{fields{defaultMeta},
args{[]string{"-parallel=true", "file.json"}},
args{[]string{"-parallel-builds=10", "file.json"}},
BuildArgs{
MetaArgs: MetaArgs{Path: "file.json"},
ParallelBuilds: math.MaxInt64,
@ -652,7 +652,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
0,
},
{fields{defaultMeta},
args{[]string{"-parallel=false", "file.json"}},
args{[]string{"-parallel-builds=1", "file.json"}},
BuildArgs{
MetaArgs: MetaArgs{Path: "file.json"},
ParallelBuilds: 1,
@ -670,7 +670,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
0,
},
{fields{defaultMeta},
args{[]string{"-parallel=false", "-parallel-builds=5", "otherfile.json"}},
args{[]string{"-parallel-builds=1", "-parallel-builds=5", "otherfile.json"}},
BuildArgs{
MetaArgs: MetaArgs{Path: "otherfile.json"},
ParallelBuilds: 5,

View File

@ -41,9 +41,6 @@ func ConfigType(args ...string) (string, error) {
// NewMetaArgs parses cli args and put possible values
func (ma *MetaArgs) AddFlagSets(fs *flag.FlagSet) {
if ma == nil {
ma = &MetaArgs{}
}
fs.Var((*sliceflag.StringFlag)(&ma.Only), "only", "")
fs.Var((*sliceflag.StringFlag)(&ma.Except), "except", "")
fs.Var((*kvflag.Flag)(&ma.Vars), "var", "")
@ -60,9 +57,6 @@ type MetaArgs struct {
}
func (ba *BuildArgs) AddFlagSets(flags *flag.FlagSet) {
if ba == nil {
ba = &BuildArgs{}
}
flags.BoolVar(&ba.Color, "color", true, "")
flags.BoolVar(&ba.Debug, "debug", false, "")
flags.BoolVar(&ba.Force, "force", false, "")
@ -89,9 +83,6 @@ type BuildArgs struct {
type ConsoleArgs struct{ MetaArgs }
func (fa *FixArgs) AddFlagSets(flags *flag.FlagSet) {
if fa == nil {
fa = &FixArgs{}
}
flags.BoolVar(&fa.Validate, "validate", true, "")
fa.MetaArgs.AddFlagSets(flags)
@ -104,9 +95,6 @@ type FixArgs struct {
}
func (va *ValidateArgs) AddFlagSets(flags *flag.FlagSet) {
if va == nil {
va = &ValidateArgs{}
}
flags.BoolVar(&va.SyntaxOnly, "syntax-only", true, "")
va.MetaArgs.AddFlagSets(flags)

View File

@ -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
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
means no limit (defaults to 0).