Fake server, Consumer Driven Contracts and help with testing performance from one configuration file with zero system dependencies and no coding whatsoever

Overview

mockingjay server

Build StatusCoverage StatusGoDoc

mj example

Mockingjay lets you define the contract between a consumer and producer and with just a configuration file you get:

  • A fast to launch fake server for your integration tests
  • Configurable to simulate the eratic nature of calling other services
  • Consumer driven contracts (CDCs) to run against your real downstream services.

Mockingjay makes it really easy to check your HTTP integration points. It's fast, requires no coding and is better than other solutions because it will ensure your mock servers and real integration points are consistent so that you never have a green build but failing software.

Running a fake server

---
 - name: My very important integration point
   request:
     uri: /hello
     method: POST
     body: "Chris" # * matches any body
   response:
     code: 200
     body: '{"message": "hello, Chris"}'   # * matches any body
     headers:
       content-type: application/json

# define as many as you need...
$ mockingjay-server -config=example.yaml -port=1234 &
2015/04/13 14:27:54 Serving 3 endpoints defined from example.yaml on port 1234
$ curl http://localhost:1234/hello
{"message": "hello, world"}

Check configuration is compatible with a real server

$ mockingjay-server -config=example.yaml -realURL=http://some-real-api.com
2015/04/13 21:06:06 Test endpoint (GET /hello) is incompatible with http://some-real-api - Couldn't reach real server
2015/04/13 21:06:06 Test endpoint 2 (DELETE /world) is incompatible with http://some-real-api - Couldn't reach real server
2015/04/13 21:06:06 Failing endpoint (POST /card) is incompatible with http://some-real-api - Couldn't reach real server
2015/04/13 21:06:06 At least one endpoint was incompatible with the real URL supplied

This ensures your integration test is working against a reliable fake.

Inspect what requests mockingjay has received

 http://{mockingjayhost}:{port}/requests

Calling this will return you a JSON list of requests

Make your fake server flaky

Mockingjay has an annoying friend, a monkey. Given a monkey configuration you can make your fake service misbehave. This can be useful for performance tests where you want to simulate a more realistic scenario (i.e all integration points are painful).

---
# Writes a different body 50% of the time
- body: "This is wrong :( "
  frequency: 0.5

# Delays initial writing of response by a second 20% of the time
- delay: 1000
  frequency: 0.2

# Returns a 404 30% of the time
- status: 404
  frequency: 0.3

# Write 10,000,000 garbage bytes 9% of the time
- garbage: 10000000
  frequency: 0.09
