2019-04-08 07:41:06 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2019-04-08 07:41:06 -04:00
|
|
|
"github.com/hashicorp/packer/builder/file"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
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{
|
2021-01-13 06:14:06 -05:00
|
|
|
BuilderStore: packer.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
|
|
|
},
|
2021-01-13 06:14:06 -05:00
|
|
|
ProvisionerStore: packer.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|