diff options
author | Thomas Hipp <thipp@suse.de> | 2017-11-27 16:52:07 +0100 |
---|---|---|
committer | Thomas Hipp <thipp@suse.de> | 2017-11-27 16:52:07 +0100 |
commit | c18ea2d3772fc16f7d4479d59a69becd3e81cba4 (patch) | |
tree | 4e607290bc9e5e57669a97b0060268f9db6bc64b /libvirt | |
parent | c7cc7221d46e8fa7ee7d64c7eab64f5515980fc1 (diff) | |
download | terraform-provider-libvirt-c18ea2d3772fc16f7d4479d59a69becd3e81cba4.tar terraform-provider-libvirt-c18ea2d3772fc16f7d4479d59a69becd3e81cba4.tar.gz |
tests: format hcl strings
Signed-off-by: Thomas Hipp <thipp@suse.de>
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/cloudinit_def_test.go | 33 | ||||
-rw-r--r-- | libvirt/resource_libvirt_coreos_ignition_test.go | 30 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 380 | ||||
-rw-r--r-- | libvirt/resource_libvirt_network_test.go | 31 | ||||
-rw-r--r-- | libvirt/resource_libvirt_volume_test.go | 26 |
5 files changed, 251 insertions, 249 deletions
diff --git a/libvirt/cloudinit_def_test.go b/libvirt/cloudinit_def_test.go index c2202a75..4f8091dc 100644 --- a/libvirt/cloudinit_def_test.go +++ b/libvirt/cloudinit_def_test.go @@ -2,15 +2,16 @@ package libvirt import ( "fmt" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" - libvirt "github.com/libvirt/libvirt-go" - "gopkg.in/yaml.v2" "os" "path/filepath" "regexp" "strings" "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + libvirt "github.com/libvirt/libvirt-go" + "gopkg.in/yaml.v2" ) func TestNewCloudInitDef(t *testing.T) { @@ -176,12 +177,12 @@ func TestCreateCloudIsoViaPlugin(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` - resource "libvirt_cloudinit" "test" { - name = "test.iso" - local_hostname = "tango1" - pool = "default" - user_data = "#cloud-config\nssh_authorized_keys: []\n" - }`), + resource "libvirt_cloudinit" "test" { + name = "test.iso" + local_hostname = "tango1" + pool = "default" + user_data = "#cloud-config\nssh_authorized_keys: []\n" + }`), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -194,12 +195,12 @@ func TestCreateCloudIsoViaPlugin(t *testing.T) { // 2nd tests Invalid userdata { Config: fmt.Sprintf(` - resource "libvirt_cloudinit" "test" { - name = "commoninit2.iso" - local_hostname = "samba2" - pool = "default" - user_data = "invalidgino" - }`), + 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"), }, }, diff --git a/libvirt/resource_libvirt_coreos_ignition_test.go b/libvirt/resource_libvirt_coreos_ignition_test.go index 027cbd3a..9330c3ea 100644 --- a/libvirt/resource_libvirt_coreos_ignition_test.go +++ b/libvirt/resource_libvirt_coreos_ignition_test.go @@ -12,21 +12,21 @@ import ( func TestAccLibvirtIgnition_Basic(t *testing.T) { var volume libvirt.StorageVol var config = fmt.Sprintf(` - data "ignition_systemd_unit" "acceptance-test-systemd" { - name = "example.service" - content = "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" - } - - data "ignition_config" "acceptance-test-config" { - systemd = [ - "${data.ignition_systemd_unit.acceptance-test-systemd.id}", - ] - } - - resource "libvirt_ignition" "ignition" { - name = "ignition" - content = "${data.ignition_config.acceptance-test-config.rendered}" - } + data "ignition_systemd_unit" "acceptance-test-systemd" { + name = "example.service" + content = "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" + } + + data "ignition_config" "acceptance-test-config" { + systemd = [ + "${data.ignition_systemd_unit.acceptance-test-systemd.id}", + ] + } + + resource "libvirt_ignition" "ignition" { + name = "ignition" + content = "${data.ignition_config.acceptance-test-config.rendered}" + } `) resource.Test(t, resource.TestCase{ diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 055c67c4..47c99ef5 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -17,9 +17,9 @@ import ( func TestAccLibvirtDomain_Basic(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain-1" { - name = "terraform-test" - }`) + resource "libvirt_domain" "acceptance-test-domain-1" { + name = "terraform-test" + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -45,11 +45,11 @@ func TestAccLibvirtDomain_Basic(t *testing.T) { func TestAccLibvirtDomain_Detailed(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain-2" { - name = "terraform-test" - memory = 384 - vcpu = 2 - }`) + resource "libvirt_domain" "acceptance-test-domain-2" { + name = "terraform-test" + memory = 384 + vcpu = 2 + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -77,21 +77,21 @@ func TestAccLibvirtDomain_Volume(t *testing.T) { var volume libvirt.StorageVol var configVolAttached = fmt.Sprintf(` - resource "libvirt_volume" "acceptance-test-volume" { - name = "terraform-test" - } + resource "libvirt_volume" "acceptance-test-volume" { + name = "terraform-test" + } - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - disk { - volume_id = "${libvirt_volume.acceptance-test-volume.id}" - } - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + disk { + volume_id = "${libvirt_volume.acceptance-test-volume.id}" + } + }`) var configVolDettached = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -121,29 +121,29 @@ func TestAccLibvirtDomain_VolumeTwoDisks(t *testing.T) { var volume libvirt.StorageVol var configVolAttached = fmt.Sprintf(` - resource "libvirt_volume" "acceptance-test-volume1" { - name = "terraform-test-vol1" - } + resource "libvirt_volume" "acceptance-test-volume1" { + name = "terraform-test-vol1" + } - resource "libvirt_volume" "acceptance-test-volume2" { - name = "terraform-test-vol2" - } + resource "libvirt_volume" "acceptance-test-volume2" { + name = "terraform-test-vol2" + } - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" - disk { - volume_id = "${libvirt_volume.acceptance-test-volume1.id}" - } + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + disk { + volume_id = "${libvirt_volume.acceptance-test-volume1.id}" + } - disk { - volume_id = "${libvirt_volume.acceptance-test-volume2.id}" - } - }`) + disk { + volume_id = "${libvirt_volume.acceptance-test-volume2.id}" + } + }`) var configVolDettached = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -173,18 +173,18 @@ func TestAccLibvirtDomain_VolumeTwoDisks(t *testing.T) { func TestAccLibvirtDomain_ScsiDisk(t *testing.T) { var domain libvirt.Domain var configScsi = fmt.Sprintf(` - resource "libvirt_volume" "acceptance-test-volume1" { - name = "terraform-test-vol1" - } - - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" - disk { - volume_id = "${libvirt_volume.acceptance-test-volume1.id}" - scsi = "yes" - wwn = "000000123456789a" - } - }`) + resource "libvirt_volume" "acceptance-test-volume1" { + name = "terraform-test-vol1" + } + + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + disk { + volume_id = "${libvirt_volume.acceptance-test-volume1.id}" + scsi = "yes" + wwn = "000000123456789a" + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -211,12 +211,12 @@ func TestAccLibvirtDomainURLDisk(t *testing.T) { } var configURL = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" - disk { - url = "%s" - } - }`, u.String()) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + disk { + url = "%s" + } + }`, u.String()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -241,32 +241,32 @@ func TestAccLibvirtDomainKernelInitrdCmdline(t *testing.T) { var initrd libvirt.StorageVol var config = fmt.Sprintf(` - resource "libvirt_volume" "kernel" { - source = "testdata/tetris.elf" - name = "kernel" - pool = "default" - format = "raw" - } - - resource "libvirt_volume" "initrd" { - source = "testdata/initrd.img" - name = "initrd" - pool = "default" - format = "raw" - } - - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" - kernel = "${libvirt_volume.kernel.id}" - initrd = "${libvirt_volume.initrd.id}" - cmdline { - foo = 1 - bar = "bye" - } - cmdline { - foo = 2 - } - }`) + resource "libvirt_volume" "kernel" { + source = "testdata/tetris.elf" + name = "kernel" + pool = "default" + format = "raw" + } + + resource "libvirt_volume" "initrd" { + source = "testdata/initrd.img" + name = "initrd" + pool = "default" + format = "raw" + } + + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + kernel = "${libvirt_volume.kernel.id}" + initrd = "${libvirt_volume.initrd.id}" + cmdline { + foo = 1 + bar = "bye" + } + cmdline { + foo = 2 + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -291,23 +291,23 @@ func TestAccLibvirtDomain_NetworkInterface(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_volume" "acceptance-test-volume" { - name = "terraform-test" - } - - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - network_interface = { - network_name = "default" - } - network_interface = { - network_name = "default" - mac = "52:54:00:A9:F5:17" - } - disk { - volume_id = "${libvirt_volume.acceptance-test-volume.id}" - } - }`) + resource "libvirt_volume" "acceptance-test-volume" { + name = "terraform-test" + } + + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + network_interface = { + network_name = "default" + } + network_interface = { + network_name = "default" + mac = "52:54:00:A9:F5:17" + } + disk { + volume_id = "${libvirt_volume.acceptance-test-volume.id}" + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -332,18 +332,18 @@ func TestAccLibvirtDomain_Graphics(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_volume" "acceptance-test-graphics" { - name = "terraform-test" - } - - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - graphics { - type = "spice" - autoport = "yes" - listen_type = "none" - } - }`) + resource "libvirt_volume" "acceptance-test-graphics" { + name = "terraform-test" + } + + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + graphics { + type = "spice" + autoport = "yes" + listen_type = "none" + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -371,26 +371,26 @@ func TestAccLibvirtDomain_IgnitionObject(t *testing.T) { var volume libvirt.StorageVol var config = fmt.Sprintf(` - data "ignition_systemd_unit" "acceptance-test-systemd" { - name = "example.service" - content = "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" - } - - data "ignition_config" "acceptance-test-config" { - systemd = [ - "${data.ignition_systemd_unit.acceptance-test-systemd.id}", - ] - } - - resource "libvirt_ignition" "ignition" { - name = "ignition" - content = "${data.ignition_config.acceptance-test-config.rendered}" - } - - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-domain" + data "ignition_systemd_unit" "acceptance-test-systemd" { + name = "example.service" + content = "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" + } + + data "ignition_config" "acceptance-test-config" { + systemd = [ + "${data.ignition_systemd_unit.acceptance-test-systemd.id}", + ] + } + + resource "libvirt_ignition" "ignition" { + name = "ignition" + content = "${data.ignition_config.acceptance-test-config.rendered}" + } + + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" coreos_ignition = "${libvirt_ignition.ignition.id}" - } + } `) resource.Test(t, resource.TestCase{ @@ -414,12 +414,12 @@ func TestAccLibvirtDomain_Cpu(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - cpu { - mode = "custom" - } - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + cpu { + mode = "custom" + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -442,10 +442,10 @@ func TestAccLibvirtDomain_Autostart(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - autostart = true - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + autostart = true + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -466,19 +466,19 @@ func TestAccLibvirtDomain_Filesystems(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - filesystem { - source = "/tmp" - target = "tmp" - readonly = false - } - filesystem { - source = "/proc" - target = "proc" - readonly = true - } - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + filesystem { + source = "/tmp" + target = "tmp" + readonly = false + } + filesystem { + source = "/proc" + target = "proc" + readonly = true + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -511,20 +511,20 @@ func TestAccLibvirtDomain_Consoles(t *testing.T) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - console { - type = "pty" - target_port = "0" - source_path = "/dev/pts/1" - } - console { - type = "pty" - target_port = "0" - target_type = "virtio" - source_path = "/dev/pts/2" - } - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + console { + type = "pty" + target_port = "0" + source_path = "/dev/pts/1" + } + console { + type = "pty" + target_port = "0" + target_type = "virtio" + source_path = "/dev/pts/2" + } + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -796,13 +796,13 @@ func TestAccLibvirtDomainFirmware(t *testing.T) { func subtestAccLibvirtDomainFirmwareNoTemplate(t *testing.T, NVRAMPath string, firmware string) { var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-firmware-no-template" - firmware = "%s" - nvram { - file = "%s" - } - }`, firmware, NVRAMPath) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-firmware-no-template" + firmware = "%s" + nvram { + file = "%s" + } + }`, firmware, NVRAMPath) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -833,14 +833,14 @@ func subtestAccLibvirtDomainFirmwareTemplate(t *testing.T, NVRAMPath string, fir var domain libvirt.Domain var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test-firmware-with-template" - firmware = "%s" - nvram { - file = "%s" - template = "%s" - } - }`, firmware, NVRAMPath, template) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-firmware-with-template" + firmware = "%s" + nvram { + file = "%s" + template = "%s" + } + }`, firmware, NVRAMPath, template) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -871,10 +871,10 @@ func TestAccLibvirtDomain_MachineType(t *testing.T) { // Using machine type of pc as this is earliest QEMU target // and so most likely to be available var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - machine = "pc" - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + machine = "pc" + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -896,10 +896,10 @@ func TestAccLibvirtDomain_ArchType(t *testing.T) { // Using i686 as architecture in case anyone running tests on an i686 only host var config = fmt.Sprintf(` - resource "libvirt_domain" "acceptance-test-domain" { - name = "terraform-test" - arch = "i686" - }`) + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + arch = "i686" + }`) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/libvirt/resource_libvirt_network_test.go b/libvirt/resource_libvirt_network_test.go index cedcc507..f3c0d211 100644 --- a/libvirt/resource_libvirt_network_test.go +++ b/libvirt/resource_libvirt_network_test.go @@ -2,10 +2,11 @@ package libvirt import ( "fmt" + "testing" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/libvirt/libvirt-go" - "testing" ) func TestNetworkAutostart(t *testing.T) { @@ -17,13 +18,13 @@ func TestNetworkAutostart(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` - resource "libvirt_network" "test_net" { - name = "networktest" - mode = "nat" - domain = "k8s.local" - addresses = ["10.17.3.0/24"] - autostart = true - }`), + resource "libvirt_network" "test_net" { + name = "networktest" + mode = "nat" + domain = "k8s.local" + addresses = ["10.17.3.0/24"] + autostart = true + }`), Check: resource.ComposeTestCheckFunc( networkExists("libvirt_network.test_net", &network), resource.TestCheckResourceAttr("libvirt_network.test_net", "autostart", "true"), @@ -31,13 +32,13 @@ func TestNetworkAutostart(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "libvirt_network" "test_net" { - name = "networktest" - mode = "nat" - domain = "k8s.local" - addresses = ["10.17.3.0/24"] - autostart = false - }`), + resource "libvirt_network" "test_net" { + name = "networktest" + mode = "nat" + domain = "k8s.local" + addresses = ["10.17.3.0/24"] + autostart = false + }`), Check: resource.ComposeTestCheckFunc( networkExists("libvirt_network.test_net", &network), resource.TestCheckResourceAttr("libvirt_network.test_net", "autostart", "false"), diff --git a/libvirt/resource_libvirt_volume_test.go b/libvirt/resource_libvirt_volume_test.go index 277b2990..d185b65e 100644 --- a/libvirt/resource_libvirt_volume_test.go +++ b/libvirt/resource_libvirt_volume_test.go @@ -85,10 +85,10 @@ func TestAccLibvirtVolume_Basic(t *testing.T) { var volume libvirt.StorageVol const testAccCheckLibvirtVolumeConfigBasic = ` - resource "libvirt_volume" "terraform-acceptance-test-1" { - name = "terraform-test" - size = 1073741824 - }` + resource "libvirt_volume" "terraform-acceptance-test-1" { + name = "terraform-test" + size = 1073741824 + }` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -125,10 +125,10 @@ func TestAccLibvirtVolume_DownloadFromSource(t *testing.T) { } const testAccCheckLibvirtVolumeConfigSource = ` - resource "libvirt_volume" "terraform-acceptance-test-2" { - name = "terraform-test" - source = "%s" - }` + resource "libvirt_volume" "terraform-acceptance-test-2" { + name = "terraform-test" + source = "%s" + }` config := fmt.Sprintf(testAccCheckLibvirtVolumeConfigSource, url) resource.Test(t, resource.TestCase{ @@ -152,11 +152,11 @@ func TestAccLibvirtVolume_Format(t *testing.T) { var volume libvirt.StorageVol const testAccCheckLibvirtVolumeConfigFormat = ` - resource "libvirt_volume" "terraform-acceptance-test-3" { - name = "terraform-test" - format = "raw" - size = 1073741824 - }` + resource "libvirt_volume" "terraform-acceptance-test-3" { + name = "terraform-test" + format = "raw" + size = 1073741824 + }` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, |