{"modulePath":"github.com/linuxsuren/api-testing","version":"v0.0.21","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package runner\n\nPackage runner responsible for excute the test case\n\nPackage runner provides the common expr style functions\n\n## Variables\n\n```go\nvar RunnersNum = promauto.NewGauge(prometheus.GaugeOpts{\n\tName: \"atest_runners_count\",\n\tHelp: \"The total number of runners\",\n})\n```\n\n## Functions\n\n```go\nfunc DeepCopy(src, dist interface{}) (err error)\n```\n\n```go\nfunc ExprFuncHTTPReady(params ...interface{}) (res interface{}, err error)\n```\nExprFuncHTTPReady is an expr function for reading status from a HTTP server\n\n```go\nfunc ExprFuncSleep(params ...interface{}) (res interface{}, err error)\n```\nExprFuncSleep is an expr function for sleeping\n\n```go\nfunc IsJSONCompatileType(contentType string) bool\n```\n\n```go\nfunc RegisterRunner(kind string, runner RunnerCreator) error\n```\n\n```go\nfunc Verify(expect testing.Response, data map[string]any) (err error)\n```\nVerify if the data satisfies the expression.\n\n## Types\n\n```go\ntype BodyGetter interface {\n\tGetBody() string\n\tGetBodyFieldsExpect() map[string]interface{}\n}\n```\n\n```go\ntype BodyVerifier interface {\n\tParse(data []byte) (interface{}, error)\n\tVerify(data []byte) error\n}\n```\n\n```go\nfunc NewBodyVerify(contentType string, body BodyGetter) BodyVerifier\n```\n\n```go\ntype ContextKey string\n```\nContextKey is the alias type of string for context key\n\n```go\nfunc NewContextKeyBuilder() ContextKey\n```\nNewContextKeyBuilder returns an emtpy context key\n\n```go\nfunc (c ContextKey) GetContextValueOrEmpty(ctx context.Context) string\n```\nGetContextValueOrEmpty returns the value of the context key, if not exist, return empty string\n\n```go\nfunc (c ContextKey) ParentDir() ContextKey\n```\nParentDir returns the key of the parent directory\n\n```go\ntype FormatPrinter interface {\n\tFprintf(w io.Writer, level, format string, a ...any) (n int, err error)\n}\n```\nFormatPrinter represents a formart printer with level\n\n```go\ntype GithubPRCommentOption struct {\n\tRepo       string\n\tPR         int\n\tIdentity   string\n\tToken      string\n\tReportFile string\n}\n```\n\n```go\ntype LevelWriter interface {\n\tInfo(format string, a ...any)\n\tDebug(format string, a ...any)\n\tTrace(format string, a ...any)\n}\n```\nLevelWriter represents a writer with level\n\n```go\nfunc NewDefaultLevelWriter(level string, writer io.Writer) LevelWriter\n```\nNewDefaultLevelWriter creates a default LevelWriter instance\n\n```go\ntype LogLevel int\n```\n\n```go\nconst (\n\tLogLevelInfo  LogLevel = 3\n\tLogLevelDebug LogLevel = 5\n\tLogLevelTrace LogLevel = 7\n)\n```\n\n```go\ntype Mutator interface {\n\tRender(*testing.TestCase) *testing.TestCase\n\tMessage() string\n}\n```\n\n```go\ntype ReportRecord struct {\n\tGroup     string\n\tName      string\n\tMethod    string\n\tAPI       string\n\tBody      string\n\tBeginTime time.Time\n\tEndTime   time.Time\n\tError     error\n}\n```\nReportRecord represents the raw data of a request\n\n```go\nfunc NewReportRecord() *ReportRecord\n```\nNewReportRecord creates a record, and set the begin time to be now\n\n```go\nfunc (r *ReportRecord) Duration() time.Duration\n```\nDuration returns the duration between begin and end time\n\n```go\nfunc (r *ReportRecord) ErrorCount() int\n```\nErrorCount returns the count number of errors\n\n```go\nfunc (r *ReportRecord) GetErrorMessage() string\n```\nGetErrorMessage returns the error message\n\n```go\ntype ReportResult struct {\n\tName             string\n\tAPI              string\n\tCount            int\n\tAverage          time.Duration\n\tMax              time.Duration\n\tMin              time.Duration\n\tQPS              int\n\tError            int\n\tLastErrorMessage string\n}\n```\nReportResult represents the report result of a set of the same API requests\n\n```go\ntype ReportResultSlice []ReportResult\n```\nReportResultSlice is the alias type of ReportResult slice\n\n```go\nfunc (r ReportResultSlice) Len() int\n```\nLen returns the count of slice items\n\n```go\nfunc (r ReportResultSlice) Less(i, j int) bool\n```\nLess returns if i bigger than j\n\n```go\nfunc (r ReportResultSlice) Swap(i, j int)\n```\nSwap swaps the items\n\n```go\ntype ReportResultWithTotal struct {\n\tReportResult\n\tTotal time.Duration\n\tFirst time.Time\n\tLast  time.Time\n}\n```\nReportResultWithTotal holds the total duration base on ReportResult\n\n```go\ntype ReportResultWriter interface {\n\tOutput([]ReportResult) error\n\tWithAPICoverage(apiCoverage apispec.APICoverage) ReportResultWriter\n\tWithResourceUsage([]ResourceUsage) ReportResultWriter\n\tGetWriter() io.Writer\n}\n```\nReportResultWriter is the interface of the report writer\n\n```go\nfunc NewDiscardResultWriter() ReportResultWriter\n```\nNewDiscardResultWriter creates a report result writer which discard everything\n\n```go\nfunc NewGRPCResultWriter(ctx context.Context, url string) ReportResultWriter\n```\nNewGRPCResultWriter creates a new grpcResultWriter\n\n```go\nfunc NewGithubPRCommentWriter(opt *GithubPRCommentOption) (ReportResultWriter, error)\n```\n\n```go\nfunc NewHTMLResultWriter(writer io.Writer) ReportResultWriter\n```\nNewHTMLResultWriter creates a new htmlResultWriter\n\n```go\nfunc NewHTTPResultWriter(requestType string, url string, parameters map[string]string, templateFile *TemplateOption) ReportResultWriter\n```\nNewHTTPResultWriter creates a new httpResultWriter\n\n```go\nfunc NewJSONResultWriter(writer io.Writer) ReportResultWriter\n```\nNewJSONResultWriter creates a new jsonResultWriter\n\n```go\nfunc NewMarkdownResultWriter(writer io.Writer) ReportResultWriter\n```\nNewMarkdownResultWriter creates the Markdown writer\n\n```go\nfunc NewPDFResultWriter(writer io.Writer) ReportResultWriter\n```\nNewPDFResultWriter creates a new PDFResultWriter\n\n```go\nfunc NewResultWriter(writer io.Writer) ReportResultWriter\n```\nNewResultWriter creates a result writer with the specific io.Writer\n\n```go\ntype ResourceUsage struct {\n\tMemory uint64\n\tCPU    uint64\n\tTime   time.Time\n}\n```\n\n```go\ntype ResponseRecord interface {\n\tGetResponseRecord() SimpleResponse\n}\n```\nHTTPResponseRecord represents a http response record\n\n```go\ntype RunnerCreator func(suite *testing.TestSuite) TestCaseRunner\n```\n\n```go\ntype SimpleResponse struct {\n\tHeader     map[string]string\n\tBody       string\n\tRawBody    []byte\n\tStatusCode int\n}\n```\nSimpleResponse represents a simple response\n\n```go\nfunc HandleLargeResponseBody(resp SimpleResponse, suite string, caseName string) (SimpleResponse, error)\n```\n\n```go\ntype TemplateOption struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTemplateOption(filename string, fileType string) *TemplateOption\n```\n\n```go\ntype TestCaseRunner interface {\n\tRunTestCase(testcase *testing.TestCase, dataContext interface{}, ctx context.Context) (output interface{}, err error)\n\tGetSuggestedAPIs(suite *testing.TestSuite, api string) ([]*testing.TestCase, error)\n\tWithSecure(secure *testing.Secure)\n\tWithOutputWriter(io.Writer)\n\tWithWriteLevel(level string)\n\tWithTestReporter(TestReporter)\n\tWithExecer(fakeruntime.Execer)\n\tWithSuite(*testing.TestSuite)\n\tWithAPISuggestLimit(int)\n}\n```\nTestCaseRunner represents a test case runner\n\n```go\nfunc GetTestSuiteRunner(suite *testing.TestSuite) TestCaseRunner\n```\nGetTestSuiteRunner returns a proper runner according to the given test suite.\n\n```go\nfunc NewGRPCTestCaseRunner(host string, proto testing.RPCDesc) TestCaseRunner\n```\n\n```go\nfunc NewGraphQLRunner(parent TestCaseRunner) TestCaseRunner\n```\n\n```go\nfunc NewReverseHTTPRunner(normal TestCaseRunner) TestCaseRunner\n```\n\n```go\nfunc NewSimpleTestCaseRunner() TestCaseRunner\n```\nNewSimpleTestCaseRunner creates the instance of the simple test case runner\n\n```go\ntype TestReporter interface {\n\tPutRecord(*ReportRecord)\n\tGetAllRecords() []*ReportRecord\n\tExportAllReportResults() (ReportResultSlice, error)\n\tGetResourceUsage() []ResourceUsage\n}\n```\nTestReporter is the interface of the report\n\n```go\nfunc NewDiscardTestReporter() TestReporter\n```\nNewDiscardTestReporter creates a test reporter which discard everything\n\n```go\nfunc NewMemoryTestReporter(resMonitor monitor.MonitorClient, monitorTarget string) TestReporter\n```\nNewMemoryTestReporter creates a memory based test reporter\n\n```go\nfunc NewPrometheusWriter(remote string, sync bool) TestReporter\n```\nNewPrometheusWriter creates a new PrometheusWriter\n\n```go\ntype UnimplementedRunner struct {\n\tSecure *testing.Secure\n\t// contains filtered or unexported fields\n}\n```\nUnimplementedRunner implements interface TestCaseRunner except method RunTestCase.\n\nGenerally, this struct can be inherited directly when implementing a new runner. It is recommended to use NewDefaultUnimplementedRunner to initalize rather than to fill it manully.\n\n```go\nfunc NewDefaultUnimplementedRunner() UnimplementedRunner\n```\nNewDefaultUnimplementedRunner initializes an unimplementedRunner using the default values.\n\n```go\nfunc (r *UnimplementedRunner) GetSuggestedAPIs(suite *testing.TestSuite, api string) (result []*testing.TestCase, err error)\n```\n\n```go\nfunc (r *UnimplementedRunner) RunTestCase(testcase *testing.TestCase, dataContext interface{}, ctx context.Context) (output interface{}, err error)\n```\n\n```go\nfunc (r *UnimplementedRunner) WithAPISuggestLimit(int)\n```\n\n```go\nfunc (r *UnimplementedRunner) WithExecer(execer fakeruntime.Execer)\n```\nWithExecer sets the execer\n\n```go\nfunc (r *UnimplementedRunner) WithOutputWriter(writer io.Writer)\n```\nWithOutputWriter sets the io.Writer\n\n```go\nfunc (r *UnimplementedRunner) WithSecure(secure *testing.Secure)\n```\nWithSecure sets the secure option.\n\n```go\nfunc (s *UnimplementedRunner) WithSuite(suite *testing.TestSuite)\n```\n\n```go\nfunc (r *UnimplementedRunner) WithTestReporter(reporter TestReporter)\n```\nWithTestReporter sets the TestReporter\n\n```go\nfunc (r *UnimplementedRunner) WithWriteLevel(level string)\n```\nWithWriteLevel sets the level writer\n\n","path":"github.com/linuxsuren/api-testing/pkg/runner","name":"runner","synopsis":"Package runner responsible for excute the test case","isRedistributable":true}
