@ -3,12 +3,9 @@ package lib
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"
"testing"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/suite"
)
@ -51,48 +48,6 @@ func (ts *PackerTestSuite) CompileTestPluginVersions(t *testing.T, versions ...s
wg . Wait ( )
}
// BuildSimplePlugin creates a plugin that essentially does nothing.
//
// The plugin's code is contained in a subdirectory of this, and lets us
// change the attributes of the plugin binary itself, like the SDK version,
// the plugin's version, etc.
//
// The plugin is functional, and can be used to run builds with.
// There won't be anything substantial created though, its goal is only
// to validate the core functionality of Packer.
//
// The path to the plugin is returned, it won't be removed automatically
// though, deletion is the caller's responsibility.
func ( ts * PackerTestSuite ) BuildSimplePlugin ( versionString string , t * testing . T ) string {
// Only build plugin binary if not already done beforehand
path , ok := ts . LoadPluginVersion ( versionString )
if ok {
return path
}
v := version . Must ( version . NewSemver ( versionString ) )
t . Logf ( "Building plugin in version %v" , v )
testDir , err := currentDir ( )
if err != nil {
t . Fatalf ( "failed to compile plugin binary: %s" , err )
}
testerPluginDir := filepath . Join ( testDir , "plugin_tester" )
outBin := filepath . Join ( ts . pluginsDirectory , BinaryName ( v ) )
compileCommand := exec . Command ( "go" , "build" , "-C" , testerPluginDir , "-o" , outBin , "-ldflags" , LDFlags ( v ) , "." )
logs , err := compileCommand . CombinedOutput ( )
if err != nil {
t . Fatalf ( "failed to compile plugin binary: %s\ncompiler logs: %s" , err , logs )
}
ts . StorePluginVersion ( v . String ( ) , outBin )
return outBin
}
// SkipNoAcc is a pre-condition that skips the test if the PACKER_ACC environment
// variable is unset, or set to "0".
//