github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/ignition/resource_ignition_disk_test.go (about)

     1  package ignition
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/coreos/ignition/config/types"
     8  )
     9  
    10  func TestIngnitionDisk(t *testing.T) {
    11  	testIgnition(t, `
    12  		data "ignition_disk" "foo" {
    13  			device = "/foo"
    14  			partition {
    15  				label = "qux"
    16  				size = 42
    17  				start = 2048
    18  				type_guid = "01234567-89AB-CDEF-EDCB-A98765432101"
    19  			}
    20  		}
    21  
    22  		data "ignition_config" "test" {
    23  			disks = [
    24  				"${data.ignition_disk.foo.id}",
    25  			]
    26  		}
    27  	`, func(c *types.Config) error {
    28  		if len(c.Storage.Disks) != 1 {
    29  			return fmt.Errorf("disks, found %d", len(c.Storage.Disks))
    30  		}
    31  
    32  		d := c.Storage.Disks[0]
    33  		if d.Device != "/foo" {
    34  			return fmt.Errorf("name, found %q", d.Device)
    35  		}
    36  
    37  		if len(d.Partitions) != 1 {
    38  			return fmt.Errorf("parition, found %d", len(d.Partitions))
    39  		}
    40  
    41  		p := d.Partitions[0]
    42  		if p.Label != "qux" {
    43  			return fmt.Errorf("parition.0.label, found %q", p.Label)
    44  		}
    45  
    46  		if p.Size != 42 {
    47  			return fmt.Errorf("parition.0.size, found %q", p.Size)
    48  		}
    49  
    50  		if p.Start != 2048 {
    51  			return fmt.Errorf("parition.0.start, found %q", p.Start)
    52  		}
    53  
    54  		if p.TypeGUID != "01234567-89AB-CDEF-EDCB-A98765432101" {
    55  			return fmt.Errorf("parition.0.type_guid, found %q", p.TypeGUID)
    56  		}
    57  
    58  		return nil
    59  	})
    60  }
    61  
    62  func TestIngnitionDiskResource(t *testing.T) {
    63  	testIgnition(t, `
    64  		resource "ignition_disk" "foo" {
    65  			device = "/foo"
    66  			partition {
    67  				label = "qux"
    68  			}
    69  		}
    70  
    71  		data "ignition_config" "test" {
    72  			disks = [
    73  				"${ignition_disk.foo.id}",
    74  			]
    75  		}
    76  	`, func(c *types.Config) error {
    77  		if len(c.Storage.Disks) != 1 {
    78  			return fmt.Errorf("disks, found %d", len(c.Storage.Disks))
    79  		}
    80  
    81  		return nil
    82  	})
    83  }