Skip to content

Commit

Permalink
proper destination_dir conditionals and update util unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Jan 2, 2025
1 parent be40bc8 commit a36b1ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 9 additions & 6 deletions provisioner/testinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions provisioner/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit a36b1ad

Please sign in to comment.