forked from terraform-docs/terraform-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpretty_test.go
111 lines (97 loc) · 2.68 KB
/
pretty_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
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"
)
func TestPretty(t *testing.T) {
tests := map[string]struct {
config print.Config
}{
// Base
"Base": {
config: testutil.WithSections(),
},
"Empty": {
config: testutil.WithDefaultSections(
testutil.With(func(c *print.Config) {
c.ModuleRoot = "empty"
}),
),
},
"HideAll": {
config: testutil.With(func(c *print.Config) {
c.Sections.Header = false // Since we don't show the header, the file won't be loaded at all
c.HeaderFrom = "bad.tf"
}),
},
// Settings
"WithColor": {
config: testutil.WithSections(
testutil.With(func(c *print.Config) {
c.Settings.Color = true
}),
),
},
"OutputValues": {
config: testutil.With(func(c *print.Config) {
c.Sections.Outputs = true
c.OutputValues.Enabled = true
c.OutputValues.From = "output_values.json"
c.Settings.Sensitive = true
}),
},
// Only section
"OnlyDataSources": {
config: testutil.With(func(c *print.Config) { c.Sections.DataSources = true }),
},
"OnlyHeader": {
config: testutil.With(func(c *print.Config) { c.Sections.Header = true }),
},
"OnlyFooter": {
config: testutil.With(func(c *print.Config) {
c.Sections.Footer = true
c.FooterFrom = "footer.md"
}),
},
"OnlyInputs": {
config: testutil.With(func(c *print.Config) { c.Sections.Inputs = true }),
},
"OnlyOutputs": {
config: testutil.With(func(c *print.Config) { c.Sections.Outputs = true }),
},
"OnlyModulecalls": {
config: testutil.With(func(c *print.Config) { c.Sections.ModuleCalls = true }),
},
"OnlyProviders": {
config: testutil.With(func(c *print.Config) { c.Sections.Providers = true }),
},
"OnlyRequirements": {
config: testutil.With(func(c *print.Config) { c.Sections.Requirements = true }),
},
"OnlyResources": {
config: testutil.With(func(c *print.Config) { c.Sections.Resources = true }),
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
expected, err := testutil.GetExpected("pretty", "pretty-"+name)
assert.Nil(err)
module, err := testutil.GetModule(&tt.config)
assert.Nil(err)
formatter := NewPretty(&tt.config)
err = formatter.Generate(module)
assert.Nil(err)
assert.Equal(expected, formatter.Content())
})
}
}