github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/ignition/resource_ignition_filesystem_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 TestIngnitionFilesystem(t *testing.T) {
    11  	testIgnition(t, `
    12  		data "ignition_filesystem" "foo" {
    13  			name = "foo"
    14  			path = "/foo"
    15  		}
    16  
    17  		data "ignition_filesystem" "qux" {
    18  			name = "qux"
    19  			mount {
    20  				device = "/qux"
    21  				format = "ext4"
    22  			}
    23  		}
    24  
    25  		data "ignition_filesystem" "bar" {
    26  			name = "bar"
    27  			mount {
    28  				device = "/bar"
    29  				format = "ext4"
    30  				force = true
    31  				options = ["rw"]
    32  			}
    33  		}
    34  
    35  		data "ignition_config" "test" {
    36  			filesystems = [
    37  				"${data.ignition_filesystem.foo.id}",
    38  				"${data.ignition_filesystem.qux.id}",
    39  				"${data.ignition_filesystem.bar.id}",
    40  			]
    41  		}
    42  	`, func(c *types.Config) error {
    43  		if len(c.Storage.Filesystems) != 3 {
    44  			return fmt.Errorf("disks, found %d", len(c.Storage.Filesystems))
    45  		}
    46  
    47  		f := c.Storage.Filesystems[0]
    48  		if f.Name != "foo" {
    49  			return fmt.Errorf("name, found %q", f.Name)
    50  		}
    51  
    52  		if f.Mount != nil {
    53  			return fmt.Errorf("mount, found %q", f.Mount.Device)
    54  		}
    55  
    56  		if string(*f.Path) != "/foo" {
    57  			return fmt.Errorf("path, found %q", f.Path)
    58  		}
    59  
    60  		f = c.Storage.Filesystems[1]
    61  		if f.Name != "qux" {
    62  			return fmt.Errorf("name, found %q", f.Name)
    63  		}
    64  
    65  		if f.Mount.Device != "/qux" {
    66  			return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
    67  		}
    68  
    69  		if f.Mount.Format != "ext4" {
    70  			return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
    71  		}
    72  
    73  		if f.Mount.Create != nil {
    74  			return fmt.Errorf("mount, create was found %#v", f.Mount.Create)
    75  		}
    76  
    77  		f = c.Storage.Filesystems[2]
    78  		if f.Name != "bar" {
    79  			return fmt.Errorf("name, found %q", f.Name)
    80  		}
    81  
    82  		if f.Mount.Device != "/bar" {
    83  			return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
    84  		}
    85  
    86  		if f.Mount.Format != "ext4" {
    87  			return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
    88  		}
    89  
    90  		if f.Mount.Create.Force != true {
    91  			return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
    92  		}
    93  
    94  		if len(f.Mount.Create.Options) != 1 || f.Mount.Create.Options[0] != "rw" {
    95  			return fmt.Errorf("mount.0.options, found %q", f.Mount.Create.Options)
    96  		}
    97  
    98  		return nil
    99  	})
   100  }