keploy

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 26 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MockPath string
	MockId   = MockLib{/* contains filtered or unexported fields */}
)

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 GetGrpcClient added in v0.6.0

func GetGrpcClient() proto.RegressionServiceClient

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 SetGrpcClient added in v0.5.0

func SetGrpcClient(c proto.RegressionServiceClient)

avoids circular dependency between mock and keploy packages

func SetMode added in v0.2.0

func SetMode(m Mode) error

SetMode sets the keploy SDK mode error is returned if the mode is invalid

func SetPath added in v0.5.0

func SetPath(path string)

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 Context

type Context struct {
	Mode       Mode
	TestID     string
	FileExport bool
	Deps       []models.Dependency
	Mock       []*proto.Mock
}

func GetState

func GetState(ctx context.Context) (*Context, error)

GetState returns value of "KeployContext" key-value pair which is stored in the request context.

type Filter added in v0.3.1

type Filter struct {
	UrlRegex    string
	HeaderRegex []string
}

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 KctxType

type KctxType string
const KCTX KctxType = "KeployContext"

type Keploy added in v0.2.0

type Keploy struct {
	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) models.HttpResp

func (*Keploy) PutResp added in v0.2.1

func (k *Keploy) PutResp(id string, resp models.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 MockLib added in v0.6.0

type MockLib struct {
	// contains filtered or unexported fields
}

func (*MockLib) Load added in v0.6.0

func (m *MockLib) Load(name string)

func (*MockLib) Unique added in v0.6.0

func (m *MockLib) Unique(name string) bool

To avoid creating the duplicate mock yaml file

type Mode added in v0.2.0

type Mode string

Mode represents the mode at which the SDK is operating MODE_RECORD is for recording API calls to generate testcases MODE_TEST is for testing the application on previous recorded testcases MODE_OFF disables keploy SDK automatically from the application

const (
	MODE_RECORD Mode = "record"
	MODE_TEST   Mode = "test"
	MODE_OFF    Mode = "off"
)

func GetMode

func GetMode() Mode

GetMode returns the mode of the keploy SDK

func GetModeFromContext added in v0.2.0

func GetModeFromContext(ctx context.Context) Mode

GetModeFromContext returns the mode on which SDK is configured by accessing environment variable.

func (Mode) Valid added in v0.2.0

func (m Mode) Valid() bool

Valid checks if the provided mode is valid

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
}

Jump to

Keyboard shortcuts

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