github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ignition/resource_ignition_filesystem_test.go (about)

     1  package ignition
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"testing"
     7  
     8  	"github.com/coreos/ignition/config/types"
     9  )
    10  
    11  func TestIngnitionFilesystem(t *testing.T) {
    12  	testIgnition(t, `
    13  		data "ignition_filesystem" "foo" {
    14  			name = "foo"
    15  			path = "/foo"
    16  		}
    17  
    18  		data "ignition_filesystem" "qux" {
    19  			name = "qux"
    20  			mount {
    21  				device = "/qux"
    22  				format = "ext4"
    23  			}
    24  		}
    25  
    26  		data "ignition_filesystem" "baz" {
    27  			name = "baz"
    28  			mount {
    29  				device = "/baz"
    30  				format = "ext4"
    31  				create = true
    32  			}
    33  		}
    34  
    35  		data "ignition_filesystem" "bar" {
    36  			name = "bar"
    37  			mount {
    38  				device = "/bar"
    39  				format = "ext4"
    40  				create = true
    41  				force = true
    42  				options = ["rw"]
    43  			}
    44  		}
    45  
    46  		data "ignition_config" "test" {
    47  			filesystems = [
    48  				"${data.ignition_filesystem.foo.id}",
    49  				"${data.ignition_filesystem.qux.id}",
    50  				"${data.ignition_filesystem.baz.id}",
    51  				"${data.ignition_filesystem.bar.id}",
    52  			]
    53  		}
    54  	`, func(c *types.Config) error {
    55  		if len(c.Storage.Filesystems) != 4 {
    56  			return fmt.Errorf("disks, found %d", len(c.Storage.Filesystems))
    57  		}
    58  
    59  		f := c.Storage.Filesystems[0]
    60  		if f.Name != "foo" {
    61  			return fmt.Errorf("name, found %q", f.Name)
    62  		}
    63  
    64  		if f.Mount != nil {
    65  			return fmt.Errorf("mount, found %q", f.Mount.Device)
    66  		}
    67  
    68  		if string(*f.Path) != "/foo" {
    69  			return fmt.Errorf("path, found %q", f.Path)
    70  		}
    71  
    72  		f = c.Storage.Filesystems[1]
    73  		if f.Name != "qux" {
    74  			return fmt.Errorf("name, found %q", f.Name)
    75  		}
    76  
    77  		if f.Mount.Device != "/qux" {
    78  			return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
    79  		}
    80  
    81  		if f.Mount.Format != "ext4" {
    82  			return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
    83  		}
    84  
    85  		if f.Mount.Create != nil {
    86  			return fmt.Errorf("mount, create was found %#v", f.Mount.Create)
    87  		}
    88  
    89  		f = c.Storage.Filesystems[2]
    90  		if f.Name != "baz" {
    91  			return fmt.Errorf("name, found %q", f.Name)
    92  		}
    93  
    94  		if f.Mount.Device != "/baz" {
    95  			return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
    96  		}
    97  
    98  		if f.Mount.Format != "ext4" {
    99  			return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
   100  		}
   101  
   102  		if f.Mount.Create.Force != false {
   103  			return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
   104  		}
   105  
   106  		f = c.Storage.Filesystems[3]
   107  		if f.Name != "bar" {
   108  			return fmt.Errorf("name, found %q", f.Name)
   109  		}
   110  
   111  		if f.Mount.Device != "/bar" {
   112  			return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
   113  		}
   114  
   115  		if f.Mount.Format != "ext4" {
   116  			return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
   117  		}
   118  
   119  		if f.Mount.Create.Force != true {
   120  			return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
   121  		}
   122  
   123  		if len(f.Mount.Create.Options) != 1 || f.Mount.Create.Options[0] != "rw" {
   124  			return fmt.Errorf("mount.0.options, found %q", f.Mount.Create.Options)
   125  		}
   126  
   127  		return nil
   128  	})
   129  }
   130  
   131  func TestIngnitionFilesystemMissingCreate(t *testing.T) {
   132  	testIgnitionError(t, `
   133  		data "ignition_filesystem" "bar" {
   134  			name = "bar"
   135  			mount {
   136  				device = "/bar"
   137  				format = "ext4"
   138  				force = true
   139  			}
   140  		}
   141  
   142  		data "ignition_config" "test" {
   143  			filesystems = [
   144  				"${data.ignition_filesystem.bar.id}",
   145  			]
   146  		}
   147  	`, regexp.MustCompile("create should be true when force or options is used"))
   148  }