HTTP mocking to test API services for chaos scenarios

Overview

GAOS

HTTP mocking to test API services for chaos scenarios

Apache 2.0 Go Report Build Status GitHub release


Gaos, can create and provide custom mock restful services via using your fully-customizable scenarios and runs them on Docker & Kubernetes & localhost flawlessly.

Warning: Currently in Beta.

asciicast

Features

  • API response mocking
  • Custom behaviour scenarios
  • Create custom actions for each scenario
  • Robust routing
  • Serve static & dynamic responses
  • Duration, Latency, Error scenarios
  • Deploy your services on Docker & K8S
  • ... and much more, explore the Gaos!

Installation

  • Via HomeBrew
$ brew tap trendyol/trendyol-tap
$ brew install gaos
  • Via Go
$ go get -u github.com/Trendyol/gaos 
  • Build on Docker
$ make build

Scenarios

Scenario Explanation
latency Adds extra latency for request
duration Adds duration limit for request
span Executes accept if in the specified time range, ignore otherwise.
rate Executes ignore if reaches the value or on multiples of, accept otherwise.

Actions

Action Explanation
accept Execute if span and rate conditions doesn't match in the specified scenario
ignore Execute if span and rate conditions does match in the specified scenario
direct Specifies which scenario should be handled by next request
result Specifies Result Type that will be return eventually
status Specifies Status Code for given Result Type

Results

Result Explanation
type Result Type of the content
content Definitions the relevant result's content, according to Result Type

Result Type

Result Type Explanation
static Returns json content
file Returns content.type after reading the file in content.path
redirect Sends request to remote content.host and awaits response (reverse proxy)

Usage

Usage:
  gaos [command]

Available Commands:
  help        Help about any command
  run         Run Gaos server on localhost
  start       Start Gaos server on given engine (Docker, K8S)

Flags:
  -h, --help   help for gaos

Run Command

Run Gaos server on your localhost

Usage:
  gaos run [flags]

Flags:
  -x, --execute string    execute scenario services
  -s, --scenario string   scenario file input (default "./scenario.json")

Example:

$ gaos run -s ./examples/example.json

After Gaos server started:

$ go run ./examples/example.go

Start Command

Start Gaos server on given engine (Docker, K8S)

Usage:
  gaos start [flags]

Flags:
  -c, --config string        choose k8s config (default "minikube")
      --cpu string           cpu limit (default "500m")
  -e, --environment string   gaos running environment {docker, k8s} (default "local")
	  --memory string        memory limit (default "500mi")
  -n, --namespace string     choose namespace (default "default")
  -p, --password string      image registry password
  -r, --registry string      image registry
	  --replica string       replica count (default "1")
  -s, --scenario string      scenario file input (default "./scenario.json")
	  --secret string        secret key name
  -t, --timeout string       client timeout (default "5m")
  -u, --username string      image registry username
  • Example: Docker
$ gaos start -e docker -s './examples/example.json'
  • Example: Kubernetes
$ gaos start -e k8s -s './examples/example.json'

Running Tests

Requirements:

$ bats e2e.bats

Known Issues

  • Lack of some unit tests
  • E2E tests are not running on pipeline yet. (Manually: bats e2e.bats)
  • Not tested in Windows yet

TO-DO

  • Add ./docs folder for better documentation
  • Scenario linter - to check rules, keys and paths
  • Remote server config reader
  • API client
  • Envoy support - sidecar feature
  • Consul support - service mesh feature

License

The base project code is licensed under Apache License unless otherwise specified. Please see the LICENSE file for more information.

GAOS

You might also like...
This repository includes consumer driven contract test for provider, unit test and counter api.

This repository includes consumer driven contract test for provider, unit test and counter api.

Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻

Gnomock – tests without mocks 🏗️ Spin up entire dependency stack 🎁 Setup initial dependency state – easily! 🏭 Test against actual, close to product

go-test-trace is like go test but it also generates distributed traces.
go-test-trace is like go test but it also generates distributed traces.

go-test-trace go-test-trace is like go test but it also generates distributed traces. Generated traces are exported in OTLP to a OpenTelemetry collect

