2019-04-08 07:41:06 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/builder/file"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-20 13:21:29 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2019-04-08 07:41:06 -04:00
|
|
|
shell_local "github.com/hashicorp/packer/provisioner/shell-local"
|
|
|
|
"github.com/hashicorp/packer/provisioner/sleep"
|
|
|
|
)
|
|
|
|
|
|
|
|
// testCoreConfigBuilder creates a packer CoreConfig that has a file builder
|
|
|
|
// available. This allows us to test a builder that writes files to disk.
|
|
|
|
func testCoreConfigSleepBuilder(t *testing.T) *packer.CoreConfig {
|
|
|
|
components := packer.ComponentFinder{
|
2020-12-02 15:12:47 -05:00
|
|
|
BuilderStore: packersdk.MapOfBuilder{
|
2020-12-01 16:42:11 -05:00
|
|
|
"file": func() (packersdk.Builder, error) { return &file.Builder{}, nil },
|
2019-04-08 07:41:06 -04:00
|
|
|
},
|
2020-12-02 15:12:47 -05:00
|
|
|
ProvisionerStore: packersdk.MapOfProvisioner{
|
2020-12-01 17:25:14 -05:00
|
|
|
"sleep": func() (packersdk.Provisioner, error) { return &sleep.Provisioner{}, nil },
|
|
|
|
"shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil },
|
2019-04-08 07:41:06 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return &packer.CoreConfig{
|
|
|
|
Components: components,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// testMetaFile creates a Meta object that includes a file builder
|
|
|
|
func testMetaSleepFile(t *testing.T) Meta {
|
|
|
|
var out, err bytes.Buffer
|
|
|
|
return Meta{
|
|
|
|
CoreConfig: testCoreConfigSleepBuilder(t),
|
2020-11-20 13:21:29 -05:00
|
|
|
Ui: &packersdk.BasicUi{
|
2019-04-08 07:41:06 -04:00
|
|
|
Writer: &out,
|
|
|
|
ErrorWriter: &err,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildSleepTimeout(t *testing.T) {
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
c := &BuildCommand{
|
|
|
|
Meta: testMetaSleepFile(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
filepath.Join(testFixture("timeout"), "template.json"),
|
|
|
|
}
|
|
|
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
if code := c.Run(args); code == 0 {
|
|
|
|
fatalCommand(t, c.Meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range []string{"roses.txt", "fuchsias.txt", "lilas.txt"} {
|
|
|
|
if !fileExists(f) {
|
|
|
|
t.Errorf("Expected to find %s", f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range []string{"campanules.txt"} {
|
|
|
|
if fileExists(f) {
|
|
|
|
t.Errorf("Expected to not find %s", f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|