Skip to content

Commit

Permalink
implement different levels of verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Jun 26, 2024
1 parent f76b4c3 commit 455ed79
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion provisioner/testinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions provisioner/testinfra_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion provisioner/testinfra_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion provisioner/testinfra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 455ed79

Please sign in to comment.