-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage_test.go
More file actions
77 lines (66 loc) · 2.04 KB
/
Copy pathexample_usage_test.go
File metadata and controls
77 lines (66 loc) · 2.04 KB
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
package diffy
import (
"context"
"path/filepath"
"testing"
)
// Ensures the HCL in examples/module still parses and validates against a minimal schema.
func TestExampleModuleValidatesWithStubRunner(t *testing.T) {
root := filepath.Join("examples", "module")
parser := &exampleStubParser{providerSource: "registry.terraform.io/hashicorp/azurerm"}
runner := &exampleStubRunner{
schema: &TerraformSchema{
ProviderSchemas: map[string]*ProviderSchema{
parser.providerSource: {
ResourceSchemas: map[string]*ResourceSchema{
"azurerm_linux_function_app": {
Block: &SchemaBlock{
Attributes: map[string]*SchemaAttribute{},
BlockTypes: map[string]*SchemaBlockType{},
},
},
},
DataSourceSchemas: map[string]*ResourceSchema{},
},
},
},
}
findings, err := ValidateSchema(
WithTerraformRoot(root),
WithParser(parser),
WithTerraformRunner(runner),
func(opts *SchemaValidatorOptions) {
opts.Silent = true
},
)
if err != nil {
t.Fatalf("ValidateSchema returned error: %v", err)
}
if len(findings) > 0 {
t.Fatalf("example validation produced %d findings: %+v", len(findings), findings)
}
}
type exampleStubParser struct {
providerSource string
resources []ParsedResource
}
func (p *exampleStubParser) ParseProviderRequirements(_ context.Context, _ string) (map[string]ProviderConfig, error) {
return map[string]ProviderConfig{
"azurerm": {Source: p.providerSource},
}, nil
}
func (p *exampleStubParser) ParseMainFile(ctx context.Context, filename string) ([]ParsedResource, []ParsedDataSource, error) {
return p.ParseTerraformFiles(ctx, []string{filename})
}
func (p *exampleStubParser) ParseTerraformFiles(_ context.Context, _ []string) ([]ParsedResource, []ParsedDataSource, error) {
return p.resources, nil, nil
}
type exampleStubRunner struct {
schema *TerraformSchema
}
func (r *exampleStubRunner) Init(_ context.Context, _ string) error {
return nil
}
func (r *exampleStubRunner) GetSchema(_ context.Context, _ string) (*TerraformSchema, error) {
return r.schema, nil
}