keploy

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

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

func AssertTests(t *testing.T)

func CaptureGrpcTC

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

func CaptureHttpTC

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

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

func Middleware(k *Keploy, router Router) error

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

func SetTestMode()

SetTestMode sets the keploy SDK mode to MODE_TEST

Types

type AppConfig

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

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

func (*BodyDumpResponseWriter) Flush

func (w *BodyDumpResponseWriter) Flush()

func (*BodyDumpResponseWriter) Hijack

func (*BodyDumpResponseWriter) Write

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

func (*BodyDumpResponseWriter) WriteHeader

func (w *BodyDumpResponseWriter) WriteHeader(code int)

type Config

type Config struct {
	App    AppConfig
	Server ServerConfig
}

type CustomHandler

type CustomHandler struct {
	*grpcurl.DefaultEventHandler
}

func (*CustomHandler) OnReceiveResponse

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

type Filter

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

type GrpcResp

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

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

func New

func New(cfg Config) *Keploy

func (*Keploy) Capture

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

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

func (*Keploy) GetClock

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

func (*Keploy) GetDependencies

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

func (*Keploy) GetMocks

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

func (*Keploy) GetResp

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

func (*Keploy) GetRespGrpc

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

func (*Keploy) PutResp

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

func (*Keploy) PutRespGrpc

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

func (*Keploy) Test

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

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

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