Added acceptance test for file builder
This commit is contained in:
parent
29f02d243f
commit
aea70d5a72
|
@ -15,27 +15,13 @@ import (
|
|||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
const BuilderId = "cbednarski.file"
|
||||
const BuilderId = "packer.file"
|
||||
|
||||
type Builder struct {
|
||||
config *Config
|
||||
runner multistep.Runner
|
||||
}
|
||||
|
||||
// Prepare is responsible for configuring the builder and validating
|
||||
// that configuration. Any setup should be done in this method. Note that
|
||||
// NO side effects should take place in prepare, it is meant as a state
|
||||
// setup only. Calling Prepare is not necessarilly followed by a Run.
|
||||
//
|
||||
// The parameters to Prepare are a set of interface{} values of the
|
||||
// configuration. These are almost always `map[string]interface{}`
|
||||
// parsed from a template, but no guarantee is made.
|
||||
//
|
||||
// Each of the configuration values should merge into the final
|
||||
// configuration.
|
||||
//
|
||||
// Prepare should return a list of warnings along with any errors
|
||||
// that occured while preparing.
|
||||
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||
c, warnings, errs := NewConfig(raws...)
|
||||
if errs != nil {
|
||||
|
|
|
@ -1,11 +1,78 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
builderT "github.com/mitchellh/packer/helper/builder/testing"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
func TestBuilder_implBuilder(t *testing.T) {
|
||||
var _ packer.Builder = new(Builder)
|
||||
}
|
||||
|
||||
func TestBuilderFileAcc_content(t *testing.T) {
|
||||
builderT.Test(t, builderT.TestCase{
|
||||
Builder: &Builder{},
|
||||
Template: fileContentTest,
|
||||
Check: checkContent,
|
||||
})
|
||||
}
|
||||
|
||||
func TestBuilderFileAcc_copy(t *testing.T) {
|
||||
builderT.Test(t, builderT.TestCase{
|
||||
Builder: &Builder{},
|
||||
Template: fileCopyTest,
|
||||
Check: checkCopy,
|
||||
})
|
||||
}
|
||||
|
||||
func checkContent(artifacts []packer.Artifact) error {
|
||||
content, err := ioutil.ReadFile("contentTest.txt")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contentString := string(content)
|
||||
if contentString != "hello world!" {
|
||||
return fmt.Errorf("Unexpected file contents: %s", contentString)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkCopy(artifacts []packer.Artifact) error {
|
||||
content, err := ioutil.ReadFile("copyTest.txt")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contentString := string(content)
|
||||
if contentString != "Hello world.\n" {
|
||||
return fmt.Errorf("Unexpected file contents: %s", contentString)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const fileContentTest = `
|
||||
{
|
||||
"builders": [
|
||||
{
|
||||
"type":"test",
|
||||
"target":"contentTest.txt",
|
||||
"content":"hello world!"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
const fileCopyTest = `
|
||||
{
|
||||
"builders": [
|
||||
{
|
||||
"type":"test",
|
||||
"target":"copyTest.txt",
|
||||
"source":"test-fixtures/artifact.txt"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -39,8 +38,7 @@ func TestNoContent(t *testing.T) {
|
|||
delete(raw, "content")
|
||||
delete(raw, "source")
|
||||
_, warns, _ := NewConfig(raw)
|
||||
fmt.Println(len(warns))
|
||||
fmt.Printf("%#v\n", warns)
|
||||
|
||||
if len(warns) == 0 {
|
||||
t.Error("Expected config warning without any content")
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Hello world.
|
Loading…
Reference in New Issue