/
util_test.go
78 lines (72 loc) · 2.26 KB
/
util_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
package provider
import (
"testing"
"github.com/google/go-cmp/cmp"
tfjson "github.com/hashicorp/terraform-json"
)
func Test_resourceSchema(t *testing.T) {
cases := map[string]struct {
schemas map[string]*tfjson.Schema
providerShortName string
templateFileName string
expectedSchema *tfjson.Schema
expectedResourceName string
}{
"provider short name matches schema name": {
schemas: map[string]*tfjson.Schema{
"http": {},
},
providerShortName: "http",
templateFileName: "http.md.tmpl",
expectedSchema: &tfjson.Schema{},
expectedResourceName: "http",
},
"provider short name does not match schema name": {
schemas: map[string]*tfjson.Schema{
"http": {},
},
providerShortName: "tls",
templateFileName: "http.md.tmpl",
expectedSchema: nil,
expectedResourceName: "tls_http",
},
"provider short name concatenated with template file name matches schema name": {
schemas: map[string]*tfjson.Schema{
"tls_cert_request": {},
},
providerShortName: "tls",
templateFileName: "cert_request.md.tmpl",
expectedSchema: &tfjson.Schema{},
expectedResourceName: "tls_cert_request",
},
"provider short name concatenated with template file name does not match schema name": {
schemas: map[string]*tfjson.Schema{
"tls_cert_request": {},
},
providerShortName: "tls",
templateFileName: "not_found.md.tmpl",
expectedSchema: nil,
expectedResourceName: "tls_not_found",
},
"provider short name concatenated with same template file name matches schema name": {
schemas: map[string]*tfjson.Schema{
"tls_tls": {},
},
providerShortName: "tls",
templateFileName: "tls.md.tmpl",
expectedSchema: &tfjson.Schema{},
expectedResourceName: "tls_tls",
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actualSchema, actualResourceName := resourceSchema(c.schemas, c.providerShortName, c.templateFileName)
if !cmp.Equal(c.expectedSchema, actualSchema) {
t.Errorf("expected: %+v, got: %+v", c.expectedSchema, actualSchema)
}
if !cmp.Equal(c.expectedResourceName, actualResourceName) {
t.Errorf("expected: %s, got: %s", c.expectedResourceName, actualResourceName)
}
})
}
}