mock

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright 2024-2025 API Testing Authors.

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Copyright 2025 API Testing Authors.

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Copyright 2024 API Testing Authors.

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Copyright 2024 API Testing Authors.

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Copyright 2024 API Testing Authors.

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamicServer

type DynamicServer interface {
	Start(reader Reader, prefix string) error
	SetupHandler(reader Reader, prefix string) (http.Handler, error)
	Stop() error
	GetPort() string
	EnableMetrics()
	Loadable
}

func NewInMemoryServer

func NewInMemoryServer(ctx context.Context, port int) DynamicServer

type InMemoryMetrics added in v0.0.19

type InMemoryMetrics struct {
	MetricData
	// contains filtered or unexported fields
}

InMemoryMetrics implements RequestMetrics with in-memory storage

func NewInMemoryMetrics added in v0.0.19

func NewInMemoryMetrics() *InMemoryMetrics

NewInMemoryMetrics creates a new InMemoryMetrics instance

func (*InMemoryMetrics) AddMetricsHandler added in v0.0.19

func (m *InMemoryMetrics) AddMetricsHandler(mux MetricsHandler)

func (*InMemoryMetrics) GetMetrics added in v0.0.19

func (m *InMemoryMetrics) GetMetrics() MetricData

GetMetrics returns a copy of the current metrics

func (*InMemoryMetrics) RecordRequest added in v0.0.19

func (m *InMemoryMetrics) RecordRequest(path string)

RecordRequest records a request for the given path

type Item

type Item struct {
	Name     string   `yaml:"name" json:"name"`
	Request  Request  `yaml:"request" json:"request"`
	Response Response `yaml:"response" json:"response"`
	Param    map[string]string
}

type Loadable

type Loadable interface {
	Load() error
}

type MetricData added in v0.0.19

type MetricData struct {
	FirstRequestTime time.Time
	LastRequestTime  time.Time
	Requests         map[string]int
}

type MetricsHandler added in v0.0.19

type MetricsHandler interface {
	HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *mux.Route
}

type NoopMetrics added in v0.0.19

type NoopMetrics struct{}

NoopMetrics implements RequestMetrics but does nothing

func NewNoopMetrics added in v0.0.19

func NewNoopMetrics() *NoopMetrics

NewNoopMetrics creates a new NoopMetrics instance

func (*NoopMetrics) AddMetricsHandler added in v0.0.19

func (m *NoopMetrics) AddMetricsHandler(mux MetricsHandler)

AddMetricsHandler implements RequestMetrics but does nothing

func (*NoopMetrics) GetMetrics added in v0.0.19

func (m *NoopMetrics) GetMetrics() MetricData

GetMetrics implements RequestMetrics but returns empty map

func (*NoopMetrics) RecordRequest added in v0.0.19

func (m *NoopMetrics) RecordRequest(path string)

RecordRequest implements RequestMetrics but does nothing

type Object

type Object struct {
	Name      string `yaml:"name" json:"name"`
	InitCount *int   `yaml:"initCount" json:"initCount"`
	Sample    string `yaml:"sample" json:"sample"`
}

type Proxy added in v0.0.18

type Proxy struct {
	Path         string       `yaml:"path" json:"path"`
	Target       string       `yaml:"target" json:"target"`
	RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
}

type Reader

type Reader interface {
	Parse() (*Server, error)
	GetData() []byte
}

type ReaderAndWriter

type ReaderAndWriter interface {
	Reader
	Writer
}

func NewInMemoryReader

func NewInMemoryReader(config string) ReaderAndWriter

func NewLocalFileReader

func NewLocalFileReader(file string) ReaderAndWriter

type Request

type Request struct {
	Path   string            `yaml:"path" json:"path"`
	Method string            `yaml:"method" json:"method"`
	Header map[string]string `yaml:"header" json:"header"`
	Body   string            `yaml:"body" json:"body"`
}

type RequestAmend added in v0.0.19

type RequestAmend struct {
	BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
}

type RequestMetrics added in v0.0.19

type RequestMetrics interface {
	RecordRequest(path string)
	GetMetrics() MetricData
	AddMetricsHandler(MetricsHandler)
}

RequestMetrics represents an interface for collecting request metrics

type RequestWithAuth added in v0.0.19

type RequestWithAuth struct {
	Request   `yaml:",inline"`
	BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
	Username  string `yaml:"username" json:"username"`
	Password  string `yaml:"password" json:"password"`
}

type Response

type Response struct {
	Encoder    string            `yaml:"encoder" json:"encoder"`
	Body       string            `yaml:"body" json:"body"`
	Header     map[string]string `yaml:"header" json:"header"`
	StatusCode int               `yaml:"statusCode" json:"statusCode"`
	BodyData   []byte
}

type Server

type Server struct {
	Objects  []Object  `yaml:"objects" json:"objects"`
	Items    []Item    `yaml:"items" json:"items"`
	Proxies  []Proxy   `yaml:"proxies" json:"proxies"`
	Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
}

type Webhook

type Webhook struct {
	Name    string          `yaml:"name" json:"name"`
	Timer   string          `yaml:"timer" json:"timer"`
	Request RequestWithAuth `yaml:"request" json:"request"`
}

type Writer

type Writer interface {
	Write([]byte)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL