github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ignition/resource_ignition_systemd_unit_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 TestIngnitionSystemdUnit(t *testing.T) { 11 testIgnition(t, ` 12 data "ignition_systemd_unit" "foo" { 13 name = "foo.service" 14 content = "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n" 15 enable = false 16 mask = true 17 18 dropin { 19 name = "foo.conf" 20 content = "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n" 21 } 22 } 23 24 data "ignition_config" "test" { 25 systemd = [ 26 "${data.ignition_systemd_unit.foo.id}", 27 ] 28 } 29 `, func(c *types.Config) error { 30 if len(c.Systemd.Units) != 1 { 31 return fmt.Errorf("systemd, found %d", len(c.Systemd.Units)) 32 } 33 34 u := c.Systemd.Units[0] 35 36 if u.Name != "foo.service" { 37 return fmt.Errorf("name, found %q", u.Name) 38 } 39 40 if u.Contents != "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n" { 41 return fmt.Errorf("content, found %q", u.Contents) 42 } 43 44 if u.Mask != true { 45 return fmt.Errorf("mask, found %t", u.Mask) 46 } 47 48 if u.Enable != false { 49 return fmt.Errorf("enable, found %t", u.Enable) 50 } 51 52 if len(u.DropIns) != 1 { 53 return fmt.Errorf("dropins, found %q", u.DropIns) 54 } 55 56 return nil 57 }) 58 } 59 60 func TestIngnitionSystemdUnitEmptyContentWithDropIn(t *testing.T) { 61 testIgnition(t, ` 62 data "ignition_systemd_unit" "foo" { 63 name = "foo.service" 64 dropin { 65 name = "foo.conf" 66 content = "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n" 67 } 68 } 69 70 data "ignition_config" "test" { 71 systemd = [ 72 "${data.ignition_systemd_unit.foo.id}", 73 ] 74 } 75 `, func(c *types.Config) error { 76 if len(c.Systemd.Units) != 1 { 77 return fmt.Errorf("systemd, found %d", len(c.Systemd.Units)) 78 } 79 80 u := c.Systemd.Units[0] 81 82 if u.Name != "foo.service" { 83 return fmt.Errorf("name, found %q", u.Name) 84 } 85 86 if u.Contents != "" { 87 return fmt.Errorf("content, found %q", u.Contents) 88 } 89 90 if len(u.DropIns) != 1 { 91 return fmt.Errorf("dropins, found %q", u.DropIns) 92 } 93 94 return nil 95 }) 96 } 97 98 // #11325 99 func TestIgnitionSystemdUnit_emptyContent(t *testing.T) { 100 testIgnition(t, ` 101 data "ignition_systemd_unit" "foo" { 102 name = "foo.service" 103 enable = true 104 } 105 106 data "ignition_config" "test" { 107 systemd = [ 108 "${data.ignition_systemd_unit.foo.id}", 109 ] 110 } 111 `, func(c *types.Config) error { 112 if len(c.Systemd.Units) != 1 { 113 return fmt.Errorf("systemd, found %d", len(c.Systemd.Units)) 114 } 115 116 u := c.Systemd.Units[0] 117 if u.Name != "foo.service" { 118 return fmt.Errorf("name, expected 'foo.service', found %q", u.Name) 119 } 120 if u.Contents != "" { 121 return fmt.Errorf("expected empty content, found %q", u.Contents) 122 } 123 if len(u.DropIns) != 0 { 124 return fmt.Errorf("expected 0 dropins, found %q", u.DropIns) 125 } 126 return nil 127 }) 128 }