From a36b1ad934bf9ce83f04544e1d9e6f8f6fffcb48 Mon Sep 17 00:00:00 2001 From: Matthew Schuchard <8029687+mschuchard@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:24:05 -0500 Subject: [PATCH] proper destination_dir conditionals and update util unit test --- provisioner/testinfra.go | 15 +++++++++------ provisioner/util_test.go | 7 +++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/provisioner/testinfra.go b/provisioner/testinfra.go index b5d5459..13c4e0e 100644 --- a/provisioner/testinfra.go +++ b/provisioner/testinfra.go @@ -227,16 +227,19 @@ func (provisioner *Provisioner) Provision(ctx context.Context, ui packer.Ui, com return err } - // upload testinfra files to temporary packer instance - if err = uploadFiles(comm, provisioner.config.TestFiles, provisioner.config.DestinationDir); err != nil { - ui.Error("the test files could not be transferred to the temporary Packer instance") - return err - } - // execute testinfra remotely with *exec.Cmd if localCmd == nil && cmd != nil { err = execCmd(cmd, ui) } else if localCmd != nil && cmd == nil { + // testinfra local execution + if len(provisioner.config.DestinationDir) > 0 { + // upload testinfra files to temporary packer instance + if err = uploadFiles(comm, provisioner.config.TestFiles, provisioner.config.DestinationDir); err != nil { + ui.Error("the test files could not be transferred to the temporary Packer instance") + return err + } + } + // execute testinfra local to instance with packer.RemoteCmd err = packerRemoteCmd(localCmd, provisioner.config.InstallCmd, comm, ui) } else { diff --git a/provisioner/util_test.go b/provisioner/util_test.go index 077a799..b28e6fc 100644 --- a/provisioner/util_test.go +++ b/provisioner/util_test.go @@ -11,13 +11,12 @@ import ( func TestProvisionerUploadFiles(test *testing.T) { comm := new(packer.MockCommunicator) - err := uploadFiles(comm, []string{}, "/tmp/") + err := uploadFiles(comm, []string{"../.gitignore"}, "/dafdfsad") if err != nil { - test.Errorf("uploadFiles with empty files slice input returned error") - test.Error(err) + test.Errorf("generic inputs returned error: %s", err) } - err = uploadFiles(comm, []string{"foobar"}, "/tmp/") + err = uploadFiles(comm, []string{"foobar"}, "/tmp") if !errors.Is(err, os.ErrNotExist) { test.Errorf("expected nonexistent file to return ErrNotExist error, but instead %s was returned", err) }