github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ignition/resource_ignition_file_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 TestIngnitionFile(t *testing.T) {
    11  	testIgnition(t, `
    12  		data "ignition_file" "foo" {
    13  			filesystem = "foo"
    14  			path = "/foo"
    15  			content {
    16  				content = "foo"
    17  			}
    18  			mode = 420
    19  			uid = 42
    20  			gid = 84
    21  		}
    22  
    23  		data "ignition_file" "qux" {
    24  			filesystem = "qux"
    25  			path = "/qux"
    26  			source {
    27  				source = "qux"
    28  				compression = "gzip"
    29  				verification = "sha512-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
    30  			}
    31  		}
    32  
    33  		data "ignition_config" "test" {
    34  			files = [
    35  				"${data.ignition_file.foo.id}",
    36  				"${data.ignition_file.qux.id}",
    37  			]
    38  		}
    39  	`, func(c *types.Config) error {
    40  		if len(c.Storage.Files) != 2 {
    41  			return fmt.Errorf("arrays, found %d", len(c.Storage.Arrays))
    42  		}
    43  
    44  		f := c.Storage.Files[0]
    45  		if f.Filesystem != "foo" {
    46  			return fmt.Errorf("filesystem, found %q", f.Filesystem)
    47  		}
    48  
    49  		if f.Path != "/foo" {
    50  			return fmt.Errorf("path, found %q", f.Path)
    51  		}
    52  
    53  		if f.Contents.Source.String() != "data:text/plain;charset=utf-8;base64,Zm9v" {
    54  			return fmt.Errorf("contents.source, found %q", f.Contents.Source)
    55  		}
    56  
    57  		if f.Mode != types.FileMode(420) {
    58  			return fmt.Errorf("mode, found %q", f.Mode)
    59  		}
    60  
    61  		if f.User.Id != 42 {
    62  			return fmt.Errorf("uid, found %q", f.User.Id)
    63  		}
    64  
    65  		if f.Group.Id != 84 {
    66  			return fmt.Errorf("gid, found %q", f.Group.Id)
    67  		}
    68  
    69  		f = c.Storage.Files[1]
    70  		if f.Filesystem != "qux" {
    71  			return fmt.Errorf("filesystem, found %q", f.Filesystem)
    72  		}
    73  
    74  		if f.Path != "/qux" {
    75  			return fmt.Errorf("path, found %q", f.Path)
    76  		}
    77  
    78  		if f.Contents.Source.String() != "qux" {
    79  			return fmt.Errorf("contents.source, found %q", f.Contents.Source)
    80  		}
    81  
    82  		if f.Contents.Compression != "gzip" {
    83  			return fmt.Errorf("contents.compression, found %q", f.Contents.Compression)
    84  		}
    85  
    86  		if f.Contents.Verification.Hash.Sum != "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" {
    87  			return fmt.Errorf("config.replace.verification, found %q", f.Contents.Verification.Hash)
    88  		}
    89  
    90  		return nil
    91  	})
    92  }