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) DiscoverTests(splitOn string, reappend, individual bool) ([]string, error)
- func (f *File) ExtractChangedTests() (tests []string, ok bool, err error)
- func (f *File) ExtractTests(splitOn string, reappend bool) ([]string, error)
- func (f *File) GetContent() ([]byte, error)
- func (f *File) InServicePackage() bool
- func (f *File) IsMigrationFile() bool
- func (f *File) MigrationResourcePrefix() string
- func (f *File) ResourcePrefix() string
- func (f *File) SetContent(content []byte)
- func (f *File) SetPatch(patch string)
- 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) DiscoverTests ¶ added in v1.3.0
DiscoverTests extracts a file's test names for build triggering. With individual set, only full test function names are ever returned — never split prefixes: a directly changed test file (which carries its PR patch) yields just the test functions the PR modifies, while a file without a patch (e.g. discovered via a sibling resource) or one whose diff touches only non-test code yields every test function in the file. With individual off, all files get ExtractTests' split-prefix behaviour.
func (*File) ExtractChangedTests ¶ added in v1.3.0
ExtractChangedTests returns the full (unsplit) names of the acceptance test functions whose declarations overlap the file's PR patch — i.e. only the tests actually modified, not every test in the file. It returns ok=false when the file has no stored patch (it wasn't directly changed in the PR, e.g. discovered via a sibling resource file), in which case the caller should fall back to ExtractTests' prefix behaviour.
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) IsMigrationFile ¶ added in v1.2.0
IsMigrationFile returns true if this file lives inside a known state migration subdirectory of a service package (e.g. internal/services/storage/migration/storage_queue_v1_to_v2.go).
func (*File) MigrationResourcePrefix ¶ added in v1.2.0
MigrationResourcePrefix extracts the resource name from a migration filename by stripping the version-transition suffix (e.g. "_v0_to_v1"). For "storage_queue_v1_to_v2" -> "storage_queue".
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) SetPatch ¶ added in v1.3.0
SetPatch stores the file's unified diff from the GitHub PR file listing, enabling individual test discovery (ExtractChangedTests) for directly changed test files.
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.