Skip to content

Commit

Permalink
Go module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Michael committed Aug 7, 2019
1 parent c3d913a commit 001aabf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.10
- image: circleci/golang:1.12
environment:
GO111MODULE: "on"
working_directory: /go/src/github.com/jesse0michael/go-rest-assured
steps:
- checkout
- run:
name: Install Dependencies
command: |
go get -u -v -t github.com/Masterminds/glide
go get -v golang.org/x/tools/cmd/cover
go get -v github.com/mattn/goveralls
go get -v github.com/modocache/gover
make install-deps
- run:
name: Build & Test
command: |
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ endif
LDFLAGS = -ldflags '-X main.gitSHA=$(shell git rev-parse HEAD)'

all: build test cover
install-deps:
glide install
build:
if [ ! -d bin ]; then mkdir bin; fi
$(GO) build $(LDFLAGS) -v -o bin/go-rest-assured
fmt:
find . -not -path "./vendor/*" -name '*.go' -type f | sed 's#\(.*\)/.*#\1#' | sort -u | xargs -n1 -I {} bash -c "cd {} && goimports -w *.go && gofmt -w -l -s *.go"
gofmt -w -l -s *.go
test:
if [ ! -d $(COVERAGEDIR) ]; then mkdir $(COVERAGEDIR); fi
$(GO) test -v ./assured -cover -coverprofile=$(COVERAGEDIR)/assured.coverprofile
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# GO REST ASSURED

