github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/ignition/resource_ignition_user_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 TestIngnitionUser(t *testing.T) { 11 testIgnition(t, ` 12 resource "ignition_user" "foo" { 13 name = "foo" 14 password_hash = "password" 15 ssh_authorized_keys = ["keys"] 16 uid = 42 17 gecos = "gecos" 18 home_dir = "home" 19 no_create_home = true 20 primary_group = "primary_group" 21 groups = ["group"] 22 no_user_group = true 23 no_log_init = true 24 shell = "shell" 25 } 26 27 resource "ignition_user" "qux" { 28 name = "qux" 29 } 30 31 resource "ignition_config" "test" { 32 users = [ 33 "${ignition_user.foo.id}", 34 "${ignition_user.qux.id}", 35 ] 36 } 37 `, func(c *types.Config) error { 38 if len(c.Passwd.Users) != 2 { 39 return fmt.Errorf("users, found %d", len(c.Passwd.Users)) 40 } 41 42 u := c.Passwd.Users[0] 43 44 if u.Name != "foo" { 45 return fmt.Errorf("name, found %q", u.Name) 46 } 47 48 if u.PasswordHash != "password" { 49 return fmt.Errorf("password_hash, found %q", u.PasswordHash) 50 } 51 52 if len(u.SSHAuthorizedKeys) != 1 || u.SSHAuthorizedKeys[0] != "keys" { 53 return fmt.Errorf("ssh_authorized_keys, found %q", u.SSHAuthorizedKeys) 54 } 55 56 if *u.Create.Uid != uint(42) { 57 return fmt.Errorf("uid, found %q", *u.Create.Uid) 58 } 59 60 if u.Create.GECOS != "gecos" { 61 return fmt.Errorf("gecos, found %q", u.Create.GECOS) 62 } 63 64 if u.Create.Homedir != "home" { 65 return fmt.Errorf("home_dir, found %q", u.Create.Homedir) 66 } 67 68 if u.Create.NoCreateHome != true { 69 return fmt.Errorf("no_create_home, found %t", u.Create.NoCreateHome) 70 } 71 72 if u.Create.PrimaryGroup != "primary_group" { 73 return fmt.Errorf("primary_group, found %q", u.Create.PrimaryGroup) 74 } 75 76 if len(u.Create.Groups) != 1 || u.Create.Groups[0] != "group" { 77 return fmt.Errorf("groups, found %q", u.Create.Groups) 78 } 79 80 if u.Create.NoUserGroup != true { 81 return fmt.Errorf("no_create_home, found %t", u.Create.NoCreateHome) 82 } 83 84 if u.Create.NoLogInit != true { 85 return fmt.Errorf("no_log_init, found %t", u.Create.NoLogInit) 86 } 87 88 if u.Create.Shell != "shell" { 89 return fmt.Errorf("shell, found %q", u.Create.Shell) 90 } 91 92 u = c.Passwd.Users[1] 93 94 if u.Name != "qux" { 95 return fmt.Errorf("name, found %q", u.Name) 96 } 97 98 if u.Create.Uid != nil { 99 return fmt.Errorf("uid, found %d", *u.Create.Uid) 100 } 101 102 return nil 103 }) 104 }