2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIngnitionGroup(t *testing.T) {
|
|
|
|
testIgnition(t, `
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_group" "foo" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "foo"
|
|
|
|
password_hash = "password"
|
|
|
|
gid = 42
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_group" "qux" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "qux"
|
2017-03-06 13:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data "ignition_config" "test" {
|
2017-01-03 12:29:14 +01:00
|
|
|
groups = [
|
2017-03-06 13:23:04 +01:00
|
|
|
"${data.ignition_group.foo.id}",
|
|
|
|
"${data.ignition_group.qux.id}",
|
2017-01-03 12:29:14 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
`, func(c *types.Config) error {
|
|
|
|
if len(c.Passwd.Groups) != 2 {
|
|
|
|
return fmt.Errorf("groups, found %d", len(c.Passwd.Groups))
|
|
|
|
}
|
|
|
|
|
|
|
|
g := c.Passwd.Groups[0]
|
|
|
|
|
|
|
|
if g.Name != "foo" {
|
|
|
|
return fmt.Errorf("name, found %q", g.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.PasswordHash != "password" {
|
|
|
|
return fmt.Errorf("password_hash, found %q", g.PasswordHash)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.Gid == nil || *g.Gid != uint(42) {
|
|
|
|
return fmt.Errorf("gid, found %q", *g.Gid)
|
|
|
|
}
|
|
|
|
|
|
|
|
g = c.Passwd.Groups[1]
|
|
|
|
|
|
|
|
if g.Name != "qux" {
|
|
|
|
return fmt.Errorf("name, found %q", g.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.Gid != nil {
|
|
|
|
return fmt.Errorf("uid, found %d", *g.Gid)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|