-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathrender_test.go
116 lines (103 loc) · 2.61 KB
/
render_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
112
113
114
115
116
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package schemamd_test
import (
"encoding/json"
"os"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
tfjson "github.com/hashicorp/terraform-json"
"github.com/hashicorp/terraform-plugin-docs/internal/schemamd"
)
func TestRender(t *testing.T) {
t.Parallel()
for _, c := range []struct {
name string
inputFile string
expectedFile string
blocksSection bool
}{
{
"aws_route_table_association",
"testdata/aws_route_table_association.schema.json",
"testdata/aws_route_table_association.md",
false,
},
{
"aws_acm_certificate",
"testdata/aws_acm_certificate.schema.json",
"testdata/aws_acm_certificate.md",
false,
},
{
"awscc_logs_log_group",
"testdata/awscc_logs_log_group.schema.json",
"testdata/awscc_logs_log_group.md",
false,
},
{
"awscc_acmpca_certificate",
"testdata/awscc_acmpca_certificate.schema.json",
"testdata/awscc_acmpca_certificate.md",
false,
},
{
"framework_types",
"testdata/framework_types.schema.json",
"testdata/framework_types.md",
false,
},
{
"framework_types_blocks_section",
"testdata/framework_types.schema.json",
"testdata/framework_types_blocks_section.md",
true,
},
{
// Reference: https://github.com/hashicorp/terraform-plugin-docs/issues/380
"deep_nested_attributes",
"testdata/deep_nested_attributes.schema.json",
"testdata/deep_nested_attributes.md",
false,
},
{
// Reference: https://github.com/hashicorp/terraform-plugin-docs/issues/380
"deep_nested_attributes_blocks_section",
"testdata/deep_nested_attributes.schema.json",
"testdata/deep_nested_attributes_blocks_section.md",
true,
},
} {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
input, err := os.ReadFile(c.inputFile)
if err != nil {
t.Fatal(err)
}
expected, err := os.ReadFile(c.expectedFile)
if err != nil {
t.Fatal(err)
}
var schema tfjson.Schema
err = json.Unmarshal(input, &schema)
if err != nil {
t.Fatal(err)
}
b := &strings.Builder{}
err = schemamd.Render(&schema, b, c.blocksSection)
if err != nil {
t.Fatal(err)
}
// Remove \r characters so tests don't fail on windows
expectedStr := strings.ReplaceAll(string(expected), "\r", "")
// Remove trailing newlines before comparing (some text editors remove them).
expectedStr = strings.TrimRight(expectedStr, "\n")
actual := strings.TrimRight(b.String(), "\n")
if diff := cmp.Diff(expectedStr, actual); diff != "" {
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
}
})
}
}