Documentation
¶
Overview ¶
Package provider understands the layout of terraform provider repositories: classifying changed files, extracting acceptance tests, and tracing symbols and imports via the Go AST.
Index ¶
- Constants
- Variables
- func GetModulePath(repoPath string) (string, error)
- func SymbolsFromAST(parsed *ast.File, exportedOnly bool) []string
- type File
- func (f *File) AddDiscovery(source string)
- func (f *File) Classify() FileType
- func (f *File) ColouredFileName() string
- func (f *File) ExtractTests(splitOn string, reappend bool) ([]string, error)
- func (f *File) GetContent() ([]byte, error)
- func (f *File) InServicePackage() bool
- func (f *File) ResourcePrefix() string
- func (f *File) SetContent(content []byte)
- func (f *File) Symbols(exportedOnly bool) []string
- func (f *File) TextColour() string
- func (f *File) TypeLabel() string
- type FileType
Constants ¶
const ( FileColourOther = "<darkGray>" FileColourResource = "<fg=36>" FileColourHelper = "<fg=117>" FileColourTest = "<fg=28>" FileColourUnitTest = "<darkGray>" FileColourVendor = "<fg=177>" FileColourDerived = "<fg=36>" FileColourSkipped = "<red>" )
Variables ¶
var Classifier = DefaultClassifier
Classifier sets the file type for a File. It can be overridden at program start to provide custom logic.
var ServiceDirPrefixes = []string{"internal/services", "internal/service"}
ServiceDirPrefixes lists the path segments used by different providers to organise service packages. Azure uses "internal/services/", AWS uses "internal/service/". All code that needs to detect or enumerate service directories should iterate over this slice.
Functions ¶
func GetModulePath ¶
GetModulePath reads go.mod in the repo and returns the module import path.
Types ¶
type File ¶
type File struct {
RelPath string // full relative path: "internal/services/batch/batch_account_resource.go"
Path string // absolute local path (or empty if using Content buffer)
Dir string // directory with trailing slash: "internal/services/batch/"
Name string // filename: "batch_account_resource.go"
BaseName string // filename without .go: "batch_account_resource"
Service string // the extracted service name from the path, e.g. "batch"
Type FileType
DiscoveredBy []string // e.g. CHANGED, DERIVED, TRACED, VENDOR
// contains filtered or unexported fields
}
File represents a Go source file in a Terraform provider repository.
func NewFile ¶
NewFile creates a File with only the path-derived fields populated. Use this for files in a remote environment where a local disk path isn't applicable.
func NewFileWithPath ¶
NewFileWithPath creates a File from a relative path and a local repository root.
func (*File) AddDiscovery ¶
AddDiscovery adds a discovery source label if it isn't already present.
func (*File) Classify ¶
Classify determines the FileType for this file using the global Classifier and sets f.Type.
func (*File) ColouredFileName ¶
ColouredFileName returns the formatted dir + coloured base for cout output. Example: "<fg=208>internal/services/batch/</><fg=36>batch_account_resource.go</>"
func (*File) ExtractTests ¶
ExtractTests parses Go source code and extracts names of acceptance tests (functions starting with "TestAcc"). If AST parsing fails, it falls back to string regex matching. It uses f.GetContent() to read the file (from cached Content or from disk). It also applies the provided `splitOn` and `reappend` logic.
func (*File) GetContent ¶
GetContent returns the file's content. It uses the cached Content buffer if available, otherwise reads from the absolute Path on disk and caches the result.
func (*File) InServicePackage ¶
InServicePackage returns true if the path is within a service directory.
func (*File) ResourcePrefix ¶
ResourcePrefix returns the prefix used for test file discovery. For "batch_account_resource.go" → "batch_account". For "batch_account_data_source.go" → "batch_account_data_source".
func (*File) SetContent ¶
SetContent sets the file's internal content buffer and re-runs classification.
func (*File) Symbols ¶
Symbols extracts all globally declared function/type/variable/constant names from the file. If exportedOnly is true, it only returns symbols starting with an uppercase letter.
func (*File) TextColour ¶
TextColour returns the cout colour tag for this file type.
type FileType ¶
type FileType int
FileType classifies a Go file within a Terraform provider repository.
const ( FileTypeOther FileType = iota // outside service directories FileTypeResource // matches fileregex (resource or data source at service root) FileTypeHelper // in service dir but doesn't match fileregex (e.g. parse/, validate/, client/) FileTypeTest // _test.go with TestAcc functions FileTypeUnitTest // _test.go without TestAcc functions FileTypeVendor // under vendor/ )
func DefaultClassifier ¶
DefaultClassifier provides the base classification logic.