keploy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 37 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MODE_RECORD keploy.Mode = keploy.MODE_RECORD
	MODE_TEST   keploy.Mode = keploy.MODE_TEST
	MODE_OFF    keploy.Mode = keploy.MODE_OFF
)

Variables

View Source
var (
	RespChannels = map[string]chan bool{}
)

Functions

func AssertTests added in v0.2.0

func AssertTests(t *testing.T)

func CaptureGrpcTC added in v0.7.9

func CaptureGrpcTC(k *Keploy, grpcCtx context.Context, req models.GrpcReq, resp models.GrpcResp)

func CaptureHttpTC added in v0.7.9

func CaptureHttpTC(k *Keploy, r *http.Request, reqBody []byte, resp models.HttpResp, params map[string]string)

func Decode

func Decode(bin []byte, obj interface{}) (interface{}, error)

Decode returns the decoded data by using gob decoder on bin parameter.

func Encode

func Encode(obj interface{}, arr [][]byte, pos int) error

Encode takes obj parameter and encodes its contents into arr parameter. If obj have no exported field then, it returns an error.

func GetMode

func GetMode() keploy.Mode

GetMode returns the mode of the keploy SDK

func GrpCurl added in v0.7.9

func GrpCurl(grpcReq string, id string, port string, method string) error

GrpCurl function acts as a grpc client for the simulate client. It takes grpcRequest json , testcase id, port and request method as its parameter

func Middleware added in v0.4.3

func Middleware(k *Keploy, router Router) error

func NewCustomHandler added in v0.7.9

func ProcessDep

func ProcessDep(ctx context.Context, log *zap.Logger, meta map[string]string, outputs ...interface{}) (bool, []interface{})

ProcessDep is a generic method to encode and decode the outputs of external dependecies. If request is on keploy.MODE_TEST mode, it returns (true, decoded outputs of stored binaries in keploy context). Else in keploy.MODE_RECORD mode, it encodes the outputs of external dependencies and stores in keploy context. Returns (false, nil).

func SetTestMode added in v0.2.0

func SetTestMode()

SetTestMode sets the keploy SDK mode to MODE_TEST

Types

type AppConfig added in v0.2.0

type AppConfig struct {
	Name     string        `validate:"required"`
	Host     string        `default:"localhost"`
	Port     string        `validate:"required"`
	Delay    time.Duration `default:"5s"`
	Timeout  time.Duration `default:"60s"`
	Filter   Filter
	TestPath string `default:""`
	MockPath string `default:""`
}

type BodyDumpResponseWriter added in v0.2.0

type BodyDumpResponseWriter struct {
	io.Writer
	http.ResponseWriter
	Status int
}

func ProcessRequest added in v0.4.0

func (*BodyDumpResponseWriter) Flush added in v0.2.0

func (w *BodyDumpResponseWriter) Flush()

func (*BodyDumpResponseWriter) Hijack added in v0.2.0

func (*BodyDumpResponseWriter) Write added in v0.2.0

func (w *BodyDumpResponseWriter) Write(b []byte) (int, error)

func (*BodyDumpResponseWriter) WriteHeader added in v0.2.0

func (w *BodyDumpResponseWriter) WriteHeader(code int)

type Config added in v0.2.0

type Config struct {
	App    AppConfig
	Server ServerConfig
}

type CustomHandler added in v0.7.9

type CustomHandler struct {
	*grpcurl.DefaultEventHandler
}

func (*CustomHandler) OnReceiveResponse added in v0.7.9

func (h *CustomHandler) OnReceiveResponse(protoiface.MessageV1)

type Filter added in v0.3.1

type Filter struct {
	AcceptUrlRegex string
	HeaderRegex    []string
	Remove         []string
	Replace        map[string]string
	RejectUrlRegex []string
}

type GrpcResp added in v0.7.9

type GrpcResp struct {
	Resp models.GrpcResp
	L    *sync.Mutex
}

type HttpResp

type HttpResp struct {
	Resp models.HttpResp
	L    *sync.Mutex
}

type KError

type KError struct {
	Err error
}

KError stores the error for encoding and decoding as errorString has no exported fields due to gob wasn't able to encode the unexported fields.

func (*KError) Error

func (e *KError) Error() string

Error method returns error string stored in Err field of KError.

func (*KError) GobDecode

func (e *KError) GobDecode(b []byte) error

GobDecode decodes the b([]byte) into error struct.

func (*KError) GobEncode

func (e *KError) GobEncode() ([]byte, error)

GobEncode encodes the Err and returns the binary data.

type Keploy added in v0.2.0

type Keploy struct {
	Ctx context.Context
	Log *zap.Logger
	// contains filtered or unexported fields
}

func New added in v0.2.0

func New(cfg Config) *Keploy

func (*Keploy) Capture added in v0.2.0

func (k *Keploy) Capture(req models.TestCaseReq)

Capture will capture request, response and output of external dependencies by making Call to keploy server.

func (*Keploy) Get added in v0.2.0

func (k *Keploy) Get(id string) *models.TestCase

func (*Keploy) GetClock added in v0.3.6

func (k *Keploy) GetClock(id string) int64

func (*Keploy) GetDependencies added in v0.2.1

func (k *Keploy) GetDependencies(id string) []models.Dependency

func (*Keploy) GetMocks added in v0.6.0

func (k *Keploy) GetMocks(id string) []*proto.Mock

func (*Keploy) GetResp added in v0.2.1

func (k *Keploy) GetResp(id string) HttpResp

func (*Keploy) GetRespGrpc added in v0.7.9

func (k *Keploy) GetRespGrpc(id string) GrpcResp

func (*Keploy) PutResp added in v0.2.1

func (k *Keploy) PutResp(id string, resp HttpResp)

func (*Keploy) PutRespGrpc added in v0.7.9

func (k *Keploy) PutRespGrpc(id string, resp GrpcResp)

func (*Keploy) Test added in v0.2.0

func (k *Keploy) Test()

Test fetches the testcases from the keploy server and current response of API. Then, both of the responses are sent back to keploy's server for comparision.

type Router added in v0.4.3

type Router interface {
	// GetRequest provides access to the current http request object.
	// Example: echo.Context.Request()
	GetRequest() *http.Request
	// SetRequest sets the http request with given request object parameter.
	SetRequest(*http.Request)
	// GetResponseWriter returns current ResponseWriter of the http handler.
	GetResponseWriter() http.ResponseWriter
	// SetResponseWriter sets the ResponseWriter of http handler with given parameter.
	SetResponseWriter(http.ResponseWriter)
	// Context returns the underlying context of the http.Request.
	Context() context.Context
	// Next is used to call the next handler of the middleware chain.
	Next() error
	// GetURLParams returns the url parameter as key:value pair.
	GetURLParams() map[string]string
}

type ServerConfig added in v0.2.0

type ServerConfig struct {
	URL        string `default:"http://localhost:6789/api"`
	LicenseKey string
	AsyncCalls bool
}

Jump to

Keyboard shortcuts

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