2020-04-16 05:58:54 -04:00
|
|
|
package shell_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/helper/tests/acc"
|
|
|
|
"github.com/hashicorp/packer/provisioner/shell"
|
|
|
|
|
2020-11-20 13:21:29 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-04-16 05:58:54 -04:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/command"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShellLocalProvisionerWithRetryOption(t *testing.T) {
|
|
|
|
acc.TestProvisionersPreCheck("shell-local", t)
|
|
|
|
acc.TestProvisionersAgainstBuilders(new(ShellLocalProvisionerAccTest), t)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShellLocalProvisionerAccTest struct{}
|
|
|
|
|
|
|
|
func (s *ShellLocalProvisionerAccTest) GetName() string {
|
|
|
|
return "file"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShellLocalProvisionerAccTest) GetConfig() (string, error) {
|
|
|
|
filePath := filepath.Join("./test-fixtures", "shell-local-provisioner.txt")
|
|
|
|
config, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Expected to find %s", filePath)
|
|
|
|
}
|
|
|
|
defer config.Close()
|
|
|
|
|
|
|
|
file, err := ioutil.ReadAll(config)
|
|
|
|
return string(file), err
|
|
|
|
}
|
|
|
|
|
2020-12-02 15:12:47 -05:00
|
|
|
func (s *ShellLocalProvisionerAccTest) GetProvisionerStore() packersdk.MapOfProvisioner {
|
|
|
|
return packersdk.MapOfProvisioner{
|
2020-12-01 17:25:14 -05:00
|
|
|
"shell-local": func() (packersdk.Provisioner, error) { return &shell.Provisioner{}, nil },
|
2020-04-16 05:58:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShellLocalProvisionerAccTest) IsCompatible(builder string, vmOS string) bool {
|
|
|
|
return vmOS == "linux"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShellLocalProvisionerAccTest) RunTest(c *command.BuildCommand, args []string) error {
|
|
|
|
if code := c.Run(args); code != 0 {
|
2020-11-20 13:21:29 -05:00
|
|
|
ui := c.Meta.Ui.(*packersdk.BasicUi)
|
2020-04-16 05:58:54 -04:00
|
|
|
out := ui.Writer.(*bytes.Buffer)
|
|
|
|
err := ui.ErrorWriter.(*bytes.Buffer)
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Bad exit code.\n\nStdout:\n\n%s\n\nStderr:\n\n%s",
|
|
|
|
out.String(),
|
|
|
|
err.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|