$ mockingjay-server -config=examples/example.yaml -monkeyConfig=examples/monkey-business.yaml
2015/04/17 14:19:53 Serving 3 endpoints defined from examples/example.yaml on port 9090
2015/04/17 14:19:53 Monkey config loaded
2015/04/17 14:19:53 50% of the time | Body: This is wrong :(
2015/04/17 14:19:53 20% of the time | Delay: 1s
2015/04/17 14:19:53 30% of the time | Status: 404
2015/04/17 14:19:53  9% of the time | Garbage bytes: 10000000

Building

Requirements

Build application

$ go get github.com/quii/mockingjay-server
$ cd $GOPATH/src/github.com/quii/mockingjay-server
$ ./build.sh

MIT license

Issues
  • Writing log messages to stderr

    Writing log messages to stderr

    I'm not familiar with the go language, but it appears log.Printf prints to stderr instead of the expected stdout for info-level log messages. I created a gulp task to start my mock api server when I startup my dev server:

        gulp.task('serve:api', [], function () {
          var serverPath = './linux_amd64_mockingjay-server';
          var mockPath = path.join(__dirname, './mock.yml');
          var mockingjay = spawn(serverPath, ['-config=./mock.yml']);
    
          mockingjay.stdout.on('data', function (data) {
            gutil.log('stdout: ' + data);
          });
    
          mockingjay.stderr.on('data', function (data) {
            gutil.log(gutil.colors.red('[Mockingjay Error]: ' + data));
          });
    
          mockingjay.on('close', function (code) {
            gutil.log('Mockingjay exited with code ' + code);
          });
        });
    

    when running I get the message Serving 2 endpoints defined from ./mock.yml on port 9090 through stderr:

    image

    bug 
    opened by lightswitch05 7
  • Running contract tests against the Producer

    Running contract tests against the Producer

    I understand how I can use this to mock the producer, and run tests on the consumer. But what about the other way around - running tests on the producer against the same contracts and making sure the producer does break them?

    opened by alonpeer 6
  • Be able to define different response body for different response code

    Be able to define different response body for different response code

    So when it's sending 400 response defined in the monkey-business.yaml instead of normal 200, it would be nice to have server return different response body

    opened by jzk 6
  • Added minimal go build as Dockerfile

    Added minimal go build as Dockerfile

    Rather than download a pre-release bin or build it, it seemed simpler to pull an image for now...

    Created first pass container, currently pushed to quay.io/ukhomeofficedigital/mockingj-server (for now).

    opened by lewismarshall 6
  • runtime error: index out of range

    runtime error: index out of range

    panic: runtime error: index out of range
    
    goroutine 20 [running]:
    panic(0x2d5820, 0xc4200121c0)
    	/home/travis/.gimme/versions/go1.7.linux.amd64/src/runtime/panic.go:500 +0x1a1
    github.com/quii/mockingjay-server/vendor/github.com/quii/jsonequaliser.getJSONNodeFromString(0xc420013ee0, 0x2, 0xc4200ce900, 0x2, 0x8)
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/vendor/github.com/quii/jsonequaliser/json.go:14 +0x216
    github.com/quii/mockingjay-server/vendor/github.com/quii/jsonequaliser.IsCompatible(0xc420013ee0, 0x2, 0xc4200ce7e8, 0x2, 0x0, 0xc42002c400, 0xc42000f7c0)
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/vendor/github.com/quii/jsonequaliser/compatability.go:13 +0x39
    github.com/quii/mockingjay-server/mockingjay.checkBody(0xc4200ce7e8, 0x2, 0xc420013ee0, 0x2, 0xc4200ce7e8, 0x2, 0x0)
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/mockingjay/compatibility.go:147 +0xca
    github.com/quii/mockingjay-server/mockingjay.(*CompatibilityChecker).check(0xc4200c2aa0, 0xc420486f18, 0x7fff5fbff712, 0x22, 0x0, 0x0, 0x0)
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/mockingjay/compatibility.go:114 +0x4b2
    github.com/quii/mockingjay-server/mockingjay.(*CompatibilityChecker).compatabilityWorker(0xc4200c2aa0, 0xc420774720, 0x1e, 0x0, 0xc42000b2f0, 0x28, 0x0, 0xc420013ea8, 0x3, 0x0, ...)
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/mockingjay/compatibility.go:70 +0x72
    created by github.com/quii/mockingjay-server/mockingjay.(*CompatibilityChecker).CheckCompatibility
    	/home/travis/gopath/src/github.com/quii/mockingjay-server/mockingjay/compatibility.go:56 +0x2c0
    
    opened by Daniel-ltw 5
  • There were duplicated requests found ...

    There were duplicated requests found ...

    There were duplicated requests found because request body limited 50 bytes https://github.com/quii/mockingjay-server/blob/4a9da103e0c6997bdc069e3cdce5dc09faafcf92/mockingjay/request.go#L154

    opened by tochka 4
  • For the go-uninititated, could you provide a little more installation info please?

    For the go-uninititated, could you provide a little more installation info please?

    Using "go get ...." might have worked (maybe), but I have no $mockingjay-server application available on my terminal after sourcing all various profiles etc. Please can you update with any other steps required. I'm on MAC OS X. Thanks

    opened by mikebrules 4
  • swagger support

    swagger support

    it would be really nice to pass MJ a swagger schema, along with some of the flakiness parameters and have MJ serve the endpoints in the schema according to the specified flakiness.

    enhancement 
    opened by arschles 4
  • Canned Response Headers cannot contain spaces

    Canned Response Headers cannot contain spaces

    Neither the key or the value of the headers in the canned response can contain spaces.

    This blocks using cookies that contain expiry dates.

    The code responsible for this might be in https://github.com/quii/mockingjay-server/blob/master/mockingjay/validationHelpers.go

    Example:

     - name: render Login form
       request:
         uri: /login
         regexuri: \/login.*
         method: GET
       response:
         code: 200
         body: 'non-empty body'
         Set-Cookie: 'Expires=Tue, 28 Apr 2037 13:46:30 GMT'
    
    opened by alvarogarcia7 3
  • Body doesn't seem to be sent in request when doing compatibility check

    Body doesn't seem to be sent in request when doing compatibility check


    - name: Valid login details
      request:
        uri: /user-token
        method: POST
        body: '{"email":"[email protected]","password":"secret"}'
        headers:
         X-Api-Key: supersecret
      response:
        code: 200
        body: '{"token": "1234abc"}'
    
    bug 
    opened by quii 3
  • Proposal: Allow returning simple code results

    Proposal: Allow returning simple code results

    I'd love to randomize the results - no different than allowing simple code execution. In this case, it might look like the following

    
    ---
     - name: Test endpoint
       request:
         uri: /hello
         method: GET
       response:
         code: 200
         body: '{"message": "hello, world", "temperatureOutside": `fmt.Sprintf("%s", rand.Intn(100)))`}'
         headers:
           content-type: text/json
    

    There is a much much much less ugly way to do it than the above, but you get the idea.

    opened by aronchick 3
  • Missing Dependency causing go get failure

    Missing Dependency causing go get failure

    I tried to use go get github.com/quii/mockingjay-server/ as defined in the Installation doc.

    The action fails because it cannot find the package https://github.com/johnmuth/xmlcompare.

    14:03 $ go get github.com/quii/mockingjay-server/
    go: finding module for package github.com/johnmuth/xmlcompare
    go: finding module for package github.com/johnmuth/xmlcompare
    ../../pkg/mod/github.com/quii/[email protected]/mockingjay/compatibility.go:13:2: cannot find module providing package github.com/johnmuth/xmlcompare: module github.com/johnmuth/xmlcompare: git ls-remote -q origin in /Users/dennis.valovcin/go/pkg/mod/cache/vcs/2a071fa2cce3c7382acfab8a0860d125aced727be653d3dcaba277800cbb76b3: exit status 128:
    	fatal: could not read Username for 'https://github.com': terminal prompts disabled
    Confirm the import path was entered correctly.
    If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
    
    opened by maddienotmaddy 1
  • Validate JSON format

    Validate JSON format

    Mockingjay conveniently parses JSON requests, however they are provided in a junky YAML file. Just spent way too much time trying to find an issue, because my request body had an extra " and was not matching request. Would have realised much faster if there was a generic (outside of matching specific request) JSON validation if the request content-type was that.

    opened by oshdev 0
  • Environment variable? API Key?

    Environment variable? API Key?

    Hello!

    Is there a way to have the body read from environment variable?

    We need this for example to add an API KEY inside the yaml file, so we can run the verify against the real API.

    opened by lucaspottersky 1
  • When there are Regex problems, the output doesn't give information about where that problem is

    When there are Regex problems, the output doesn't give information about where that problem is

    Example output:

    service_name                | 2020/04/15 14:49:29 A regex defined in the request does not pass against it's defined URI
    

    Sometimes it can be a bit difficult to figure out which config has the regex issue. Could it be updated so that the output says which config had the issue?

    e.g

    service_name                | 2020/04/15 14:49:29 A regex defined in the request for config 'Name of the config' does not pass against it's defined URI
    
    opened by tamj0rd2 0
  • Make field type error less awful

    Make field type error less awful

    JSON err on field 'counterparts->entities->headquarters->state->value' : Field is not a float in other JSON

    This is nice, but what is the type of the field?

    opened by quii 0
Releases(1.12.0)
Owner
Chris James
Chris James
A repository for the X-Team community to collaborate and learn solutions to most coding challenges to help prepare for their interviews.

Community Coding Challenge Handbook This repository focuses on helping X-Teamers and community members to thrive through coding challenges offering so

X-Team 118 May 7, 2022
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。

English | ???? 中文 ?? Introduction gnet is an event-driven networking framework that is fast and lightweight. It makes direct epoll and kqueue syscalls

Andy Pan 6.6k Jun 30, 2022
High-performance, non-blocking, event-driven, easy-to-use networking framework written in Go, support tls/http1.x/websocket.

High-performance, non-blocking, event-driven, easy-to-use networking framework written in Go, support tls/http1.x/websocket.

lesismal 697 Jun 21, 2022
Brook is a cross-platform strong encryption and not detectable proxy. Zero-Configuration. Brook 是一个跨平台的强加密无特征的代理软件. 零配置.

Brook 中文 v20210401 [GUI] Block list(Ad Block) Bypass & Block rule [GUI] Forward DNS [GUI] OpenWrt GUI client [GUI] Fake DNS [CLI] $ brook tproxy Scrip

TxThinking 13k Jun 27, 2022
A Go package for creating contributor list by release, Help full for those organization that use one repository for platform release

This is a Go package which create contributors list by release by scanning across all repository that exist in organisation, Only helpful for those or

Yuvraj 0 Dec 26, 2021
A pair of local reverse proxies (one in Windows, one in Linux) for Tailscale on WSL2

tailscale-wsl2 TL;DR Running two reverse proxies (one in Windows, one in the WSL2 Linux VM), the Windows Tailscale daemon can be accessed via WSL2: $

Danny Hermes 23 Jun 16, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Aliaksandr Valialkin 17.9k Jun 23, 2022
RFC 1413 compliant fake identd

RFC 1413 compliant fake identd. It is an implementation of the Ident Protocol, but it lies to the clients and always returns fake identities of queried users.

Hyeon Kim (김지현) 2 Jan 30, 2022
“Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server!

Dear Port80 About The Project: “Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server! +---------------------

Abbas Gheydi 5 May 20, 2022
Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik Config Validator Note This is currently pre-release software. traefik-config-validator is a CLI tool to (syntactically) validate your Traefik

Thomas Klinger 0 Dec 16, 2021
Coding challenge for fullstack and backend developer candidates

Backend/API Developer Code Challenge Overview In this task, you will develop a commandline interface for working with a standard todo.txt file. (todo.

null 1 May 13, 2022
DeepCopy a portable app that allows you to copy all forms of specified file types from your entire file system of the computer

DeepCopy a portable app that allows you to copy all forms of specified file types from your entire file system of the computer

subrahmanya  s hegade 1 Dec 20, 2021
Reed-Solomon Erasure Coding in Go

Reed-Solomon Reed-Solomon Erasure Coding in Go, with speeds exceeding 1GB/s/cpu core implemented in pure Go. This is a Go port of the JavaReedSolomon

Klaus Post 1.5k Jun 23, 2022
💥Performance testing tool (Go)

ptg Performance testing tool (Go), It is also a GUI gRPC client. Test the gRPC service like postman. Features Cli performance test support. GUI suppor

crossoverJie 80 Jun 21, 2022
Echo-server - An HTTP echo server designed for testing applications and proxies

echo-server An HTTP echo server designed for testing applications and proxies. R

Erik Cavalcanti 4 Jan 5, 2022
This is a proof of concept (PoC) for creating a QR code system for proving that one has had a valid vaccination record

TestVac QR Core This is a proof of concept (PoC) for creating a QR code system for proving that one has had a valid vaccination record (FHIR, see http

Ministerie van Volksgezondheid, Welzijn en Sport 38 Feb 2, 2022
Ephemeral One Time/Build-Time gRPC TLS PKI system.

PkiSauce Ephemeral Build Time TLS PKI saucing for your intra services GRPC (or not) communications. Description A simple attempt to avoid deploying co

Ermites.IO 5 Jun 17, 2022
Simple web content/proxy server that embodies enterprise zero trust security

pswa - Protected Static Web App Introduction pswa is a simple web content/proxy server which is suitable for various static web apps. Features Availab

YAEGASHI Takeshi 3 Jan 10, 2022