Skip to content

Commit

Permalink
Added TestRestClient and TestCommandableHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
seroukhov committed Apr 23, 2021
1 parent 2399fda commit 811fdf3
Show file tree
Hide file tree
Showing 28 changed files with 149 additions and 118 deletions.
22 changes: 9 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls Golang Changelog
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls for Pip.Services in Go Changelog

## <a name="1.3.0"></a> 1.3.0 (2021-04-33)

### Breaking Changes
* **test** Added TestRestClient
* **test** Added TestCommandableHttpClient

## <a name="1.2.0"></a> 1.2.0 (2021-04-04)

Expand All @@ -10,8 +16,7 @@
## <a name="1.1.3"></a> 1.1.3 (2021-03-15)

### Features
* **services**
Add **correlation_id** and **access_token** to CORS headers
* **services** Added **correlation_id** and **access_token** to CORS headers

## <a name="1.1.0"></a> 1.1.0 (2021-02-21)

Expand All @@ -21,43 +26,36 @@ Add **correlation_id** and **access_token** to CORS headers
## <a name="1.0.13"></a> 1.0.13 (2020-12-10)

### Features

* Fix work with CorrelationID in RestService
* Update dependencies

## <a name="1.0.12"></a> 1.0.12 (2020-12-10)

### Features

* Fix headers in RestClient for properly work with others services


## <a name="1.0.8-1.0.11"></a> 1.0.8-1.0.11 (2020-12-02)

### Features

* Added helper methods to RestOperations
* Change RegisterWithAuth methods
* Changed RegisterWithAuth methods

### Bug Fixes
* Fix authorizer

## <a name="1.0.7"></a> 1.0.7 (2020-11-20)

### Features

* Added swagger support

## <a name="1.0.5-1.0.6"></a> 1.0.5-1.0.6 (2020-11-13)

### Features

* Added helper methods

## <a name="1.0.3-1.0.4"></a> 1.0.3-1.0.4 (2020-11-12)

### Features

* Added helper methods in RestService

### Bug Fixes
Expand All @@ -66,7 +64,6 @@ Add **correlation_id** and **access_token** to CORS headers
## <a name="1.0.1-1.0.2"></a> 1.0.1-1.0.2 (2020-08-05)

### Features

* Added error handler in Call method of RestClient

### Bug Fixes
Expand All @@ -77,7 +74,6 @@ Add **correlation_id** and **access_token** to CORS headers
Initial public release

### Features

* **build** HTTP service factory
* **clients** mechanisms for retrieving connection settings
* **connect** helper module to retrieve connections services and clients
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls Golang
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls for Pip.Services in Go

