2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIngnitionSystemdUnit(t *testing.T) {
|
|
|
|
testIgnition(t, `
|
|
|
|
resource "ignition_systemd_unit" "foo" {
|
|
|
|
name = "foo.service"
|
|
|
|
content = "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n"
|
|
|
|
enable = false
|
|
|
|
mask = true
|
|
|
|
|
|
|
|
dropin {
|
|
|
|
name = "foo.conf"
|
|
|
|
content = "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "ignition_config" "test" {
|
|
|
|
systemd = [
|
|
|
|
"${ignition_systemd_unit.foo.id}",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`, func(c *types.Config) error {
|
|
|
|
if len(c.Systemd.Units) != 1 {
|
|
|
|
return fmt.Errorf("systemd, found %d", len(c.Systemd.Units))
|
|
|
|
}
|
|
|
|
|
|
|
|
u := c.Systemd.Units[0]
|
|
|
|
|
|
|
|
if u.Name != "foo.service" {
|
|
|
|
return fmt.Errorf("name, found %q", u.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.Contents != "[Match]\nName=eth0\n\n[Network]\nAddress=10.0.1.7\n" {
|
|
|
|
return fmt.Errorf("content, found %q", u.Contents)
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.Mask != true {
|
2017-01-13 23:31:44 +01:00
|
|
|
return fmt.Errorf("mask, found %t", u.Mask)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Enable != false {
|
2017-01-13 23:31:44 +01:00
|
|
|
return fmt.Errorf("enable, found %t", u.Enable)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(u.DropIns) != 1 {
|
|
|
|
return fmt.Errorf("dropins, found %q", u.DropIns)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|