github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ignition/resource_ignition_group_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 TestIngnitionGroup(t *testing.T) {
    11  	testIgnition(t, `
    12  		data "ignition_group" "foo" {
    13  			name = "foo"
    14  			password_hash = "password"
    15  			gid = 42
    16  		}
    17  
    18  		data "ignition_group" "qux" {
    19  			name = "qux"
    20  		}
    21  
    22  		data "ignition_config" "test" {
    23  			groups = [
    24  				"${data.ignition_group.foo.id}",
    25  				"${data.ignition_group.qux.id}",
    26  			]
    27  		}
    28  	`, func(c *types.Config) error {
    29  		if len(c.Passwd.Groups) != 2 {
    30  			return fmt.Errorf("groups, found %d", len(c.Passwd.Groups))
    31  		}
    32  
    33  		g := c.Passwd.Groups[0]
    34  
    35  		if g.Name != "foo" {
    36  			return fmt.Errorf("name, found %q", g.Name)
    37  		}
    38  
    39  		if g.PasswordHash != "password" {
    40  			return fmt.Errorf("password_hash, found %q", g.PasswordHash)
    41  		}
    42  
    43  		if g.Gid == nil || *g.Gid != uint(42) {
    44  			return fmt.Errorf("gid, found %q", *g.Gid)
    45  		}
    46  
    47  		g = c.Passwd.Groups[1]
    48  
    49  		if g.Name != "qux" {
    50  			return fmt.Errorf("name, found %q", g.Name)
    51  		}
    52  
    53  		if g.Gid != nil {
    54  			return fmt.Errorf("uid, found %d", *g.Gid)
    55  		}
    56  
    57  		return nil
    58  	})
    59  }