2015-06-12 20:24:03 -04:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
2015-06-16 14:31:53 -04:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2015-06-12 20:24:03 -04:00
|
|
|
"testing"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
builderT "github.com/hashicorp/packer/helper/builder/testing"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-06-12 20:24:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuilder_implBuilder(t *testing.T) {
|
|
|
|
var _ packer.Builder = new(Builder)
|
|
|
|
}
|
2015-06-16 14:31:53 -04:00
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|