{"modulePath":"github.com/linuxsuren/api-testing","version":"v0.0.21","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package testing\n\nCopyright 2023-2024 API Testing Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n### Package testing provide the test case functions {#hdr-Package_testing_provide_the_test_case_functions}\n\nCopyright 2023 API Testing Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\nCopyright 2023-2024 API Testing Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\nCopyright 2023 API Testing Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\nCopyright 2023 API Testing Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n## Constants\n\n```go\nconst (\n\tContextKeyGlobalParam = \"param\"\n)\n```\n\n## Functions\n\n```go\nfunc GetHeader() string\n```\nGetHeader returns the header of the YAML config file\n\n```go\nfunc SaveTestSuiteToFile(suite *TestSuite, suitePath string) (err error)\n```\nSaveTestSuiteToFile saves the test suite to file\n\n```go\nfunc ToYAML(suite *TestSuite) ([]byte, error)\n```\n\n## Types\n\n```go\ntype APISpec struct {\n\tKind   string   `yaml:\"kind,omitempty\" json:\"kind,omitempty\"`\n\tURL    string   `yaml:\"url,omitempty\" json:\"url,omitempty\"`\n\tRPC    *RPCDesc `yaml:\"rpc,omitempty\" json:\"rpc,omitempty\"`\n\tSecure *Secure  `yaml:\"secure,omitempty\" json:\"secure,omitempty\"`\n\tMetric *Metric  `yaml:\"metric,omitempty\" json:\"metric,omitempty\"`\n}\n```\n\n```go\ntype ConditionalVerify struct {\n\tCondition []string `yaml:\"condition,omitempty\" json:\"condition,omitempty\"`\n\tVerify    []string `yaml:\"verify,omitempty\" json:\"verify,omitempty\"`\n}\n```\n\n```go\ntype DataResult struct {\n\tPairs           map[string]string\n\tRows            []map[string]string\n\tDatabases       []string\n\tTables          []string\n\tCurrentDatabase string\n\tDuration        string\n\tLabels          map[string]string\n}\n```\n\n```go\ntype GraphQLRequestBody struct {\n\tQuery         string            `yaml:\"query\" json:\"query\"`\n\tOperationName string            `yaml:\"operationName\" json:\"operationName\"`\n\tVariables     map[string]string `yaml:\"variables\" json:\"variables\"`\n}\n```\n\n```go\ntype HistoryTestCase struct {\n\tID               string            `yaml:\"id,omitempty\" json:\"id,omitempty\"`\n\tCaseName         string            `yaml:\"caseName,omitempty\" json:\"name,omitempty\"`\n\tSuiteName        string            `yaml:\"suiteName,omitempty\" json:\"suiteName,omitempty\"`\n\tHistorySuiteName string            `yaml:\"historySuiteName,omitempty\" json:\"historySuiteName,omitempty\"`\n\tCreateTime       time.Time         `yaml:\"createTime,omitempty\" json:\"createTime,omitempty\"`\n\tSuiteAPI         string            `yaml:\"api,omitempty\" json:\"api,omitempty\"`\n\tSuiteSpec        APISpec           `yaml:\"spec,omitempty\" json:\"spec,omitempty\"`\n\tSuiteParam       map[string]string `yaml:\"param,omitempty\" json:\"param,omitempty\"`\n\tData             TestCase          `yaml:\"data,omitempty\" json:\"data,omitempty\"`\n\tHistoryHeader    map[string]string `yaml:\"historyHeader,omitempty\" json:\"historyHeader,omitempty\"`\n}\n```\n\n```go\ntype HistoryTestResult struct {\n\tMessage        string           `yaml:\"message,omitempty\" json:\"message,omitempty\"`\n\tError          string           `yaml:\"error,omitempty\" json:\"error,omitempty\"`\n\tTestCaseResult []TestCaseResult `yaml:\"testCaseResult,omitempty\" json:\"testCaseResult,omitempty\"`\n\tData           HistoryTestCase  `yaml:\"data,omitempty\" json:\"data,omitempty\"`\n\tCreateTime     time.Time        `yaml:\"createTime,omitempty\" json:\"createTime,omitempty\"`\n}\n```\n\n```go\ntype HistoryTestSuite struct {\n\tHistorySuiteName string            `yaml:\"name,omitempty\" json:\"name,omitempty\"`\n\tItems            []HistoryTestCase `yaml:\"items,omitempty\" json:\"items,omitempty\"`\n}\n```\n\n```go\ntype Job struct {\n\tItems []string `yaml:\"items,omitempty\" json:\"items,omitempty\"`\n}\n```\nJob contains a list of jobs\n\n```go\ntype Loader interface {\n\tHasMore() bool\n\tLoad() ([]byte, error)\n\tPut(string) (err error)\n\tGetContext() string\n\tGetCount() int\n\tReset()\n\tWithUserConfigDir(string)\n\n\tVerify() (readOnly bool, version string, err error)\n\tPProf(name string) []byte\n\n\tQuery(query map[string]string) (result DataResult, err error)\n\tGetThemes() ([]string, error)\n\tGetTheme(string) (string, error)\n\tGetBindings() ([]string, error)\n\tGetBinding(string) (string, error)\n\tGetMenus() ([]*Menu, error)\n\tGetPageOfJS(string) (string, error)\n\tGetPageOfCSS(string) (string, error)\n\tGetPageOfStatic(string) (string, error)\n\tGetPageOfServer(string) (string, error)\n}\n```\nLoader is an interface for test cases loader\n\n```go\nfunc NewFileLoader() Loader\n```\nNewFileLoader creates the instance of file loader\n\n```go\ntype Menu struct {\n\tName    string `json:\"name\"`\n\tIcon    string `json:\"icon\"`\n\tIndex   string `json:\"index\"`\n\tVersion int32  `json:\"version\"`\n}\n```\n\n```go\ntype Metric struct {\n\tType string `yaml:\"type,omitempty\" json:\"type,omitempty\"`\n\tURL  string `yaml:\"url,omitempty\" json:\"url,omitempty\"`\n}\n```\n\n```go\ntype Proxy struct {\n\tHTTP  string `yaml:\"http,omitempty\" json:\"http,omitempty\"`   // HTTP proxy URL\n\tHTTPS string `yaml:\"https,omitempty\" json:\"https,omitempty\"` // HTTPS proxy URL\n\tNo    string `yaml:\"no,omitempty\" json:\"no,omitempty\"`       // Comma-separated list of hosts to exclude from proxying\n}\n```\nProxy configuration for the test suite\n\n```go\ntype RPCDesc struct {\n\tImportPath       []string `yaml:\"import,omitempty\" json:\"import,omitempty\"`\n\tServerReflection bool     `yaml:\"serverReflection,omitempty\" json:\"serverReflection,omitempty\"`\n\tProtoFile        string   `yaml:\"protofile,omitempty\" json:\"protofile,omitempty\"`\n\tProtoSet         string   `yaml:\"protoset,omitempty\" json:\"protoset,omitempty\"`\n\tRaw              string   `yaml:\"raw,omitempty\" json:\"raw,omitempty\"`\n}\n```\n\n```go\ntype Request struct {\n\tAPI          string              `yaml:\"api\" json:\"api\"`\n\tMethod       string              `yaml:\"method,omitempty\" json:\"method,omitempty\" jsonschema:\"enum=GET,enum=POST,enum=PUT,enum=DELETE\"`\n\tQuery        SortedKeysStringMap `yaml:\"query,omitempty\" json:\"query,omitempty\"`\n\tHeader       map[string]string   `yaml:\"header,omitempty\" json:\"header,omitempty\"`\n\tCookie       map[string]string   `yaml:\"cookie,omitempty\" json:\"cookie,omitempty\"`\n\tForm         map[string]string   `yaml:\"form,omitempty\" json:\"form,omitempty\"`\n\tBody         RequestBody         `yaml:\"body,omitempty\" json:\"body,omitempty\"`\n\tBodyFromFile string              `yaml:\"bodyFromFile,omitempty\" json:\"bodyFromFile,omitempty\"`\n}\n```\nRequest represents a HTTP request\n\n```go\nfunc (r *Request) GetBody() (reader io.Reader, err error)\n```\nGetBody returns the request body\n\n```go\nfunc (r *Request) Render(ctx interface{}, dataDir string) (err error)\n```\nRender injects the template based context\n\n```go\nfunc (r *Request) RenderAPI(base string)\n```\nRenderAPI will combine with the base API\n\n```go\ntype RequestBody struct {\n\tValue string `json:\"value\" yaml:\"value\"`\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewRequestBody(val string) RequestBody\n```\n\n```go\nfunc (e RequestBody) Bytes() (data []byte)\n```\n\n```go\nfunc (e RequestBody) IsEmpty() bool\n```\n\n```go\nfunc (e RequestBody) MarshalYAML() (val interface{}, err error)\n```\n\n```go\nfunc (e RequestBody) String() string\n```\n\n```go\nfunc (e *RequestBody) UnmarshalYAML(unmarshal func(interface{}) error) (err error)\n```\n\n```go\ntype Response struct {\n\tStatusCode        int                    `yaml:\"statusCode,omitempty\" json:\"statusCode,omitempty\"`\n\tBody              string                 `yaml:\"body,omitempty\" json:\"body,omitempty\"`\n\tHeader            map[string]string      `yaml:\"header,omitempty\" json:\"header,omitempty\"`\n\tBodyFieldsExpect  map[string]interface{} `yaml:\"bodyFieldsExpect,omitempty\" json:\"bodyFieldsExpect,omitempty\"`\n\tVerify            []string               `yaml:\"verify,omitempty\" json:\"verify,omitempty\"`\n\tConditionalVerify []ConditionalVerify    `yaml:\"conditionalVerify,omitempty\" json:\"conditionalVerify,omitempty\"`\n\tSchema            string                 `yaml:\"schema,omitempty\" json:\"schema,omitempty\"`\n}\n```\nResponse is the expected response\n\n```go\nfunc (r Response) GetBody() string\n```\n\n```go\nfunc (r Response) GetBodyFieldsExpect() map[string]interface{}\n```\n\n```go\nfunc (r *Response) Render(ctx interface{}) (err error)\n```\nRender renders the response\n\n```go\ntype Secure struct {\n\tInsecure   bool   `yaml:\"insecure,omitempty\" json:\"insecure,omitempty\"`\n\tCertFile   string `yaml:\"cert,omitempty\" json:\"cert,omitempty\"`\n\tCAFile     string `yaml:\"ca,omitempty\" json:\"ca,omitempty\"`\n\tKeyFile    string `yaml:\"key,omitempty\" json:\"key,omitempty\"`\n\tServerName string `yaml:\"serverName,omitempty\" json:\"serverName,omitempty\"`\n}\n```\n\n```go\ntype SortedKeysStringMap map[string]interface{}\n```\n\n```go\nfunc (m SortedKeysStringMap) GetValue(key string) string\n```\n\n```go\nfunc (m SortedKeysStringMap) GetVerifier(key string) (verifier *Verifier)\n```\n\n```go\nfunc (m SortedKeysStringMap) Keys() (keys []string)\n```\n\n```go\ntype Store struct {\n\tName        string\n\tOwner       string\n\tKind        StoreKind\n\tDescription string\n\tURL         string\n\tUsername    string\n\tPassword    string\n\tReadOnly    bool\n\tDisabled    bool\n\tProperties  map[string]string\n}\n```\n\n```go\nfunc MapToStore(data map[string]string) (store Store)\n```\n\n```go\nfunc (s *Store) ToMap() (result map[string]string)\n```\n\n```go\ntype StoreConfig struct {\n\tStores     []Store     `yaml:\"stores\"`\n\tPlugins    []StoreKind `yaml:\"plugins\"`\n\tExtensions []StoreKind `yaml:\"items\"`\n}\n```\n\n```go\ntype StoreGetterAndSetter interface {\n\tGetStores() (stores []Store, err error)\n\tGetStoresByOwner(owner string) (stores []Store, err error)\n\tGetStore(name string) (store *Store, err error)\n\tDeleteStore(name string) (err error)\n\tUpdateStore(store Store) (err error)\n\tCreateStore(store Store) (err error)\n\n\tGetStoreKinds() (kinds []StoreKind, err error)\n}\n```\n\n```go\nfunc NewStoreFactory(configDir string) StoreGetterAndSetter\n```\nNewStoreFactory creates a new store factory\n\n```go\ntype StoreKind struct {\n\tName         string\n\tDependencies []StoreKindDependency\n\tURL          string\n\tParams       []StoreKindParam\n\tLink         string\n\tEnabled      bool\n\tCategories   []string\n}\n```\nStoreKind represents a gRPC-based store\n\n```go\ntype StoreKindDependency struct {\n\tName string\n}\n```\n\n```go\ntype StoreKindParam struct {\n\tKey          string\n\tDefaultValue string\n\tEnum         []string\n\tDescription  string\n}\n```\n\n```go\ntype StoreWriterFactory interface {\n\tNewInstance(store Store) (writer Writer, err error)\n}\n```\n\n```go\ntype TestCase struct {\n\tID      string   `yaml:\"id,omitempty\" json:\"id,omitempty\"`\n\tName    string   `yaml:\"name,omitempty\" json:\"name,omitempty\"`\n\tGroup   string   `yaml:\"group,omitempty\" json:\"group,omitempty\"`\n\tBefore  *Job     `yaml:\"before,omitempty\" json:\"before,omitempty\"`\n\tAfter   *Job     `yaml:\"after,omitempty\" json:\"after,omitempty\"`\n\tRequest Request  `yaml:\"request\" json:\"request\"`\n\tExpect  Response `yaml:\"expect,omitempty\" json:\"expect,omitempty\"`\n}\n```\nTestCase represents a test case\n\n```go\nfunc ParseTestCaseFromData(data []byte) (testCase *TestCase, err error)\n```\nParseTestCaseFromData parses the data to a test case\n\n```go\nfunc (c *TestCase) InScope(items []string) bool\n```\nInScope returns true if the test case is in scope with the given items. Returns true if the items is empty.\n\n```go\ntype TestCaseResult struct {\n\tStatusCode int               `yaml:\"statusCode,omitempty\" json:\"statusCode,omitempty\"`\n\tBody       string            `yaml:\"body,omitempty\" json:\"body,omitempty\"`\n\tHeader     map[string]string `yaml:\"header,omitempty\" json:\"header,omitempty\"`\n\tError      string            `yaml:\"error,omitempty\" json:\"error,omitempty\"`\n\tId         string            `yaml:\"id,omitempty\" json:\"id,omitempty\"`\n\tOutput     string            `yaml:\"output,omitempty\" json:\"output,omitempty\"`\n}\n```\n\n```go\ntype TestResult struct {\n\tMessage        string            `yaml:\"message,omitempty\" json:\"message,omitempty\"`\n\tError          string            `yaml:\"error,omitempty\" json:\"error,omitempty\"`\n\tTestCaseResult []*TestCaseResult `yaml:\"testCaseResult,omitempty\" json:\"testCaseResult,omitempty\"`\n}\n```\n\n```go\ntype TestSuite struct {\n\tName  string            `yaml:\"name,omitempty\" json:\"name,omitempty\"`\n\tAPI   string            `yaml:\"api,omitempty\" json:\"api,omitempty\"`\n\tSpec  APISpec           `yaml:\"spec,omitempty\" json:\"spec,omitempty\"`\n\tParam map[string]string `yaml:\"param,omitempty\" json:\"param,omitempty\"`\n\tItems []TestCase        `yaml:\"items,omitempty\" json:\"items,omitempty\"`\n\tProxy *Proxy            `yaml:\"proxy,omitempty\" json:\"proxy,omitempty\"`\n}\n```\nTestSuite represents a set of test cases\n\n```go\nfunc Parse(data []byte) (testSuite *TestSuite, err error)\n```\nParse parses a file and returns the test suite\n\n```go\nfunc ParseFromData(data []byte) (testSuite *TestSuite, err error)\n```\nParseFromData parses data and returns the test suite\n\n```go\nfunc ParseFromStream(stream io.Reader) (testSuite *TestSuite, err error)\n```\nParseFromStream parses the stream and returns the test suite\n\n```go\nfunc ParseTestSuiteFromFile(suitePath string) (testSuite *TestSuite, err error)\n```\nParseTestSuiteFromFile parses from suite path\n\n```go\nfunc (s *TestSuite) Render(dataContext map[string]interface{}) (err error)\n```\nRender injects the template based context\n\n```go\ntype Verifier struct {\n\tValue     string `yaml:\"value,omitempty\" json:\"value,omitempty\"`\n\tRequired  bool   `yaml:\"required,omitempty\" json:\"required,omitempty\"`\n\tMax       int    `yaml:\"max\"`\n\tMin       int    `yaml:\"min\"`\n\tMaxLength int    `yaml:\"maxLength\"`\n\tMinLength int    `yaml:\"minLength\"`\n}\n```\n\n```go\ntype Writer interface {\n\tLoader\n\n\tListTestCase(suite string) (testcases []TestCase, err error)\n\tGetTestCase(suite, name string) (testcase TestCase, err error)\n\tCreateTestCase(suite string, testcase TestCase) (err error)\n\tUpdateTestCase(suite string, testcase TestCase) (err error)\n\tDeleteTestCase(suite, testcase string) (err error)\n\n\tListHistoryTestSuite() (suites []HistoryTestSuite, err error)\n\tCreateHistoryTestCase(testcaseResult TestCaseResult, suite *TestSuite, historyHeader map[string]string) (err error)\n\tGetHistoryTestCaseWithResult(id string) (historyTestCase HistoryTestResult, err error)\n\tGetHistoryTestCase(id string) (historyTestCase HistoryTestCase, err error)\n\tDeleteHistoryTestCase(id string) (err error)\n\tDeleteAllHistoryTestCase(suite, name string) (err error)\n\tRenameTestCase(suite, oldName, newName string) (err error)\n\tGetTestCaseAllHistory(suite, name string) (historyTestCase []HistoryTestCase, err error)\n\n\tListTestSuite() (suites []TestSuite, err error)\n\tGetTestSuite(name string, full bool) (suite TestSuite, err error)\n\tGetTestSuiteYaml(name string) (testSuiteYaml []byte, err error)\n\tCreateSuite(name, api string) (err error)\n\tGetSuite(name string) (*TestSuite, string, error)\n\tUpdateSuite(TestSuite) (err error)\n\tDeleteSuite(name string) (err error)\n\tRenameTestSuite(oldName, newName string) error\n\tClose()\n}\n```\n\n```go\nfunc NewFileWriter(parent string) Writer\n```\n\n```go\nfunc NewNonWriter() Writer\n```\n\n","path":"github.com/linuxsuren/api-testing/pkg/testing","name":"testing","synopsis":"","isRedistributable":true}