This module is a part of the [Pip.Services](http://pipservices.org) polyglot microservices toolkit.

Expand Down
15 changes: 0 additions & 15 deletions test/IDummyController.go

This file was deleted.

15 changes: 15 additions & 0 deletions test/TestCommandableHttpClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test

import (
"github.com/pip-services3-go/pip-services3-rpc-go/clients"
)

type TestCommandableHttpClient struct {
clients.CommandableHttpClient
}

func NewTestCommandableHttpClient(baseRoute string) *TestCommandableHttpClient {
c := &TestCommandableHttpClient{}
c.CommandableHttpClient = *clients.NewCommandableHttpClient(baseRoute)
return c
}
16 changes: 16 additions & 0 deletions test/TestRestClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test

import (
"github.com/pip-services3-go/pip-services3-rpc-go/clients"
)

type TestRestClient struct {
clients.RestClient
}

func NewTestRestClient(baseRoute string) *TestRestClient {
c := &TestRestClient{}
c.RestClient = *clients.NewRestClient()
c.BaseRoute = baseRoute
return c
}
10 changes: 4 additions & 6 deletions test/clients/DummyClientFixture.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package test_rpc_clients
package test_clients

import (
"testing"

cdata "github.com/pip-services3-go/pip-services3-commons-go/data"
testrpc "github.com/pip-services3-go/pip-services3-rpc-go/test"
tdata "github.com/pip-services3-go/pip-services3-rpc-go/test/data"
"github.com/stretchr/testify/assert"
)

Expand All @@ -18,9 +18,8 @@ func NewDummyClientFixture(client IDummyClient) *DummyClientFixture {
}

func (c *DummyClientFixture) TestCrudOperations(t *testing.T) {

dummy1 := testrpc.Dummy{Id: "", Key: "Key 1", Content: "Content 1"}
dummy2 := testrpc.Dummy{Id: "", Key: "Key 2", Content: "Content 2"}
dummy1 := tdata.Dummy{Id: "", Key: "Key 1", Content: "Content 1"}
dummy2 := tdata.Dummy{Id: "", Key: "Key 2", Content: "Content 2"}

// Create one dummy
dummy, err := c.client.CreateDummy("ClientFixture", dummy1)
Expand Down Expand Up @@ -65,5 +64,4 @@ func (c *DummyClientFixture) TestCrudOperations(t *testing.T) {
values, err := c.client.CheckCorrelationId("test_cor_id")
assert.Nil(t, err)
assert.Equal(t, values["correlationId"], "test_cor_id")

}
24 changes: 12 additions & 12 deletions test/clients/DummyCommandableHttpClient.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package test_rpc_clients
package test_clients

import (
"reflect"

cdata "github.com/pip-services3-go/pip-services3-commons-go/data"
"github.com/pip-services3-go/pip-services3-rpc-go/clients"
testrpc "github.com/pip-services3-go/pip-services3-rpc-go/test"
tdata "github.com/pip-services3-go/pip-services3-rpc-go/test/data"
)

type DummyCommandableHttpClient struct {
Expand All @@ -18,7 +18,7 @@ func NewDummyCommandableHttpClient() *DummyCommandableHttpClient {
return &dchc
}

func (c *DummyCommandableHttpClient) GetDummies(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (result *testrpc.DummyDataPage, err error) {
func (c *DummyCommandableHttpClient) GetDummies(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (result *tdata.DummyDataPage, err error) {

params := cdata.NewEmptyStringValueMap()
c.AddFilterParams(params, filter)
Expand All @@ -28,11 +28,11 @@ func (c *DummyCommandableHttpClient) GetDummies(correlationId string, filter *cd
if calErr != nil {
return nil, calErr
}
result, _ = calValue.(*testrpc.DummyDataPage)
result, _ = calValue.(*tdata.DummyDataPage)
return result, err
}

func (c *DummyCommandableHttpClient) GetDummyById(correlationId string, dummyId string) (result *testrpc.Dummy, err error) {
func (c *DummyCommandableHttpClient) GetDummyById(correlationId string, dummyId string) (result *tdata.Dummy, err error) {

params := cdata.NewEmptyAnyValueMap()
params.Put("dummy_id", dummyId)
Expand All @@ -41,11 +41,11 @@ func (c *DummyCommandableHttpClient) GetDummyById(correlationId string, dummyId
if calErr != nil {
return nil, calErr
}
result, _ = calValue.(*testrpc.Dummy)
result, _ = calValue.(*tdata.Dummy)
return result, err
}

func (c *DummyCommandableHttpClient) CreateDummy(correlationId string, dummy testrpc.Dummy) (result *testrpc.Dummy, err error) {
func (c *DummyCommandableHttpClient) CreateDummy(correlationId string, dummy tdata.Dummy) (result *tdata.Dummy, err error) {

params := cdata.NewEmptyAnyValueMap()
params.Put("dummy", dummy)
Expand All @@ -54,11 +54,11 @@ func (c *DummyCommandableHttpClient) CreateDummy(correlationId string, dummy tes
if calErr != nil {
return nil, calErr
}
result, _ = calValue.(*testrpc.Dummy)
result, _ = calValue.(*tdata.Dummy)
return result, err
}

func (c *DummyCommandableHttpClient) UpdateDummy(correlationId string, dummy testrpc.Dummy) (result *testrpc.Dummy, err error) {
func (c *DummyCommandableHttpClient) UpdateDummy(correlationId string, dummy tdata.Dummy) (result *tdata.Dummy, err error) {

params := cdata.NewEmptyAnyValueMap()
params.Put("dummy", dummy)
Expand All @@ -67,11 +67,11 @@ func (c *DummyCommandableHttpClient) UpdateDummy(correlationId string, dummy tes
if calErr != nil {
return nil, calErr
}
result, _ = calValue.(*testrpc.Dummy)
result, _ = calValue.(*tdata.Dummy)
return result, err
}

func (c *DummyCommandableHttpClient) DeleteDummy(correlationId string, dummyId string) (result *testrpc.Dummy, err error) {
func (c *DummyCommandableHttpClient) DeleteDummy(correlationId string, dummyId string) (result *tdata.Dummy, err error) {

params := cdata.NewEmptyAnyValueMap()
params.Put("dummy_id", dummyId)
Expand All @@ -80,7 +80,7 @@ func (c *DummyCommandableHttpClient) DeleteDummy(correlationId string, dummyId s
if calErr != nil {
return nil, calErr
}
result, _ = calValue.(*testrpc.Dummy)
result, _ = calValue.(*tdata.Dummy)
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion test/clients/DummyCommandableHttpClient_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test_rpc_clients
package test_clients

import (
"testing"
Expand Down
19 changes: 10 additions & 9 deletions test/clients/DummyDirectClient.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package test_rpc_clients
package test_clients

import (
cdata "github.com/pip-services3-go/pip-services3-commons-go/data"
cref "github.com/pip-services3-go/pip-services3-commons-go/refer"
"github.com/pip-services3-go/pip-services3-rpc-go/clients"
testrpc "github.com/pip-services3-go/pip-services3-rpc-go/test"
tdata "github.com/pip-services3-go/pip-services3-rpc-go/test/data"
tlogic "github.com/pip-services3-go/pip-services3-rpc-go/test/logic"
)

type DummyDirectClient struct {
clients.DirectClient
specificController testrpc.IDummyController
specificController tlogic.IDummyController
}

func NewDummyDirectClient() *DummyDirectClient {
Expand All @@ -22,15 +23,15 @@ func NewDummyDirectClient() *DummyDirectClient {
func (c *DummyDirectClient) SetReferences(references cref.IReferences) {
c.DirectClient.SetReferences(references)

specificController, ok := c.Controller.(testrpc.IDummyController)
specificController, ok := c.Controller.(tlogic.IDummyController)
if !ok {
panic("DummyDirectClient: Cant't resolv dependency 'controller' to IDummyController")
}
c.specificController = specificController

}

func (c *DummyDirectClient) GetDummies(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (result *testrpc.DummyDataPage, err error) {
func (c *DummyDirectClient) GetDummies(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (result *tdata.DummyDataPage, err error) {

timing := c.Instrument(correlationId, "dummy.get_page_by_filter")
result, err = c.specificController.GetPageByFilter(correlationId, filter, paging)
Expand All @@ -39,31 +40,31 @@ func (c *DummyDirectClient) GetDummies(correlationId string, filter *cdata.Filte

}

func (c *DummyDirectClient) GetDummyById(correlationId string, dummyId string) (result *testrpc.Dummy, err error) {
func (c *DummyDirectClient) GetDummyById(correlationId string, dummyId string) (result *tdata.Dummy, err error) {

timing := c.Instrument(correlationId, "dummy.get_one_by_id")
result, err = c.specificController.GetOneById(correlationId, dummyId)
timing.EndTiming()
return result, err
}

func (c *DummyDirectClient) CreateDummy(correlationId string, dummy testrpc.Dummy) (result *testrpc.Dummy, err error) {
func (c *DummyDirectClient) CreateDummy(correlationId string, dummy tdata.Dummy) (result *tdata.Dummy, err error) {

timing := c.Instrument(correlationId, "dummy.create")
result, err = c.specificController.Create(correlationId, dummy)
timing.EndTiming()
return result, err
}

func (c *DummyDirectClient) UpdateDummy(correlationId string, dummy testrpc.Dummy) (result *testrpc.Dummy, err error) {
func (c *DummyDirectClient) UpdateDummy(correlationId string, dummy tdata.Dummy) (result *tdata.Dummy, err error) {

timing := c.Instrument(correlationId, "dummy.update")
result, err = c.specificController.Update(correlationId, dummy)
timing.EndTiming()
return result, err
}

func (c *DummyDirectClient) DeleteDummy(correlationId string, dummyId string) (result *testrpc.Dummy, err error) {
func (c *DummyDirectClient) DeleteDummy(correlationId string, dummyId string) (result *tdata.Dummy, err error) {

timing := c.Instrument(correlationId, "dummy.delete_by_id")
result, err = c.specificController.DeleteById(correlationId, dummyId)
Expand Down
2 changes: 1 addition & 1 deletion test/clients/DummyDirectClient_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test_rpc_clients
package test_clients

import (
"testing"
Expand Down
Loading

0 comments on commit 811fdf3

Please sign in to comment.