Documentation
¶
Index ¶
- Constants
- Variables
- type AMQPMocks
- type Action
- type ActionDispatcher
- type ActionPublishAMQP
- type ActionPublishKafka
- type ActionRedis
- type ActionReplyGRPC
- type ActionReplyHTTP
- type ActionSendHTTP
- type ActionSleep
- type Context
- type Expect
- type ExpectAMQP
- type ExpectGRPC
- type ExpectHTTP
- type ExpectKafka
- type GRPCMocks
- type GRPCRequestResponsePair
- type GRPCService
- type HTTPMocks
- type KafkaMocks
- type KafkaPipelineFunc
- type Mock
- type MockRepo
- type MocksArray
- type OpenMock
- func (om *OpenMock) Load() error
- func (om *OpenMock) ParseEnv()
- func (om *OpenMock) RedisDo(commandName string, args ...interface{}) (reply interface{}, err error)
- func (om *OpenMock) RedisTemplatesStore() string
- func (om *OpenMock) SetRedis()
- func (om *OpenMock) SetupLogrus()
- func (om *OpenMock) SetupRepo()
- func (om *OpenMock) Start()
- func (om *OpenMock) Stop()
- func (om *OpenMock) ToArray() []*Mock
- func (om *OpenMock) ToYAML() []byte
- type RedisDoer
Constants ¶
const ( KindBehavior = "Behavior" KindAbstractBehavior = "AbstractBehavior" KindTemplate = "Template" )
Variables ¶
var DefaultPipelineFunc = func(c Context, in []byte) (out []byte, err error) { return in, nil }
DefaultPipelineFunc directly outputs the in bytes
var GetActualAction = func(action ActionDispatcher) Action { if !structs.IsZero(action.ActionPublishAMQP) { return action.ActionPublishAMQP } if !structs.IsZero(action.ActionSendHTTP) { return action.ActionSendHTTP } if !structs.IsZero(action.ActionReplyHTTP) { return action.ActionReplyHTTP } if !structs.IsZero(action.ActionReplyGRPC) { return action.ActionReplyGRPC } if len(action.ActionRedis) > 0 { return action.ActionRedis } if !structs.IsZero(action.ActionPublishKafka) { return action.ActionPublishKafka } return action.ActionSleep }
Functions ¶
This section is empty.
Types ¶
type ActionDispatcher ¶
type ActionDispatcher struct { Order int `yaml:"order,omitempty"` ActionPublishAMQP ActionPublishAMQP `yaml:"publish_amqp,omitempty"` ActionPublishKafka ActionPublishKafka `yaml:"publish_kafka,omitempty"` ActionRedis ActionRedis `yaml:"redis,omitempty"` ActionReplyHTTP ActionReplyHTTP `yaml:"reply_http,omitempty"` ActionSendHTTP ActionSendHTTP `yaml:"send_http,omitempty"` ActionReplyGRPC ActionReplyGRPC `yaml:"reply_grpc,omitempty"` ActionSleep ActionSleep `yaml:"sleep,omitempty"` }
Action represents actions
type ActionPublishAMQP ¶
type ActionPublishAMQP struct { Exchange string `yaml:"exchange,omitempty"` RoutingKey string `yaml:"routing_key,omitempty"` Payload string `yaml:"payload,omitempty"` PayloadFromFile string `yaml:"payload_from_file,omitempty"` }
ActionPublishAMQP represents publish AMQP action
func (ActionPublishAMQP) Perform ¶
func (a ActionPublishAMQP) Perform(ctx Context) error
type ActionPublishKafka ¶
type ActionPublishKafka struct { Topic string `yaml:"topic,omitempty"` Payload string `yaml:"payload,omitempty"` PayloadFromFile string `yaml:"payload_from_file,omitempty"` }
ActionPublishKafka represents publish kafka action
func (ActionPublishKafka) Perform ¶
func (a ActionPublishKafka) Perform(ctx Context) error
type ActionRedis ¶
type ActionRedis []string
ActionRedis represents a list of redis commands
func (ActionRedis) Perform ¶
func (a ActionRedis) Perform(ctx Context) error
type ActionReplyGRPC ¶ added in v0.3.0
type ActionReplyGRPC struct { Headers map[string]string `yaml:"headers,omitempty"` Payload string `yaml:"payload,omitempty"` PayloadFromFile string `yaml:"payload_from_file,omitempty"` }
ActionReplyGRPC represents reply grpc action
func (ActionReplyGRPC) Perform ¶ added in v0.3.0
func (a ActionReplyGRPC) Perform(ctx Context) error
type ActionReplyHTTP ¶
type ActionReplyHTTP struct { StatusCode int `yaml:"status_code,omitempty"` Headers map[string]string `yaml:"headers,omitempty"` Body string `yaml:"body,omitempty"` BodyFromFile string `yaml:"body_from_file,omitempty"` }
ActionReplyHTTP represents reply http action
func (ActionReplyHTTP) Perform ¶
func (a ActionReplyHTTP) Perform(ctx Context) (err error)
type ActionSendHTTP ¶
type ActionSendHTTP struct { URL string `yaml:"url,omitempty"` Method string `yaml:"method,omitempty"` Headers map[string]string `yaml:"headers,omitempty"` Body string `yaml:"body,omitempty"` BodyFromFile string `yaml:"body_from_file,omitempty"` }
ActionSendHTTP represents the send http action
func (ActionSendHTTP) Perform ¶
func (a ActionSendHTTP) Perform(ctx Context) error
type ActionSleep ¶
ActionSleep represents the sleep action
func (ActionSleep) Perform ¶
func (a ActionSleep) Perform(ctx Context) error
type Context ¶
type Context struct { HTTPContext echo.Context HTTPHeader http.Header HTTPBody string HTTPPath string HTTPQueryString string GRPCService string GRPCMethod string GRPCContext echo.Context GRPCHeader http.Header GRPCPayload string KafkaTopic string KafkaPayload string AMQPExchange string AMQPRoutingKey string AMQPQueue string AMQPPayload string Values map[string]interface{} // contains filtered or unexported fields }
Context represents the context of the mock expectation
func (Context) MatchCondition ¶
MatchCondition checks the condition given the context
type Expect ¶
type Expect struct { Condition string `yaml:"condition,omitempty"` HTTP ExpectHTTP `yaml:"http,omitempty"` Kafka ExpectKafka `yaml:"kafka,omitempty"` AMQP ExpectAMQP `yaml:"amqp,omitempty"` GRPC ExpectGRPC `yaml:"grpc,omitempty"` }
Expect represents what to expect from a mock
type ExpectAMQP ¶
type ExpectAMQP struct { Exchange string `yaml:"exchange,omitempty"` RoutingKey string `yaml:"routing_key,omitempty"` Queue string `yaml:"queue,omitempty"` }
ExpectAMQP represents amqp expectation
type ExpectGRPC ¶ added in v0.3.0
type ExpectGRPC struct { Service string `yaml:"service,omitempty"` Method string `yaml:"method,omitempty"` }
ExpectGRPC represents grpc expectation
type ExpectHTTP ¶
type ExpectHTTP struct { Method string `yaml:"method,omitempty"` Path string `yaml:"path,omitempty"` }
ExpectHTTP represents http expectation
type ExpectKafka ¶
type ExpectKafka struct {
Topic string `yaml:"topic,omitempty"`
}
ExpectKafka represents kafka expectation
type GRPCMocks ¶ added in v0.3.0
type GRPCMocks map[ExpectGRPC]MocksArray
GRPCMocks is keyed by service/method
type GRPCRequestResponsePair ¶ added in v0.3.0
GRPCRequestResponsePair is a pair of proto.Message to define the message schema of request and response of a method
type GRPCService ¶ added in v0.3.0
type GRPCService map[string]GRPCRequestResponsePair
GRPCService is a map of service_name => GRPCRequestResponsePair
type KafkaPipelineFunc ¶
KafkaPipelineFunc defines pipeline functions For example, decode/encode messages
type Mock ¶
type Mock struct { // Common fields Kind string `yaml:"kind,omitempty"` Key string `yaml:"key,omitempty"` Extend string `yaml:"extend,omitempty"` // KindBehavior fields Expect Expect `yaml:"expect,omitempty"` Actions []ActionDispatcher `yaml:"actions,omitempty"` Values map[string]interface{} `yaml:"values,omitempty"` // KindTemplate fields Template string `yaml:"template,omitempty"` }
Mock represents a mock struct swagger:model
type MockRepo ¶
type MockRepo struct { HTTPMocks HTTPMocks GRPCMocks GRPCMocks KafkaMocks KafkaMocks AMQPMocks AMQPMocks Templates MocksArray Behaviors *orderedmap.OrderedMap }
MockRepo stores a repository of Mocks
type MocksArray ¶
type MocksArray []*Mock
MocksArray represents an array of Mocks
func (MocksArray) DoActions ¶
func (ms MocksArray) DoActions(ctx Context)
type OpenMock ¶
type OpenMock struct { LogLevel string `env:"OPENMOCK_LOG_LEVEL" envDefault:"info"` TemplatesDir string `env:"OPENMOCK_TEMPLATES_DIR" envDefault:"./templates"` TemplatesDirHotReload bool `env:"OPENMOCK_TEMPLATES_DIR_HOT_RELOAD" envDefault:"true"` // HTTP channel HTTPEnabled bool `env:"OPENMOCK_HTTP_ENABLED" envDefault:"true"` HTTPPort int `env:"OPENMOCK_HTTP_PORT" envDefault:"9999"` HTTPHost string `env:"OPENMOCK_HTTP_HOST" envDefault:"0.0.0.0"` CorsEnabled bool `env:"OPENMOCK_CORS_ENABLED" envDefault:"false"` // Admin channel AdminHTTPEnabled bool `env:"OPENMOCK_ADMIN_HTTP_ENABLED" envDefault:"true"` AdminHTTPPort int `env:"OPENMOCK_ADMIN_HTTP_PORT" envDefault:"9998"` AdminHTTPHost string `env:"OPENMOCK_ADMIN_HTTP_HOST" envDefault:"0.0.0.0"` // Kafka channel KafkaEnabled bool `env:"OPENMOCK_KAFKA_ENABLED" envDefault:"false"` KafkaClientID string `env:"OPENMOCK_KAFKA_CLIENT_ID" envDefault:"openmock"` KafkaSeedBrokers []string `env:"OPENMOCK_KAFKA_SEED_BROKERS" envDefault:"kafka:9092" envSeparator:","` KafkaSaslUsername string `env:"OPENMOCK_KAFKA_SASL_USERNAME" envDefault:""` KafkaSaslPassword string `env:"OPENMOCK_KAFKA_SASL_PASSWORD" envDefault:""` KafkaTLSEnabled bool `env:"OPENMOCK_KAFKA_TLS_ENABLED" envDefault:"false"` KafkaProducerSeedBrokers []string `env:"OPENMOCK_KAFKA_PRODUCER_SEED_BROKERS" envDefault:"" envSeparator:","` KafkaSaslProducerUsername string `env:"OPENMOCK_KAFKA_SASL_PRODUCER_USERNAME" envDefault:""` KafkaSaslProducerPassword string `env:"OPENMOCK_KAFKA_SASL_PRODUCER_PASSWORD" envDefault:""` KafkaTLSProducerEnabled bool `env:"OPENMOCK_KAFKA_TLS_PRODUCER_ENABLED" envDefault:""` KafkaConsumerSeedBrokers []string `env:"OPENMOCK_KAFKA_CONSUMER_SEED_BROKERS" envDefault:"" envSeparator:","` KafkaSaslConsumerUsername string `env:"OPENMOCK_KAFKA_SASL_CONSUMER_USERNAME" envDefault:""` KafkaSaslConsumerPassword string `env:"OPENMOCK_KAFKA_SASL_CONSUMER_PASSWORD" envDefault:""` KafkaTLSConsumerEnabled bool `env:"OPENMOCK_KAFKA_TLS_CONSUMER_ENABLED" envDefault:""` // AMQP channel AMQPEnabled bool `env:"OPENMOCK_AMQP_ENABLED" envDefault:"false"` AMQPURL string `env:"OPENMOCK_AMQP_URL" envDefault:"amqp://guest:guest@rabbitmq:5672"` // Redis configuration for admin's ephemeral storage or redis commands RedisType string `env:"OPENMOCK_REDIS_TYPE" envDefault:"memory"` RedisURL string `env:"OPENMOCK_REDIS_URL" envDefault:"redis://redis:6379"` // GRPC channel GRPCEnabled bool `env:"OPENMOCK_GRPC_ENABLED" envDefault:"false"` GRPCPort int `env:"OPENMOCK_GRPC_PORT" envDefault:"50051"` GRPCHost string `env:"OPENMOCK_GRPC_HOST" envDefault:"0.0.0.0"` //////////////////////// Customized functions ////////////////////////////////// // KafkaConsumePipelineFunc is a pipeline function run to when consume a message KafkaConsumePipelineFunc KafkaPipelineFunc // KafkaPublishPipelineFunc is a pipeline function run to when produce a message KafkaPublishPipelineFunc KafkaPipelineFunc // GRPCServiceMap is a map of gRPC [service_name => GRPCService] GRPCServiceMap map[string]GRPCService // contains filtered or unexported fields }
OpenMock holds all the configuration of running openmock
func (*OpenMock) ParseEnv ¶
func (om *OpenMock) ParseEnv()
ParseEnv loads env vars into the openmock struct
func (*OpenMock) RedisTemplatesStore ¶
func (*OpenMock) SetRedis ¶
func (om *OpenMock) SetRedis()
SetRedis sets the Redis store for OpenMock
func (*OpenMock) SetupLogrus ¶
func (om *OpenMock) SetupLogrus()
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
pkg
|
|
swagger_gen
|
|
restapi
Package restapi OpenMock OpenMock is a Go service that can mock services in integration tests, staging environment, or anywhere.
|
Package restapi OpenMock OpenMock is a Go service that can mock services in integration tests, staging environment, or anywhere. |