Flugel Test Documentation for steps to run and test the automatio
Flugel Test Documentation for steps to run and test the automatio

Flugel Test Documentation Documentation for steps to run and test the automation #Test-01 1 - Local Test Using Terratest (End To End) 1- By runing " t

Test-assignment - Test assignment with golang
Test-assignment - Test assignment with golang

test-assignment We have a two steam of data and we need to save it in the map: I

Tesuto - a little library for testing against HTTP services

tesuto import "github.com/guregu/tesuto" tesuto is a little library for testing

http integration test framework

go-hit hit is an http integration test framework written in golang. It is designed to be flexible as possible, but to keep a simple to use interface f

Simple HTTP integration test framework for Golang

go-itest Hassle-free REST API testing for Go. Installation go get github.com/jefflinse/go-itest Usage Create tests for your API endpoints and run the

Http test server written in Golang.

Dummy Server Http test server written in Golang. Can get any request method and log headers, body, path and remote address. Useful if you need to know

Comments
  • Patched/Fix vulnerable CVE-2022-21221

    Patched/Fix vulnerable CVE-2022-21221

    Describe the sumarry:

    The Trendyol-project use fasthttp before 1.34.0 is vulnerable to Directory Traversal via the ServeFile function, due to improper sanitization. It is possible to be exploited by using a backslash %5c character in the path. Note: This security issue impacts Windows users only.

    CVE-2022-21221 CWE-22 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

    opened by pavkcon 0
  • build(deps): bump github.com/valyala/fasthttp from 1.12.0 to 1.34.0

    build(deps): bump github.com/valyala/fasthttp from 1.12.0 to 1.34.0

    Bumps github.com/valyala/fasthttp from 1.12.0 to 1.34.0.

    Release notes

    Sourced from github.com/valyala/fasthttp's releases.

    v1.34.0

    • 59f94a3 Update github.com/klauspost/compress (#1237) (Mikhail Faraponov)
    • 62c15a5 Don't reset RequestCtx.s (#1234) (Erik Dubbelboer)
    • 7670c6e Fix windows tests (#1235) (Erik Dubbelboer)
    • f54ffa1 feature: Keep the memory usage of the service at a stable level (#1216) (Rennbon)
    • 15262ec Warn about unsafe ServeFile usage (#1228) (Erik Dubbelboer)
    • 1116d03 Fix panic while reading invalid trailers (Erik Dubbelboer)
    • 856ca8e Update dependencies (#1230) (Mikhail Faraponov)
    • 6b5bc7b Add windows support to normalizePath (Erik Dubbelboer)
    • f0b0cfe Don't log ErrBadTrailer by default (Erik Dubbelboer)
    • 6937fee fix: (useless check), skip Response body if http method HEAD (#1224) (Pavel Burak)
    • b85d2a2 Fix http proxy behavior (#1221) (Aoang)
    • ad8a07a RequestHeader support set no default ContentType (#1218) (Jack.Ju)
    • c94581c support configure HostClient (#1214) (lin longhjui)
    • 632e222 Client examples (#1208) (Sergey Ponomarev)
    • 6a3cc23 uri_test.go use example.com for clearness (#1212) (Sergey Ponomarev)
    • 9d665e0 Update dependencies (#1204) (Mikhail Faraponov)
    • 8d7953e Fix scheme check for not yet parsed requests (#1203) (ArminBTVS)

    v1.33.0

    • 61aa8b1 remove redundant code (#1202) (tyltr)
    • 4369776 fix(hijack): reuse RequestCtx (#1201) (Sergio VS)
    • 2aca3e8 fix(hijack): reset userValues after hijack handler execution (#1199) (Sergio VS)
    • 9123060 Updated dependencies (#1194) (Mikhail Faraponov)

    v1.32.0

    • 7eeb00e Make tests less flaky (#1189) (Erik Dubbelboer)
    • d19b872 Update tcpdialer.go (#1188) (Mikhail Faraponov)
    • c727b99 Release UseHostHeader in ReleaseRequest() (#1185) (Tolyar)
    • 6c0518b Fix UseHostHeader for DoTimeout + tests (#1184) (Tolyar)
    • 6b55811 Add MaxIdleWorkerDuration to Server. (#1183) (Kilos Liu)
    • 4517204 Allow to set Host header for Client (#1169) (Tolyar)
    • 258a4c1 fix: reset response after reset user values on keep-alive connections (#1176) (Sergio VS)
    • e9db537 Use %w to wrap errors (#1175) (Erik Dubbelboer)
    • 7db0597 Fix bad request trailer panic (Erik Dubbelboer)
    • 4aadf9a Fix parseTrailer panic (Erik Dubbelboer)
    • da7ff7a Add trailer support (#1165) (ichx)
    • 017f0aa fix: reset request after reset user values on keep-alive connections (#1162) (Sergio VS)
    • 3b117f8 feat: close idle connections when server shutdown (#1155) (ichx)
    • a94a2c3 Remove redundant code (#1154) (ichx)
    • f7c354c Fix race condition in Client.mCleaner (Erik Dubbelboer)
    • c078a9d Add string and bytes buffer convert trick in README (#1151) (ichx)
    • 3ff6aaa uri: isHttps() and isHttp() (#1150) (Sergey Ponomarev)
    • 8febad0 http.go: Request.SetURI() (Fix #1141) (#1148) (Sergey Ponomarev)
    • 2ca01c7 fix: Status Line parsing and writing (#1135) (Shivansh Vij)
    • 931d0a4 Fix lint (Erik Dubbelboer)
    • d613502 use sync.map is better (#1145) (halst)
    • c15e642 Don't run all race tests on windows (#1143) (Erik Dubbelboer)
    • 6006c87 chore (#1137) (tyltr)
    • 6d4db9b Fix race condition in getTCPAddrs (Erik Dubbelboer)

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Trendyol Open Source
Trendyol Open Source
Full-featured test framework for Go! Assertions, mocking, input testing, output capturing, and much more! 🍕

testza ?? Testza is like pizza for Go - you could life without it, but why should you? Get The Module | Documentation | Contributing | Code of Conduct

Marvin Wendt 408 Nov 15, 2022
Robust framework for running complex workload scenarios in isolation, using Go; for integration, e2e tests, benchmarks and more! 💪

e2e Go Module providing robust framework for running complex workload scenarios in isolation, using Go and Docker. For integration, e2e tests, benchma

null 133 Nov 27, 2022
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

gock Versatile HTTP mocking made easy in Go that works with any net/http based stdlib implementation. Heavily inspired by nock. There is also its Pyth

Tom 1.7k Nov 23, 2022
HTTP mocking for Golang

httpmock Easy mocking of http responses from external resources. Install Currently supports Go 1.7 - 1.15. v1 branch has to be used instead of master.

Jared Morse 1.5k Nov 19, 2022
Lightweight HTTP mocking in Go (aka golang)

httpmock This library builds on Go's built-in httptest library, adding a more mockable interface that can be used easily with other mocking tools like

null 78 Nov 2, 2022
A simple and expressive HTTP server mocking library for end-to-end tests in Go.

mockhttp A simple and expressive HTTP server mocking library for end-to-end tests in Go. Installation go get -d github.com/americanas-go/mockhttp Exa

Americanas Go 6 Dec 19, 2021
Go Interface Mocking Tool

Charlatan Percolate's Go Interface Mocking Tool. Please read our introductory blog post. Installation go get github.com/percolate/charlatan Usage c

Percolate 199 Nov 3, 2022
GoMock is a mocking framework for the Go programming language.

gomock GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in other

Go 8.2k Nov 27, 2022
A clipboard-based mocking framework for Go that gets out of your way.

A clipboard-based mocking framework for Go that gets out of your way. This tool has been built with inspiration lovingly taken from Moq, and fuelled b

Roger Guldbrandsen 41 Nov 18, 2022
Interface mocking tool for go generate

Interface mocking tool for go generate. What is Moq? Moq is a tool that generates a struct from any interface. The struct can be used in test code as

Mat Ryer 1.4k Nov 22, 2022