You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/packer_test/suite_test.go

84 lines
2.0 KiB

package packer_test
import (
"os"
"sync"
"testing"
"github.com/stretchr/testify/suite"
)
type PackerTestSuite struct {
suite.Suite
// pluginsDirectory is the directory in which plugins are compiled.
//
// Those binaries are not necessarily meant to be used as-is, but
// instead should be used for composing plugin installation directories.
pluginsDirectory string
// packerPath is the location in which the Packer executable is compiled
//
// Since we don't necessarily want to manually compile Packer beforehand,
// we compile it on demand, and use this executable for the tests.
packerPath string
}
func buildPluginVersion(waitgroup *sync.WaitGroup, versionString string, t *testing.T) {
waitgroup.Add(1)
go func() {
defer waitgroup.Done()
BuildSimplePlugin(versionString, t)
}()
}
func (ts *PackerTestSuite) buildPluginBinaries(t *testing.T) {
wg := &sync.WaitGroup{}
buildPluginVersion(wg, "1.0.0", t)
buildPluginVersion(wg, "1.0.0+metadata", t)
buildPluginVersion(wg, "1.0.1-alpha1", t)
buildPluginVersion(wg, "1.0.9", t)
buildPluginVersion(wg, "1.0.10", t)
wg.Wait()
}
func Test_PackerCoreSuite(t *testing.T) {
ts := &PackerTestSuite{}
pluginsDirectory := PluginBinaryDir()
defer func() {
err := os.RemoveAll(pluginsDirectory)
if err != nil {
t.Logf("failed to cleanup directory %q: %s. This will need manual action", pluginsDirectory, err)
}
}()
ts.pluginsDirectory = pluginsDirectory
ts.buildPluginBinaries(t)
packerPath := os.Getenv("PACKER_CUSTOM_PATH")
if packerPath == "" {
var err error
t.Logf("Building test packer binary...")
packerPath, err = BuildTestPacker(t)
if err != nil {
t.Fatalf("failed to build Packer binary: %s", err)
}
}
ts.packerPath = packerPath
t.Logf("Done")
defer func() {
if os.Getenv("PACKER_CUSTOM_PATH") != "" {
return
}
err := os.Remove(ts.packerPath)
if err != nil {
t.Logf("failed to cleanup compiled packer binary %q: %s. This will need manual action", packerPath, err)
}
}()
suite.Run(t, ts)
}