-
Notifications
You must be signed in to change notification settings - Fork 25
/
type_teststep.go
76 lines (66 loc) · 2.52 KB
/
type_teststep.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
package resource
import (
"go/ast"
"go/types"
"github.com/bflad/tfproviderlint/helper/astutils"
)
const (
TestStepFieldCheck = `Check`
TestStepFieldConfig = `Config`
TestStepFieldDestroy = `Destroy`
TestStepFieldExpectError = `ExpectError`
TestStepFieldExpectNonEmptyPlan = `ExpectNonEmptyPlan`
TestStepFieldImportState = `ImportState`
TestStepFieldImportStateId = `ImportStateId`
TestStepFieldImportStateIdFunc = `ImportStateIdFunc`
TestStepFieldImportStateIdPrefix = `ImportStateIdPrefix`
TestStepFieldImportStateCheck = `ImportStateCheck`
TestStepFieldImportStateVerify = `ImportStateVerify`
TestStepFieldImportStateVerifyIgnore = `ImportStateVerifyIgnore`
TestStepFieldPlanOnly = `PlanOnly`
TestStepFieldPreConfig = `PreConfig`
TestStepFieldPreventDiskCleanup = `PreventDiskCleanup`
TestStepFieldPreventPostDestroyRefresh = `PreventPostDestroyRefresh`
TestStepFieldResourceName = `ResourceName`
TestStepFieldSkipFunc = `SkipFunc`
TestStepFieldTaint = `Taint`
TypeNameTestStep = `TestStep`
)
// testStepType is an internal representation of the SDK helper/resource.TestStep type
//
// This is used to prevent importing the real type since the project supports
// multiple versions of the Terraform Plugin SDK, while allowing passes to
// access the data in a familiar manner.
type testStepType struct{}
// TestStepInfo represents all gathered TestStep data for easier access
type TestStepInfo struct {
AstCompositeLit *ast.CompositeLit
Fields map[string]*ast.KeyValueExpr
TestStep *testStepType
TypesInfo *types.Info
}
// NewTestStepInfo instantiates a TestStepInfo
func NewTestStepInfo(cl *ast.CompositeLit, info *types.Info) *TestStepInfo {
result := &TestStepInfo{
AstCompositeLit: cl,
Fields: astutils.CompositeLitFields(cl),
TestStep: &testStepType{},
TypesInfo: info,
}
return result
}
// DeclaresField returns true if the field name is present in the AST
func (info *TestStepInfo) DeclaresField(fieldName string) bool {
return info.Fields[fieldName] != nil
}
// IsTypeTestStep returns if the type is TestStep from the helper/schema package
func IsTypeTestStep(t types.Type) bool {
switch t := t.(type) {
case *types.Named:
return IsNamedType(t, TypeNameTestStep)
case *types.Pointer:
return IsTypeTestStep(t.Elem())
default:
return false
}
}