github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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  		resource "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  		resource "ignition_config" "test" {
    25  			systemd = [
    26  				"${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  		resource "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  		resource "ignition_config" "test" {
    71  			systemd = [
    72  				"${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  }