mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-03 20:39:29 -05:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"bytes"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
"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{
|
|
PluginConfig: &packer.PluginConfig{
|
|
Builders: packer.MapOfBuilder{
|
|
"file": func() (packersdk.Builder, error) { return &file.Builder{}, nil },
|
|
},
|
|
Provisioners: packer.MapOfProvisioner{
|
|
"sleep": func() (packersdk.Provisioner, error) { return &sleep.Provisioner{}, nil },
|
|
"shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil },
|
|
},
|
|
},
|
|
}
|
|
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),
|
|
Ui: &packersdk.BasicUi{
|
|
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)
|
|
}
|
|
}
|
|
}
|