Files
terraform-docs/format/tfvars_hcl_test.go
Khosrow Moossavi d2fe2b1b29 Move print package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 15:04:07 -04:00

119 lines
2.4 KiB
Go

/*
Copyright 2021 The terraform-docs Authors.
Licensed under the MIT license (the "License"); you may not
use this file except in compliance with the License.
You may obtain a copy of the License at the LICENSE file in
the root directory of this source tree.
*/
package format
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/terraform-docs/terraform-docs/internal/testutil"
"github.com/terraform-docs/terraform-docs/print"
"github.com/terraform-docs/terraform-docs/terraform"
)
func TestTfvarsHcl(t *testing.T) {
tests := map[string]struct {
settings print.Settings
options terraform.Options
}{
// Base
"Base": {
settings: testutil.WithSections(),
options: terraform.Options{},
},
"Empty": {
settings: testutil.WithSections(),
options: terraform.Options{
Path: "empty",
},
},
// Settings
"EscapeCharacters": {
settings: print.Settings{EscapeCharacters: true},
options: terraform.Options{},
},
"PrintDescription": {
settings: testutil.WithSections(
print.Settings{
ShowDescription: true,
},
),
options: terraform.Options{
SortBy: &terraform.SortBy{
Name: true,
Required: true,
},
},
},
"SortByName": {
settings: testutil.WithSections(),
options: terraform.Options{
SortBy: &terraform.SortBy{
Name: true,
},
},
},
"SortByRequired": {
settings: testutil.WithSections(),
options: terraform.Options{
SortBy: &terraform.SortBy{
Name: true,
Required: true,
},
},
},
"SortByType": {
settings: testutil.WithSections(),
options: terraform.Options{
SortBy: &terraform.SortBy{
Type: true,
},
},
},
// No section
"NoInputs": {
settings: testutil.WithSections(
print.Settings{
ShowInputs: false,
},
),
options: terraform.Options{},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
expected, err := testutil.GetExpected("tfvars", "hcl-"+name)
assert.Nil(err)
options, err := terraform.NewOptions().With(&tt.options)
assert.Nil(err)
module, err := testutil.GetModule(options)
assert.Nil(err)
formatter := NewTfvarsHCL(tt.settings.ToConfig())
err = formatter.Generate(module)
assert.Nil(err)
actual, err := formatter.ExecuteTemplate("")
assert.Nil(err)
assert.Equal(expected, actual)
})
}
}