move provisioner acceptance tests into sdk alongside builder acceptance tests. Reorganize slightly to make sure no import cycles of doom get formed

This commit is contained in:
Megan Marsh 2020-12-03 13:56:41 -08:00
parent becf7723e6
commit 8f51a8bfae
8 changed files with 45 additions and 43 deletions

View File

@ -447,7 +447,7 @@ For the Shell provisioner this is:
os.Setenv("PACKER_RUN_UUID", UUID)
}
file := "provisioner.shell." + UUID + ".txt"
defer testshelper.CleanupFiles(file)
defer testutils.CleanupFiles(file)
// Run build
// All provisioner acc tests should contain this code and validation
@ -462,7 +462,7 @@ For the Shell provisioner this is:
}
// Any other extra specific validation
if !testshelper.FileExists(file) {
if !testutils.FileExists(file) {
return fmt.Errorf("Expected to find %s", file)
}
return nil

View File

@ -11,9 +11,8 @@ import (
"github.com/hashicorp/packer/builder/virtualbox/iso"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/testutils"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
testshelper "github.com/hashicorp/packer/helper/tests"
)
type VirtualBoxISOAccTest struct{}
@ -34,8 +33,8 @@ func (v *VirtualBoxISOAccTest) GetConfigs() (map[string]string, error) {
}
func (v *VirtualBoxISOAccTest) CleanUp() error {
testshelper.CleanupFiles("virtualbox-iso-packer-acc-test")
testshelper.CleanupFiles("packer_cache")
testutils.CleanupFiles("virtualbox-iso-packer-acc-test")
testutils.CleanupFiles("packer_cache")
return nil
}

View File

@ -1,8 +1,7 @@
package testshelper
package provisioneracc
import (
"bytes"
"os"
"testing"
amazonebsbuilder "github.com/hashicorp/packer/builder/amazon/ebs"
@ -13,14 +12,6 @@ import (
"github.com/hashicorp/packer/provisioner/shell"
)
// fileExists returns true if the filename is found
func FileExists(filename string) bool {
if _, err := os.Stat(filename); err == nil {
return true
}
return false
}
// testCoreConfigBuilder creates a packer CoreConfig that has a file builder
// available. This allows us to test a builder that writes files to disk.
func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig {
@ -50,9 +41,3 @@ func TestMetaFile(t *testing.T) command.Meta {
},
}
}
func CleanupFiles(moreFiles ...string) {
for _, file := range moreFiles {
os.RemoveAll(file)
}
}

View File

@ -1,4 +1,4 @@
package acc
package provisioneracc
import (
"bytes"
@ -9,11 +9,10 @@ import (
"strings"
"testing"
testshelper "github.com/hashicorp/packer/helper/tests"
amazonEBS "github.com/hashicorp/packer/builder/amazon/ebs/acceptance"
virtualboxISO "github.com/hashicorp/packer/builder/virtualbox/iso/acceptance"
"github.com/hashicorp/packer/command"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/testutils"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
)
@ -56,7 +55,7 @@ func TestProvisionersAgainstBuilders(provisionerAcc ProvisionerAcceptance, t *te
err = provisionerAcc.RunTest(c, args)
// Cleanup created resources
testshelper.CleanupFiles(fileName)
testutils.CleanupFiles(fileName)
cleanErr := builderAcc.CleanUp()
if cleanErr != nil {
log.Printf("bad: failed to clean up resources: %s", cleanErr.Error())
@ -122,7 +121,7 @@ func writeJsonTemplate(out *bytes.Buffer, filePath string, t *testing.T) {
func buildCommand(t *testing.T, builder BuilderAcceptance, provisioner ProvisionerAcceptance) *command.BuildCommand {
c := &command.BuildCommand{
Meta: testshelper.TestMetaFile(t),
Meta: TestMetaFile(t),
}
c.CoreConfig.Components.BuilderStore = builder.GetBuilderStore()
c.CoreConfig.Components.ProvisionerStore = provisioner.GetProvisionerStore()

View File

@ -0,0 +1,18 @@
package testutils
import "os"
// CleanupFiles removes all files in the given strings.
func CleanupFiles(moreFiles ...string) {
for _, file := range moreFiles {
os.RemoveAll(file)
}
}
// FileExists returns true if the filename is found.
func FileExists(filename string) bool {
if _, err := os.Stat(filename); err == nil {
return true
}
return false
}

View File

@ -10,7 +10,7 @@ import (
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/packer/command"
"github.com/hashicorp/packer/helper/tests/acc"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/provisioneracc"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/provisioner/powershell"
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
@ -19,24 +19,24 @@ import (
const TestProvisionerName = "powershell"
func TestAccPowershellProvisioner_basic(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
provisioneracc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-provisioner-cleanup.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
provisioneracc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
func TestAccPowershellProvisioner_Inline(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
provisioneracc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-inline-provisioner.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
provisioneracc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
func TestAccPowershellProvisioner_Script(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
provisioneracc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-script-provisioner.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
provisioneracc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
type PowershellProvisionerAccTest struct {

View File

@ -8,7 +8,8 @@ import (
"path/filepath"
"testing"
"github.com/hashicorp/packer/helper/tests/acc"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/provisioneracc"
"github.com/hashicorp/packer/provisioner/shell"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
@ -17,8 +18,8 @@ import (
)
func TestShellLocalProvisionerWithRetryOption(t *testing.T) {
acc.TestProvisionersPreCheck("shell-local", t)
acc.TestProvisionersAgainstBuilders(new(ShellLocalProvisionerAccTest), t)
provisioneracc.TestProvisionersPreCheck("shell-local", t)
provisioneracc.TestProvisionersAgainstBuilders(new(ShellLocalProvisionerAccTest), t)
}
type ShellLocalProvisionerAccTest struct{}

View File

@ -8,7 +8,8 @@ import (
"path/filepath"
"testing"
"github.com/hashicorp/packer/helper/tests/acc"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/provisioneracc"
"github.com/hashicorp/packer/packer-plugin-sdk/acctest/testutils"
"github.com/hashicorp/packer/provisioner/file"
"github.com/hashicorp/packer/provisioner/shell"
@ -16,12 +17,11 @@ import (
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/packer/command"
testshelper "github.com/hashicorp/packer/helper/tests"
)
func TestShellProvisioner(t *testing.T) {
acc.TestProvisionersPreCheck("shell", t)
acc.TestProvisionersAgainstBuilders(new(ShellProvisionerAccTest), t)
provisioneracc.TestProvisionersPreCheck("shell", t)
provisioneracc.TestProvisionersAgainstBuilders(new(ShellProvisionerAccTest), t)
}
type ShellProvisionerAccTest struct{}
@ -61,7 +61,7 @@ func (s *ShellProvisionerAccTest) RunTest(c *command.BuildCommand, args []string
}
file := "provisioner.shell." + UUID + ".txt"
defer testshelper.CleanupFiles(file)
defer testutils.CleanupFiles(file)
if code := c.Run(args); code != 0 {
ui := c.Meta.Ui.(*packersdk.BasicUi)
@ -73,7 +73,7 @@ func (s *ShellProvisionerAccTest) RunTest(c *command.BuildCommand, args []string
err.String())
}
if !testshelper.FileExists(file) {
if !testutils.FileExists(file) {
return fmt.Errorf("Expected to find %s", file)
}
return nil