/fake-web-service

fake web service for testing purposes

Primary LanguageGoMIT LicenseMIT

fake-web-service

License: MIT GitHub release Go Report Card Pulls Go

This simple web service is made for testing purposes. It has different endpoints that return various results, either a successful response or an error, with different delays. You can configure the endpoints, the delays, and the error rate for each endpoint independently.

Deploy

kubectl apply -f deployments/manifests/kubernetes-deploy.yaml
Pay attention

For development and testing purposes, I use docker images with the dev tag. But I also publish images with tag matching the release version, like 0.1.0. You can find the full list of tags on Docker Hub

Usage

➜ curl localhost:8080/
Available endpoints:
- /good - Good endpoint: Fast enough, no errors at all
- /bad - Bad endpoint: 30% of requests fails with 500 error
- /slow - Slow endpoint: Sometimes it fails, but it is always slow

➜ time curl localhost:8080/good
success: /good
curl localhost:8080/good  0.00s user 0.01s system 4% cpu 0.230 total

➜ time curl localhost:8080/slow
success: /slow
curl localhost:8080/slow  0.01s user 0.01s system 0% cpu 2.822 total

Configuration

Here you can find the config file that I use for development purposes. I believe it is the most detailed configuration possible.

For now, config implements the following options:

listen: 127.0.0.1:8080  # optional, default value = 0.0.0.0:8080

ws_endpoints:                     # only 1 ws endpoint is supported now
  - name: echo                    # optional
    description: WebSocket echo   # optional
    path: /echo                   # required, but will be rewrited to /ws/{{ path }} 
    type: echo                    # required, only "echo" is supported now

http_endpoints:
  - name: Some endpoint             # optional, used in endpoint list on /
    description: Simple description # optional, used in endpoint list on /
    path: /path                     # required
    error_rate: 0.0                 # optional, in range [0.0, 1.0]
    hidden: true                    # optional, do not display on request to /
    do_not_log: true                # optional, do not write access logs
    slowness:                       # required
      min: 10ms                     # required, time duration, should be less than p95
      p95: 50ms                     # required, time duration, should be less than max
      max: 100ms                    # required, time duration