gmeter

package module
v0.0.0-...-52ff012 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

GMeter License Build Status Coverage Status Go Report Card GoDoc

A simple reverse proxy server that records HTTP requests and replays HTTP responses. GMeter can be used for testing programs that make HTTP requests to third-party services.

Installation

go get github.com/hexdigest/gmeter/cmd/gmeter

Alternatively you can download one of the pre-built executables:

Usage

  -d string
    	cassettes dir (default ".")
  -h	display this help text and exit
  -insecure
    	skip HTTPs checks
  -l string
    	listen address (default "localhost:8080")
  -t string
    	target base URL

Start gmeter:

$ gmeter -t http://github.com 
2018/03/05 00:06:19 started proxy localhost:8080 -> http://github.com

Put gmeter in recording mode:

$ curl -X POST http://localhost:8080/gmeter/record -d'{"cassette": "github_test"}'

Once you see something like:

2018/03/05 00:08:14 started recording of the cassette: github_test

Now you can start recording requests/responses. Lets request github index page:

$ curl http://localhost:8080/ -v
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
< Location: https://github.com/
< Date: Sun, 04 Mar 2018 21:11:25 GMT
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact

Both request and response now recorded and present in the github_test.cassette file that can be replayed. In order to replay a cassette you have to put gmeter in play mode by making following request:

$ curl -X POST http://localhost:8080/gmeter/play -d'{"cassette": "github_test"}'

Now you can request github index page again and get a recorded response from the cassette.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	CassettePath  string
	ListenAddress string
	TargetURL     *url.URL
	Insecure      bool
}

Options contains parsed command line options

func GetOptions

func GetOptions(arguments []string, stdout, stderr io.Writer, exit exitFunc) Options

GetOptions parses arguments and returns Options struct on success, otherwise writes error message to the stderr writer and calls exit function

type RoundTripper

type RoundTripper struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

RoundTripper implements http.RoundTripper instrumented with recording and playing capabilities

func NewRoundTripper

func NewRoundTripper(options Options, logger *log.Logger) *RoundTripper

NewRoundTripper returns a pointer to RoundTripper struct

func (*RoundTripper) Play

func (rt *RoundTripper) Play(w http.ResponseWriter, r *http.Request)

Play stops recording and starts playing a cassette

func (*RoundTripper) Record

func (rt *RoundTripper) Record(w http.ResponseWriter, r *http.Request)

Record starts recording of a cassette

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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