Skip to content

Commit

Permalink
Merge pull request #15 from senseyeio/smotes/refactor-json
Browse files Browse the repository at this point in the history
smotes/refactor json
  • Loading branch information
smotes authored Jul 1, 2022
2 parents d9b39c8 + fcd0052 commit 95b12e1
Show file tree
Hide file tree
Showing 10 changed files with 971 additions and 582 deletions.
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ A mountebank API client for the Go programming language.
## Installation

```sh
$ go get -u github.com/senseyeio/mbgo
go get -u github.com/senseyeio/mbgo@latest
```

## Testing

This package includes both unit and integration tests. Use the `unit` and `integration` targets in the Makefile to run them, respectively:

```sh
$ make unit
$ make integration
make unit
make integration
```

The integration tests expect Docker to be available on the host, using it to run a local mountebank container at
Expand Down
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2018 Senseye Ltd. All rights reserved.
// Use of this source code is governed by the MIT License that can be found in the LICENSE file.

// Package mbgo implements a mountebank API client.
package mbgo

import (
Expand Down
154 changes: 139 additions & 15 deletions client_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2018 Senseye Ltd. All rights reserved.
// Use of this source code is governed by the MIT License that can be found in the LICENSE file.

//go:build integration
// +build integration

package mbgo_test
Expand Down Expand Up @@ -138,7 +139,7 @@ func TestClient_Create_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "equals",
Request: mbgo.HTTPRequest{
Request: &mbgo.HTTPRequest{
Method: http.MethodGet,
Path: "/foo",
Query: map[string][]string{
Expand All @@ -153,7 +154,7 @@ func TestClient_Create_Integration(t *testing.T) {
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.HTTPResponse{
Value: &mbgo.HTTPResponse{
StatusCode: http.StatusOK,
Headers: map[string][]string{
"Content-Type": {"application/json"},
Expand Down Expand Up @@ -214,7 +215,7 @@ func TestClient_Create_Integration(t *testing.T) {
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "c2Vjb25kIHJlc3BvbnNl",
},
},
Expand All @@ -223,6 +224,129 @@ func TestClient_Create_Integration(t *testing.T) {
},
},
},
{
Description: "should support nested logical predicates",
Input: mbgo.Imposter{
Proto: "http",
Port: 8080,
Name: "create_test_predicate_nested_logical",
Stubs: []mbgo.Stub{
{
Predicates: []mbgo.Predicate{
{
Operator: "or",
Request: []mbgo.Predicate{
{
Operator: "equals",
Request: mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/foo",
},
},
{
Operator: "equals",
Request: mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/bar",
},
},
{
Operator: "and",
Request: []mbgo.Predicate{
{
Operator: "equals",
Request: mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/baz",
},
},
{
Operator: "equals",
Request: mbgo.HTTPRequest{
Body: "foo",
},
},
},
},
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.HTTPResponse{
StatusCode: http.StatusOK,
},
},
},
},
},
},
Before: func(t *testing.T, mb *mbgo.Client) {
_, err := mb.Delete(newContext(time.Second), 8080, false)
assert.MustOk(t, err)
},
After: func(t *testing.T, mb *mbgo.Client) {
_, err := mb.Delete(newContext(time.Second), 8080, false)
assert.MustOk(t, err)
},
Expected: &mbgo.Imposter{
Proto: "http",
Port: 8080,
Name: "create_test_predicate_nested_logical",
Stubs: []mbgo.Stub{
{
Predicates: []mbgo.Predicate{
{
Operator: "or",
Request: []mbgo.Predicate{
{
Operator: "equals",
Request: &mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/foo",
},
},
{
Operator: "equals",
Request: &mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/bar",
},
},
{
Operator: "and",
Request: []mbgo.Predicate{
{
Operator: "equals",
Request: &mbgo.HTTPRequest{
Method: http.MethodPost,
Path: "/baz",
},
},
{
Operator: "equals",
Request: &mbgo.HTTPRequest{
Body: "foo",
},
},
},
},
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: &mbgo.HTTPResponse{
StatusCode: http.StatusOK,
},
},
},
},
},
},
},
}

for _, c := range cases {
Expand Down Expand Up @@ -325,15 +449,15 @@ func TestClient_Imposter_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "SGVsbG8sIHdvcmxkIQ==",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "Z2l0aHViLmNvbS9zZW5zZXllaW8vbWJnbw==",
},
},
Expand Down Expand Up @@ -449,15 +573,15 @@ func TestClient_AddStub_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "foo",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "bar",
},
},
Expand All @@ -467,15 +591,15 @@ func TestClient_AddStub_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "SGVsbG8sIHdvcmxkIQ==",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "Z2l0aHViLmNvbS9zZW5zZXllaW8vbWJnbw==",
},
},
Expand Down Expand Up @@ -593,15 +717,15 @@ func TestClient_OverwriteStub_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "foo",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "bar",
},
},
Expand Down Expand Up @@ -737,15 +861,15 @@ func TestClient_OverwriteAllStubs_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "foo",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "bar",
},
},
Expand All @@ -755,15 +879,15 @@ func TestClient_OverwriteAllStubs_Integration(t *testing.T) {
Predicates: []mbgo.Predicate{
{
Operator: "endsWith",
Request: mbgo.TCPRequest{
Request: &mbgo.TCPRequest{
Data: "bar",
},
},
},
Responses: []mbgo.Response{
{
Type: "is",
Value: mbgo.TCPResponse{
Value: &mbgo.TCPResponse{
Data: "baz",
},
},
Expand Down
3 changes: 3 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// Copyright (c) 2018 Senseye Ltd. All rights reserved.
// Use of this source code is governed by the MIT License that can be found in the LICENSE file.

// Package mbgo implements a mountebank API client with support for the HTTP and TCP protocols.
package mbgo
Loading

0 comments on commit 95b12e1

Please sign in to comment.