[![CircleCI](https://circleci.com/gh/Jesse0Michael/go-rest-assured.svg?style=svg&circle-token=afd5de8a46297d388679dcfc404d4bcc4eceab7a)](https://circleci.com/gh/Jesse0Michael/go-rest-assured) [![Coverage Status](https://coveralls.io/repos/github/Jesse0Michael/go-rest-assured/badge.svg?branch=master)](https://coveralls.io/github/Jesse0Michael/go-rest-assured?branch=master)

Go Rest Assured is a small service written in GO intended to be used to mock out REST API applications for testing. The concept is based on the [Rest Assured](http://rest-assured.io/) service written in Java and [other languages](https://github.com/artemave/REST-assured)
Expand All @@ -14,17 +15,17 @@ Go-Rest-Assured keeps track of the Assured Calls you have stubbed out and the Ca
- Delay
- Callbacks

Set these fields as a *Given* call through the client or a HTTP request to the service directly and they will be returned from the Go Rest Assured API when you hit the *When* endpoint. The Calls you stub out are uniquely mapped with an identity of their Method and Path. If you stub multiple calls to the same Method and Path, the responses will cycle through your stubs based on the order they were created.
Set these fields as a _Given_ call through the client or a HTTP request to the service directly and they will be returned from the Go Rest Assured API when you hit the _When_ endpoint. The Calls you stub out are uniquely mapped with an identity of their Method and Path. If you stub multiple calls to the same Method and Path, the responses will cycle through your stubs based on the order they were created.

If loading callbacks from a JSON file, the call unmarshaller will attempt to read the resource field as a relative file, or else a quoted string, or else just a byte slice.

## Running

### Standalone
Please have [GO](https://golang.org/) and [Glide](https://github.com/Masterminds/glide) installed on your machine
### Standalone

Please have [GO](https://golang.org/) installed on your machine

1. `go get github.com/jesse0michael/go-rest-assured`
2. `make install-deps`
2. `make build`
3. `bin/go-rest-assured`

Expand All @@ -41,6 +42,7 @@ Usage of bin/go-rest-assured:
```

### Client

```go
import ("github.com/jesse0michael/go-rest-assured/assured")

Expand All @@ -50,6 +52,7 @@ defer client.Close()
```

## Stubbing

To stub out an assured call hit the following endpoint
`/given/{path:.*}`

Expand All @@ -74,9 +77,10 @@ call := assured.Call{
client.Given(call)
```

*If your stubbed endpoint needs to return a different call on a subsequent request, then try stubbing that Method/Path again. The first time you intercept that endpoint the first call will be returned and then moved to the end of the list.*
_If your stubbed endpoint needs to return a different call on a subsequent request, then try stubbing that Method/Path again. The first time you intercept that endpoint the first call will be returned and then moved to the end of the list._

## Intercepting

To use your assured calls hit the following endpoint with the Method/Path that was used to stub the call `/when/{path:.*}`

Or..
Expand All @@ -91,6 +95,7 @@ Go-Rest-Assured will return `404 NotFound` error response when a matching stub i
As requests come in, the will be stored

## Callbacks

To include callbacks from Go-Rest-Assured when a stubbed endpoint is hit, create them by hitting the endpoint `/callbacks`
To create a callbacks you must include the HTTP header `Assured-Callback-Target` with the specified endpoint you want your callbacks to be sent to
You must also include the HTTP header `Assured-Callback-Key` with a key with the call to the `/callbacks` endpoint as well as the `/given/{path:.*}` endpoint that for the stubbed call you want the callback to be associated with
Expand All @@ -103,21 +108,23 @@ call := assured.Call{
Path: "test/assured",
StatusCode: 201,
Method: "POST",
Response: []byte(`{"holler_back":true}`),
Response: []byte(`{"holler_back":true}`),
Callbacks: []assured.Callback{
assured.Callback{
Method: "POST",
Target: "http://localhost:8080/hit/me",
Response: []byte(`holla!!`),
Response: []byte(`holla!!`),
},
},
}
// Stub out an assured call with callbacks
client.Given(call)
```
*You cannot clear out an individual callback when using the assured.Client, but you can `ClearAll()`*

_You cannot clear out an individual callback when using the assured.Client, but you can `ClearAll()`_

## Verifying

To verify the calls made against your go-rest-assured service, use the endpoint `/verify/{path:.*}`

This endpoint returns a list of assured calls made against the matching Method/Path
Expand All @@ -129,20 +136,19 @@ Or..
calls := client.Verify("GET", "test/assured")
```


## Clearing

To clear out the stubbed and made calls for a specific Method/Path, use the endpoint `/clear/{path:.*}`
*Including the HTTP Header `Assured-Callback-Key` will clear all callbacks associated with that key (independent of path)*
_Including the HTTP Header `Assured-Callback-Key` will clear all callbacks associated with that key (independent of path)_

To clear out all stubbed calls on the server, use the endpoint `/clear`

Or..

``` go
```go
// Clears calls for a Method and Path
client.Clear("GET", "test/assured")

// Crears all calls
client.ClearAll()
```

37 changes: 0 additions & 37 deletions glide.lock

This file was deleted.

14 changes: 0 additions & 14 deletions glide.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/jesse0michael/go-rest-assured

go 1.12

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-kit/kit v0.0.0-20180313180314-feff11c78971
github.com/go-logfmt/logfmt v0.3.0
github.com/go-stack/stack v1.7.0
github.com/gorilla/context v1.1.1
github.com/gorilla/handlers v1.3.0
github.com/gorilla/mux v0.0.0-20180120075819-c0091a029979
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/kit v0.0.0-20180313180314-feff11c78971 h1:50o3peBMWL89vZSNzfD9enQUMafqB+QBjWrR9WIhvQw=
github.com/go-kit/kit v0.0.0-20180313180314-feff11c78971/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-stack/stack v1.7.0 h1:S04+lLfST9FvL8dl4R31wVUC/paZp/WQZbLmUgWboGw=
github.com/go-stack/stack v1.7.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/handlers v1.3.0 h1:tsg9qP3mjt1h4Roxp+M1paRjrVBfPSOpBuVclh6YluI=
github.com/gorilla/handlers v1.3.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v0.0.0-20180120075819-c0091a029979 h1:UsXWMy9j+GSCN/I1/Oyc4wGaeW2CDYqeqAkEvWPu+cs=
github.com/gorilla/mux v0.0.0-20180120075819-c0091a029979/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa h1:l8VQbMdmwFH37kOOaWQ/cw24/u8AuBz5lUym13Wcu0Y=
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d h1:YCdGqZILKLGzbyEYbdau30JBEXbKaKYmkBDU5JUW3D0=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

0 comments on commit 001aabf

Please sign in to comment.