Added acceptance test for file builder
This commit is contained in:
parent
29f02d243f
commit
fe0c548619
|
@ -15,27 +15,13 @@ import (
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
const BuilderId = "cbednarski.file"
|
const BuilderId = "packer.file"
|
||||||
|
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
config *Config
|
config *Config
|
||||||
runner multistep.Runner
|
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) {
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
c, warnings, errs := NewConfig(raws...)
|
c, warnings, errs := NewConfig(raws...)
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
|
|
|
@ -1,11 +1,78 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
builderT "github.com/mitchellh/packer/helper/builder/testing"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuilder_implBuilder(t *testing.T) {
|
func TestBuilder_implBuilder(t *testing.T) {
|
||||||
var _ packer.Builder = new(Builder)
|
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
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -39,8 +38,7 @@ func TestNoContent(t *testing.T) {
|
||||||
delete(raw, "content")
|
delete(raw, "content")
|
||||||
delete(raw, "source")
|
delete(raw, "source")
|
||||||
_, warns, _ := NewConfig(raw)
|
_, warns, _ := NewConfig(raw)
|
||||||
fmt.Println(len(warns))
|
|
||||||
fmt.Printf("%#v\n", warns)
|
|
||||||
if len(warns) == 0 {
|
if len(warns) == 0 {
|
||||||
t.Error("Expected config warning without any content")
|
t.Error("Expected config warning without any content")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Hello world.
|
|
@ -1,3 +1,22 @@
|
||||||
package compress
|
package compress
|
||||||
|
|
||||||
import ()
|
// import (
|
||||||
|
// "testing"
|
||||||
|
//
|
||||||
|
// builderT "github.com/mitchellh/packer/helper/builder/testing"
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// func TestBuilderTagsAcc_basic(t *testing.T) {
|
||||||
|
// builderT.Test(t, builderT.TestCase{
|
||||||
|
// Builder: &Builder{},
|
||||||
|
// Template: simpleTestCase,
|
||||||
|
// Check: checkTags(),
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
const simpleTestCase = `
|
||||||
|
{
|
||||||
|
"type": "compress",
|
||||||
|
"output": "foo.tar.gz"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue