diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e1762..a81bf51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### 1.4.0 +- Support multiple levels of verbose. + ### 1.3.1 - Improve logging. - Fix returns for errors during execution command determination. diff --git a/provisioner/testinfra.go b/provisioner/testinfra.go index 103d72c..8cee2b9 100644 --- a/provisioner/testinfra.go +++ b/provisioner/testinfra.go @@ -176,7 +176,7 @@ func (provisioner *Provisioner) Prepare(raws ...interface{}) error { // verbose parameter if provisioner.config.Verbose > 0 { - log.Print("pytest will execute with verbose enabled at level %d", provisioner.config.Verbose) + log.Printf("pytest will execute with verbose enabled at level %d", provisioner.config.Verbose) } // check if testinfra files are specified as inputs diff --git a/provisioner/testinfra_command.go b/provisioner/testinfra_command.go index b547f07..a6d0251 100644 --- a/provisioner/testinfra_command.go +++ b/provisioner/testinfra_command.go @@ -191,11 +191,19 @@ func (provisioner *Provisioner) determineExecCmd() (*exec.Cmd, *packer.RemoteCmd args = append(args, fmt.Sprintf("\"--sudo-user=%s\"", provisioner.config.SudoUser)) } } - // verbose - if provisioner.config.Verbose { - args = append(args, "-v") + if provisioner.config.Verbose > 0 { + // initialize arg + levelArg := "-" + + // determine number of "v" in arg this way until go 1.23 + for level := 0; level < provisioner.config.Verbose; level++ { + levelArg += "v" + } + + args = append(args, levelArg) } + // testfiles args = append(args, provisioner.config.TestFiles...) // 1.22: args = slices.Concat(args, provisioner.config.TestFiles) diff --git a/provisioner/testinfra_command_test.go b/provisioner/testinfra_command_test.go index 9d65c11..9dafc91 100644 --- a/provisioner/testinfra_command_test.go +++ b/provisioner/testinfra_command_test.go @@ -56,7 +56,7 @@ func TestProvisionerDetermineExecCmd(test *testing.T) { test.Errorf("actual: %s, expected: %s", execCmd.Dir, basicConfig.Chdir) } // 1.22 slices.Concat( , provisioner.config.TestFiles) - if !slices.Equal(execCmd.Args, append([]string{provisioner.config.PytestPath, fmt.Sprintf("--hosts=ssh://%s@%s:%d", generatedData["User"], generatedData["Host"], generatedData["Port"]), fmt.Sprintf("--ssh-identity-file=%s", generatedData["SSHPrivateKeyFile"]), "--ssh-extra-args=\"-o StrictHostKeyChecking=no\"", "-k", fmt.Sprintf("\"%s\"", provisioner.config.Keyword), "-m", fmt.Sprintf("\"%s\"", provisioner.config.Marker), "-n", fmt.Sprint(provisioner.config.Processes), "--sudo", "-v"}, provisioner.config.TestFiles...)) { + if !slices.Equal(execCmd.Args, append([]string{provisioner.config.PytestPath, fmt.Sprintf("--hosts=ssh://%s@%s:%d", generatedData["User"], generatedData["Host"], generatedData["Port"]), fmt.Sprintf("--ssh-identity-file=%s", generatedData["SSHPrivateKeyFile"]), "--ssh-extra-args=\"-o StrictHostKeyChecking=no\"", "-k", fmt.Sprintf("\"%s\"", provisioner.config.Keyword), "-m", fmt.Sprintf("\"%s\"", provisioner.config.Marker), "-n", fmt.Sprint(provisioner.config.Processes), "--sudo", "-vv"}, provisioner.config.TestFiles...)) { test.Errorf("determineExecCmd function failed to properly determine remote execution command for basic config with SSH communicator: %s", execCmd.String()) } if localCmd != nil { diff --git a/provisioner/testinfra_test.go b/provisioner/testinfra_test.go index 05dc1c1..a1f0c7a 100644 --- a/provisioner/testinfra_test.go +++ b/provisioner/testinfra_test.go @@ -23,7 +23,7 @@ var basicConfig = &Config{ Sudo: true, SudoUser: "fooman", TestFiles: []string{"fixtures/test.py"}, - Verbose: 1, + Verbose: 2, } // test basic config for packer template/config data