Skip to content

Commit

Permalink
1.22: replace append with concat where advantageous
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Aug 26, 2024
1 parent 23e6625 commit 68fa06e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions provisioner/testinfra_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (provisioner *Provisioner) determineExecCmd() (*exec.Cmd, *packer.RemoteCmd
return nil, nil, err
}

args = append(args, communication...)
args = slices.Concat(args, communication)
}

// assign mandatory populated values
Expand Down Expand Up @@ -179,7 +179,6 @@ func (provisioner *Provisioner) determineExecCmd() (*exec.Cmd, *packer.RemoteCmd
}
// parallel
if provisioner.config.Parallel {
// 1.22: args = slices.Concat
args = append(args, "-n", "auto")
}
// sudo
Expand All @@ -205,8 +204,7 @@ func (provisioner *Provisioner) determineExecCmd() (*exec.Cmd, *packer.RemoteCmd
}

// testfiles
args = append(args, provisioner.config.TestFiles...)
// 1.22: args = slices.Concat(args, provisioner.config.TestFiles)
args = slices.Concat(args, provisioner.config.TestFiles)

// return packer remote command for local testing on instance
if localExec {
Expand Down
3 changes: 1 addition & 2 deletions provisioner/testinfra_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func TestProvisionerDetermineExecCmd(test *testing.T) {
test.Error("determineExecCmd function failed to determine execution directory for basic config")
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", "auto", "--sudo", "-vv"}, provisioner.config.TestFiles...)) {
if !slices.Equal(execCmd.Args, slices.Concat([]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", "auto", "--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

0 comments on commit 68fa06e

Please sign in to comment.