packer-cn/builder/hyperone/builder_acc_test.go

70 lines
1.3 KiB
Go
Raw Normal View History

2019-01-23 08:59:28 -05:00
package hyperone
import (
"os"
"testing"
builderT "github.com/hashicorp/packer/packer-plugin-sdk/acctest"
2019-01-23 08:59:28 -05:00
)
func TestBuilderAcc_basic(t *testing.T) {
builderT.Test(t, builderT.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Builder: &Builder{},
Template: testBuilderAccBasic,
})
}
2019-02-01 12:58:16 -05:00
func TestBuilderAcc_chroot(t *testing.T) {
builderT.Test(t, builderT.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Builder: &Builder{},
Template: testBuilderAccChroot,
})
}
2019-01-23 08:59:28 -05:00
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("HYPERONE_TOKEN"); v == "" {
t.Fatal("HYPERONE_TOKEN must be set for acceptance tests")
}
}
const testBuilderAccBasic = `
{
"builders": [{
"type": "test",
2019-02-01 12:57:43 -05:00
"vm_type": "a1.nano",
2019-02-07 03:22:30 -05:00
"source_image": "ubuntu",
"disk_size": 10,
"image_tags": {
"key":"value"
},
"vm_tags": {
"key_vm":"value_vm"
}
2019-01-23 08:59:28 -05:00
}]
}
`
2019-02-01 12:58:16 -05:00
const testBuilderAccChroot = `
{
"builders": [{
"type": "test",
2019-02-07 03:22:30 -05:00
"source_image": "ubuntu",
2019-02-01 12:58:16 -05:00
"disk_size": 10,
"vm_type": "a1.nano",
"chroot_disk": true,
"chroot_command_wrapper": "sudo {{.Command}}",
"pre_mount_commands": [
"parted {{.Device}} mklabel msdos mkpart primary 1M 100% set 1 boot on print",
"mkfs.ext4 {{.Device}}1"
],
"post_mount_commands": [
"apt-get update",
"apt-get install debootstrap",
"debootstrap --arch amd64 bionic {{.MountPath}}"
]
}]
}
`