{"modulePath":"github.com/linuxsuren/api-testing","version":"v0.0.21","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package mock\n\nCopyright 2024-2025 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 2025 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 2024-2025 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 2024-2025 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 2024-2025 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## Types\n\n```go\ntype DynamicServer interface {\n\tStart(reader Reader, prefix string) error\n\tSetupHandler(reader Reader, prefix string) (http.Handler, error)\n\tWithTLS(certFile, keyFile string) DynamicServer\n\tWithLogWriter(writer io.Writer) DynamicServer\n\tGetTLS() (certFile, keyFile string)\n\tStop() error\n\tGetPort() string\n\tEnableMetrics()\n\tLoadable\n}\n```\n\n```go\nfunc NewInMemoryServer(ctx context.Context, port int) DynamicServer\n```\n\n```go\ntype InMemoryMetrics struct {\n\tMetricData\n\t// contains filtered or unexported fields\n}\n```\nInMemoryMetrics implements RequestMetrics with in-memory storage\n\n```go\nfunc NewInMemoryMetrics() *InMemoryMetrics\n```\nNewInMemoryMetrics creates a new InMemoryMetrics instance\n\n```go\nfunc (m *InMemoryMetrics) AddMetricsHandler(mux MetricsHandler)\n```\n\n```go\nfunc (m *InMemoryMetrics) GetMetrics() MetricData\n```\nGetMetrics returns a copy of the current metrics\n\n```go\nfunc (m *InMemoryMetrics) RecordRequest(path string)\n```\nRecordRequest records a request for the given path\n\n```go\ntype Item struct {\n\tName     string   `yaml:\"name\" json:\"name\"`\n\tRequest  Request  `yaml:\"request\" json:\"request\"`\n\tResponse Response `yaml:\"response\" json:\"response\"`\n\tParam    map[string]interface{}\n}\n```\n\n```go\ntype Loadable interface {\n\tLoad() error\n}\n```\n\n```go\ntype MetricData struct {\n\tFirstRequestTime time.Time\n\tLastRequestTime  time.Time\n\tRequests         map[string]int\n}\n```\n\n```go\ntype MetricsHandler interface {\n\tHandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *mux.Route\n}\n```\n\n```go\ntype NoopMetrics struct{}\n```\nNoopMetrics implements RequestMetrics but does nothing\n\n```go\nfunc NewNoopMetrics() *NoopMetrics\n```\nNewNoopMetrics creates a new NoopMetrics instance\n\n```go\nfunc (m *NoopMetrics) AddMetricsHandler(mux MetricsHandler)\n```\nAddMetricsHandler implements RequestMetrics but does nothing\n\n```go\nfunc (m *NoopMetrics) GetMetrics() MetricData\n```\nGetMetrics implements RequestMetrics but returns empty map\n\n```go\nfunc (m *NoopMetrics) RecordRequest(path string)\n```\nRecordRequest implements RequestMetrics but does nothing\n\n```go\ntype Object struct {\n\tName      string `yaml:\"name\" json:\"name\"`\n\tInitCount *int   `yaml:\"initCount\" json:\"initCount\"`\n\tSample    string `yaml:\"sample\" json:\"sample\"`\n}\n```\n\n```go\ntype Proxy struct {\n\tPrefix       string       `yaml:\"prefix\" json:\"prefix\"`\n\tPort         int          `yaml:\"port\" json:\"port\"`\n\tPath         string       `yaml:\"path\" json:\"path\"`\n\tTarget       string       `yaml:\"target\" json:\"target\"`\n\tRequestAmend RequestAmend `yaml:\"requestAmend\" json:\"requestAmend\"`\n\tProtocol     string       `yaml:\"protocol\" json:\"protocol\"`\n\tEcho         bool         `yaml:\"echo\" json:\"echo\"`\n}\n```\n\n```go\ntype Reader interface {\n\tParse() (*Server, error)\n\tGetData() []byte\n}\n```\n\n```go\ntype ReaderAndWriter interface {\n\tReader\n\tWriter\n}\n```\n\n```go\nfunc NewInMemoryReader(config string) ReaderAndWriter\n```\n\n```go\nfunc NewLocalFileReader(file string) ReaderAndWriter\n```\n\n```go\nfunc NewObjectReader(server *Server) ReaderAndWriter\n```\n\n```go\ntype Request struct {\n\tProtocol     string            `yaml:\"protocol\" json:\"protocol\"`\n\tPath         string            `yaml:\"path\" json:\"path\"`\n\tMethod       string            `yaml:\"method\" json:\"method\"`\n\tHeader       map[string]string `yaml:\"header\" json:\"header\"`\n\tBody         string            `yaml:\"body\" json:\"body\"`\n\tBodyFromFile string            `yaml:\"bodyFromFile\" json:\"bodyFromFile\"`\n}\n```\n\n```go\ntype RequestAmend struct {\n\tBodyPatch string `yaml:\"bodyPatch\" json:\"bodyPatch\"`\n}\n```\n\n```go\ntype RequestMetrics interface {\n\tRecordRequest(path string)\n\tGetMetrics() MetricData\n\tAddMetricsHandler(MetricsHandler)\n}\n```\nRequestMetrics represents an interface for collecting request metrics\n\n```go\ntype RequestWithAuth struct {\n\tRequest   `yaml:\",inline\"`\n\tBearerAPI string `yaml:\"bearerAPI\" json:\"bearerAPI\"`\n\tUsername  string `yaml:\"username\" json:\"username\"`\n\tPassword  string `yaml:\"password\" json:\"password\"`\n}\n```\n\n```go\ntype Response struct {\n\tEncoder      string            `yaml:\"encoder\" json:\"encoder\"`\n\tBody         string            `yaml:\"body\" json:\"body\"`\n\tBodyFromFile string            `yaml:\"bodyFromFile\" json:\"bodyFromFile\"`\n\tHeader       map[string]string `yaml:\"header\" json:\"header\"`\n\tStatusCode   int               `yaml:\"statusCode\" json:\"statusCode\"`\n\tBodyData     []byte\n}\n```\n\n```go\ntype Server struct {\n\tObjects  []Object  `yaml:\"objects\" json:\"objects\"`\n\tItems    []Item    `yaml:\"items\" json:\"items\"`\n\tProxies  []Proxy   `yaml:\"proxies\" json:\"proxies\"`\n\tWebhooks []Webhook `yaml:\"webhooks\" json:\"webhooks\"`\n}\n```\n\n```go\ntype Webhook struct {\n\tName    string            `yaml:\"name\" json:\"name\"`\n\tTimer   string            `yaml:\"timer\" json:\"timer\"`\n\tParam   map[string]string `yaml:\"param\" json:\"param\"`\n\tRequest RequestWithAuth   `yaml:\"request\" json:\"request\"`\n}\n```\n\n```go\ntype Writer interface {\n\tWrite([]byte)\n}\n```\n\n","path":"github.com/linuxsuren/api-testing/pkg/mock","name":"mock","synopsis":"","isRedistributable":true}
