diff options
author | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-14 21:20:54 +0100 |
---|---|---|
committer | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-16 16:33:14 +0100 |
commit | 4ae842bbeb3b9d72659d4c78f6bf1c75a7881965 (patch) | |
tree | 270f63c34e3731dd8e64dde8d02bfb26a6070f31 /libvirt | |
parent | 9d3bfb5aaf0b51695a2dae54ede7845660d8eb70 (diff) | |
download | terraform-provider-libvirt-4ae842bbeb3b9d72659d4c78f6bf1c75a7881965.tar terraform-provider-libvirt-4ae842bbeb3b9d72659d4c78f6bf1c75a7881965.tar.gz |
add geniso to travis_guest
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/cloudinit_def_test.go | 62 |
1 files changed, 47 insertions, 15 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"), ), }, }, |