aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Maiocchi <dmaiocchi@suse.com>2017-11-14 21:20:54 +0100
committerDario Maiocchi <dmaiocchi@suse.com>2017-11-16 16:33:14 +0100
commit4ae842bbeb3b9d72659d4c78f6bf1c75a7881965 (patch)
tree270f63c34e3731dd8e64dde8d02bfb26a6070f31
parent9d3bfb5aaf0b51695a2dae54ede7845660d8eb70 (diff)
downloadterraform-provider-libvirt-4ae842bbeb3b9d72659d4c78f6bf1c75a7881965.tar
terraform-provider-libvirt-4ae842bbeb3b9d72659d4c78f6bf1c75a7881965.tar.gz
add geniso to travis_guest
-rw-r--r--libvirt/cloudinit_def_test.go62
-rwxr-xr-xtravis/setup-guest2
2 files changed, 48 insertions, 16 deletions
diff --git a/libvirt/cloudinit_def_test.go b/libvirt/cloudinit_def_test.go
index 18c63a07..1604c667 100644
--- a/libvirt/cloudinit_def_test.go
+++ b/libvirt/cloudinit_def_test.go
@@ -3,11 +3,13 @@ package libvirt
import (
"fmt"
"github.com/hashicorp/terraform/helper/resource"
+ "github.com/hashicorp/terraform/terraform"
+ "gopkg.in/yaml.v2"
"os"
"path/filepath"
+ "regexp"
"strings"
"testing"
- "gopkg.in/yaml.v2"
)
func TestNewCloudInitDef(t *testing.T) {
@@ -163,27 +165,57 @@ ssh_authorized_keys:
}
func TestCreateCloudIsoViaPlugin(t *testing.T) {
- var config = fmt.Sprintf(`
-
- resource "libvirt_cloudinit" "test" {
- name = "commoninit.iso"
- local_hostname = "tango"
- pool = "default"
- user_data = "#cloud-config\nssh_authorized_keys: []\n"
- }
- `)
+
+ // FIXME: check for existence of the cloud-init volume
+
resource.Test(t, resource.TestCase{
- PreCheck: func() { testAccPreCheck(t) },
- Providers: testAccProviders,
- CheckDestroy: testAccCheckLibvirtIgnitionDestroy,
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: func(s *terraform.State) error {
+ return nil
+ },
Steps: []resource.TestStep{
{
- Config: config,
+ Config: fmt.Sprintf(`
+ resource "libvirt_cloudinit" "test" {
+ name = "commoninit.iso"
+ local_hostname = "tango1"
+ pool = "default"
+ user_data = "#cloud-config\nssh_authorized_keys: []\n"
+ }`),
+
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"libvirt_cloudinit.test", "name", "commoninit.iso"),
resource.TestCheckResourceAttr(
- "libvirt_cloudinit.test", "local_hostname", "tango"),
+ "libvirt_cloudinit.test", "local_hostname", "tango1"),
+ ),
+ },
+ // 2nd tests Invalid userdata
+ {
+ Config: fmt.Sprintf(`
+ resource "libvirt_cloudinit" "test" {
+ name = "commoninit2.iso"
+ local_hostname = "samba2"
+ pool = "default"
+ user_data = "invalidgino"
+ }`),
+ ExpectError: regexp.MustCompile("Error merging UserData with UserDataRaw: yaml: unmarshal errors"),
+ },
+ // 3nd test explicetely don'tuse user_data
+ {
+ Config: fmt.Sprintf(`
+ resource "libvirt_cloudinit" "test3" {
+ name = "commoninit3.iso"
+ local_hostname = "nouserdata"
+ pool = "default"
+ }`),
+
+ Check: resource.ComposeTestCheckFunc(
+ resource.TestCheckResourceAttr(
+ "libvirt_cloudinit.test3", "name", "commoninit3.iso"),
+ resource.TestCheckResourceAttr(
+ "libvirt_cloudinit.test3", "local_hostname", "nouserdata"),
),
},
},
diff --git a/travis/setup-guest b/travis/setup-guest
index 71562655..42568e81 100755
--- a/travis/setup-guest
+++ b/travis/setup-guest
@@ -14,7 +14,7 @@ done
add-apt-repository -y ppa:gophers/archive
apt-get -qq update
-apt-get install -y qemu libvirt-bin libvirt-dev golang-1.9 ovmf
+apt-get install -y qemu libvirt-bin libvirt-dev golang-1.9 ovmf genisoimage
echo -e "<pool type='dir'>\n<name>default</name>\n<target>\n<path>/pool-default</path>\n</target>\n</pool>" > pool.xml
mkdir /pool-default
chmod a+rwx /pool-default