keploy

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 30 Imported by: 6

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 CaptureTestcase added in v0.2.0

func CaptureTestcase(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 Middleware added in v0.4.3

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 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:"0.0.0.0"`
	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 Filter added in v0.3.1

type Filter struct {
	AcceptUrlRegex string
	HeaderRegex    []string
	RejectUrlRegex []string
}

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 regression.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) PutResp added in v0.2.1

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

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

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