github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/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  		data "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  		data "ignition_user" "qux" {
    28  			name = "qux"
    29  		}
    30  
    31  		data "ignition_config" "test" {
    32  			users = [
    33  				"${data.ignition_user.foo.id}",
    34  				"${data.ignition_user.qux.id}",
    35  			]
    36  		}
    37  	`, func(c *types.Config) error {
    38  		if len(c.Passwd.Users) != 2 {
    39  			return fmt.Errorf("Lenght of field Users didn't match. Expected: %d, Given: %d", 2, len(c.Passwd.Users))
    40  		}
    41  
    42  		u := c.Passwd.Users[0]
    43  
    44  		if u.Name != "foo" {
    45  			return fmt.Errorf("Field Name didn't match. Expected: %s, Given: %s", "foo", u.Name)
    46  		}
    47  
    48  		if u.PasswordHash != "password" {
    49  			return fmt.Errorf("Field PasswordHash didn't match. Expected: %s, Given: %s", "password", u.PasswordHash)
    50  		}
    51  
    52  		if len(u.SSHAuthorizedKeys) != 1 {
    53  			return fmt.Errorf("Lenght of field SSHAuthorizedKeys didn't match. Expected: %d, Given: %d", 1, len(u.SSHAuthorizedKeys))
    54  		}
    55  
    56  		if u.SSHAuthorizedKeys[0] != "keys" {
    57  			return fmt.Errorf("Field SSHAuthorizedKeys didn't match. Expected: %s, Given: %s", "keys", u.SSHAuthorizedKeys[0])
    58  		}
    59  
    60  		if *u.Create.Uid != uint(42) {
    61  			return fmt.Errorf("Field Uid didn't match. Expected: %d, Given: %d", uint(42), u.Create.Uid)
    62  		}
    63  
    64  		if u.Create.GECOS != "gecos" {
    65  			return fmt.Errorf("Field GECOS didn't match. Expected: %s, Given: %s", "gecos", u.Create.GECOS)
    66  		}
    67  
    68  		if u.Create.Homedir != "home" {
    69  			return fmt.Errorf("Field Homedir didn't match. Expected: %s, Given: %s", "home", u.Create.Homedir)
    70  		}
    71  
    72  		if u.Create.NoCreateHome != true {
    73  			return fmt.Errorf("Field NoCreateHome didn't match. Expected: %t, Given: %t", true, u.Create.NoCreateHome)
    74  		}
    75  
    76  		if u.Create.PrimaryGroup != "primary_group" {
    77  			return fmt.Errorf("Field PrimaryGroup didn't match. Expected: %s, Given: %s", "primary_group", u.Create.PrimaryGroup)
    78  		}
    79  
    80  		if len(u.Create.Groups) != 1 {
    81  			return fmt.Errorf("Lenght of field Groups didn't match. Expected: %d, Given: %d", 1, len(u.Create.Groups))
    82  		}
    83  
    84  		if u.Create.Groups[0] != "group" {
    85  			return fmt.Errorf("Field Groups didn't match. Expected: %s, Given: %s", "group", u.Create.Groups[0])
    86  		}
    87  
    88  		if u.Create.NoUserGroup != true {
    89  			return fmt.Errorf("Field NoUserGroup didn't match. Expected: %t, Given: %t", true, u.Create.NoUserGroup)
    90  		}
    91  
    92  		if u.Create.NoLogInit != true {
    93  			return fmt.Errorf("Field NoLogInit didn't match. Expected: %t, Given: %t", true, u.Create.NoLogInit)
    94  		}
    95  
    96  		if u.Create.Shell != "shell" {
    97  			return fmt.Errorf("Field Shell didn't match. Expected: %s, Given: %s", "shell", u.Create.Shell)
    98  		}
    99  
   100  		u = c.Passwd.Users[1]
   101  
   102  		if u.Name != "qux" {
   103  			return fmt.Errorf("Field Name didn't match. Expected: %s, Given: %s", "qux", u.Name)
   104  		}
   105  
   106  		if u.Create != nil {
   107  			return fmt.Errorf("Field Create didn't match. Expected: %v, Given: %v", nil, u.Create)
   108  		}
   109  
   110  		return nil
   111  	})
   112  }