Documentation
¶
Overview ¶
Package gotests contains the core logic for generating table-driven tests.
Index ¶
- func ChangeFailFileSuffix(dir string, oldSuffix, newSuffix string) error
- func CheckEmptyFileAndThenRemove(filePath string, shouldPrintLog bool) error
- func CheckValueExis(ctx context.Context, p *ssa.Function, globalValue, globalName string) bool
- func CreatMiddleCode(ctx context.Context) (int, error)
- func FixGoFile(path string) error
- func GenerateBaseTest(ctx context.Context) error
- func GenerateTest(dir string, shouldPrintLog bool) error
- func GenerateTestForPlugin(opt atgconstant.Options) error
- func GetAllMock(ctx context.Context, useMockType int) map[string]map[string]int
- func GetBaseMockByTempleType(ctx context.Context, useMockType int) map[string]map[string]int
- func GetFunctions(sr *goparser.Result, opt *Options) ([]*models.Function, error)
- func GetGlobalValueBuilder(ctx context.Context) ([]string, []string)
- func GetSpecialValueBuilder(ctx context.Context) map[string][]string
- func Init(option *atgconstant.Options) (context.Context, error)
- func NewTestsuiteEntry(ctx context.Context, targetFile string, lock atghelper.RWLocker) *testsuiteEntry
- func PickStructField(ctx context.Context) []string
- func PluginCmd(opt atgconstant.Options) error
- func ReNameFileToGo(path, oldSuffix, newSuffix string, isTemp bool, shouldPrintLog bool) error
- func RecordFinalSuite(ctx context.Context, filePath string, funcData map[string]string, ...) (code []byte, err error)
- func RemoveGeneratedFile(opt atgconstant.Options)
- func ReportInternalError(option atgconstant.Options, err error, panicInfo string)
- func Run(done func(), option atgconstant.Options) int
- func RunForPlugin(option atgconstant.Options) error
- func RunSplitFunction(done func(), option atgconstant.Options)
- func RunSplitFunctionTask(filePath string, functionName string, useMockType int)
- func UpdateSmartUnit(path string) error
- func Work(path string, functionList string, useMockType int) error
- func WorkForPlugin(opt atgconstant.Options) error
- func WorkForSplitFunction(path string, useMockType int) error
- func WorkOnFile(option atgconstant.Options) error
- func WorkToChangeGo(dir string, shouldPrintLog bool) error
- type GeneratedTest
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeFailFileSuffix ¶
func CheckValueExis ¶
func GenerateBaseTest ¶
func GenerateTest ¶
func GenerateTestForPlugin ¶
func GenerateTestForPlugin(opt atgconstant.Options) error
GenerateTestForPlugin the test for the plugin. It is firstly generate the test with the _smart_unit_test_[random_number].go If there is the _smart_unit_test.go file. We merge these two file. If there is no _smart_unit_test.go file, we remove the random number.
func GetBaseMockByTempleType ¶
func GetFunctions ¶
We have two scenarios 1. generate the middle code: using the funcsMap 2. generate the final code: using the rowData
func NewTestsuiteEntry ¶
func PickStructField ¶
func PluginCmd ¶
func PluginCmd(opt atgconstant.Options) error
func ReNameFileToGo ¶
func RecordFinalSuite ¶
func RemoveGeneratedFile ¶
func RemoveGeneratedFile(opt atgconstant.Options)
we are going to remove Vector_middle_code_test.go, path_BridgeVector.go, middle_code_fail_test.txt _final_code_fail_test.txt.
func ReportInternalError ¶
func ReportInternalError(option atgconstant.Options, err error, panicInfo string)
Plugin doesn't need to report the message. Only the debug mode, we can see the message.
func Run ¶
func Run(done func(), option atgconstant.Options) int
func RunForPlugin ¶
func RunForPlugin(option atgconstant.Options) error
func RunSplitFunction ¶
func RunSplitFunction(done func(), option atgconstant.Options)
func RunSplitFunctionTask ¶
func UpdateSmartUnit ¶
func WorkForPlugin ¶
func WorkForPlugin(opt atgconstant.Options) error
func WorkForSplitFunction ¶
func WorkOnFile ¶
func WorkOnFile(option atgconstant.Options) error
func WorkToChangeGo ¶
Types ¶
type GeneratedTest ¶
type GeneratedTest struct {
Path string // The test file's absolute path.
Functions []*models.Function // The functions with new test methods.
Output []byte // The contents of the test file.
}
A GeneratedTest contains information about a test file with generated tests.
func GenerateTests ¶
func GenerateTests(srcPath string, opt *Options) (*GeneratedTest, error)
GenerateTests generates table-driven tests for the function and method signatures defined in the target source path file(s). The source path parameter can be either a Go source file or directory containing Go files.
type Options ¶
type Options struct {
Only *regexp.Regexp // Includes only functions that match.
Exclude *regexp.Regexp // Excludes functions that match.
Exported bool // Include only exported methods
PrintInputs bool // Print function parameters in error messages
Subtests bool // Print tests using Go 1.7 subtests
Ctx context.Context // Context of the smart unit
TestCaseNum int // Test case number
Uid string // uuid for each function
TestMode string // type of render test
RecordRow map[string]string // rowData on each function
Builder []string // global value builder
MiddleBuilder []string // global value builder
FilePath string // realpath
Parallel bool // Print tests that runs the subtests in parallel.
Named bool // Create Map instead of slice
Importer func() types.Importer // A custom importer. // TODO: remoeve it because I don't know to use it
Template string // Name of custom template set
TemplateDir string // Path to custom template set
TemplateParams map[string]interface{} // Custom external parameters
TemplateData [][]byte // Data slice for templates
ExistTestImport []*instrumentation.Import // Imports from exist test file for template
UseMockType int // whether to user mock pkg in cases
UseMockMap map[string]map[string]int // Data for function for mock
}
Options provides custom filters and parameters for generating tests.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
goparser
This file may have been modified by Bytedance Ltd.
|
This file may have been modified by Bytedance Ltd. |
|
models
This file may have been modified by Bytedance Ltd.
|
This file may have been modified by Bytedance Ltd. |
|
output
Package goparse contains logic for parsing Go files.
|
Package goparse contains logic for parsing Go files. |
|
render
This file may have been modified by Bytedance Ltd.
|
This file may have been modified by Bytedance Ltd. |
|
render/bindata
Code generated for package bindata by go-bindata DO NOT EDIT.
|
Code generated for package bindata by go-bindata DO NOT EDIT. |
|
Code generated by "esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./"; DO NOT EDIT.
|
Code generated by "esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./"; DO NOT EDIT. |