diff options
| author | Martin Atkins <mart@degeneration.co.uk> | 2018-11-03 21:12:11 +0000 |
|---|---|---|
| committer | Martin Atkins <mart@degeneration.co.uk> | 2018-11-03 21:20:10 +0000 |
| commit | 361186aad0d06ab9874f4f3ffbbb9011dc1a06f0 (patch) | |
| tree | 8d5ebc7acff646e9b93de4d2ccec8ff1eaf9ca29 /hclwrite | |
| parent | 17ff23300feb0cdb7b5fb12e60a834d3962e95eb (diff) | |
hclwrite: Recast TestRoundupCreate as an example
Since the goal of this is to be somewhat realistic of what a caller might
do, we might as well also include it in the godoc examples.
Diffstat (limited to 'hclwrite')
| -rw-r--r-- | hclwrite/examples_test.go (renamed from hclwrite/roundup_test.go) | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/hclwrite/roundup_test.go b/hclwrite/examples_test.go index 31543d1..170572f 100644 --- a/hclwrite/roundup_test.go +++ b/hclwrite/examples_test.go @@ -1,17 +1,13 @@ package hclwrite_test import ( - "bytes" - "strings" - "testing" + "fmt" "github.com/hashicorp/hcl2/hclwrite" "github.com/zclconf/go-cty/cty" ) -// TestRoundupCreate is a test that exercises a number of different codepaths -// to create a file from scratch, like a calling application might. -func TestRoundupCreate(t *testing.T) { +func Example_generateFromScratch() { f := hclwrite.NewEmptyFile() rootBody := f.Body() rootBody.SetAttributeValue("string", cty.StringVal("bar")) // this is overwritten later @@ -39,28 +35,24 @@ func TestRoundupCreate(t *testing.T) { bazBody.SetAttributeValue("beep", cty.StringVal("boop")) bazBody.SetAttributeValue("baz", cty.ListValEmpty(cty.String)) - got := string(bytes.TrimSpace(f.Bytes())) - want := strings.TrimSpace(` -string = "foo" - -object = {bar = 5, baz = true, foo = "foo"} -bool = false - -foo { - hello = "world" -} -empty { -} - -bar "a" "b" { - baz { - foo = 10 - beep = "boop" - baz = [] - } -} -`) - if got != want { - t.Errorf("wrong result\ngot:\n%s\n\nwant:\n%s", got, want) - } + fmt.Printf("%s", f.Bytes()) + // Output: + // string = "foo" + // + // object = {bar = 5, baz = true, foo = "foo"} + // bool = false + // + // foo { + // hello = "world" + // } + // empty { + // } + // + // bar "a" "b" { + // baz { + // foo = 10 + // beep = "boop" + // baz = [] + // } + // } } |
