Skip to content

Commit

Permalink
All tests operational again good to go.
Browse files Browse the repository at this point in the history
Slowly cleaning out the cruft, making it useful for all the things.

Signed-off-by: quobix <[email protected]>
  • Loading branch information
daveshanley committed Nov 25, 2023
1 parent 5795955 commit 02a12a5
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 116 deletions.
8 changes: 0 additions & 8 deletions bridge/broker_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ func TestBrokerConnector_BadConfig(t *testing.T) {
"Missing address from config",
&BrokerConnectorConfig{Username: "guest", Password: "guest"},
fmt.Errorf("config invalid, config missing server address")},
{
"Missing username from config",
&BrokerConnectorConfig{ServerAddr: "somewhere:000"},
fmt.Errorf("config invalid, config missing username")},
{
"Missing password from config",
&BrokerConnectorConfig{Username: "hi", ServerAddr: "somewhere:000"},
fmt.Errorf("config invalid, config missing password")},
}

for _, tc := range tt {
Expand Down
11 changes: 11 additions & 0 deletions bus/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package bus

import (
"context"
"github.com/go-stomp/stomp/v3/frame"
"github.com/google/uuid"
"github.com/pb33f/ranch/bridge"
Expand Down Expand Up @@ -247,6 +248,16 @@ type MockBridgeConnection struct {
Id *uuid.UUID
}

func (c *MockBridgeConnection) Conversation(destination string, payload []byte, opts ...func(*frame.Frame) error) (bridge.Subscription, error) {
//TODO implement me
panic("implement me")
}

func (c *MockBridgeConnection) RequestResponse(ctx context.Context, payload []byte, opts ...func(*frame.Frame) error) (*model.Message, error) {
//TODO implement me
panic("implement me")
}

func (c *MockBridgeConnection) GetId() *uuid.UUID {
return c.Id
}
Expand Down
4 changes: 2 additions & 2 deletions bus/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ func (bus *transportEventBus) StartFabricEndpoint(
connectionListener stompserver.RawConnectionListener, config EndpointConfig) error {

if bus.fabEndpoint != nil {
return nil
// return fmt.Errorf("unable to start: fabric endpoint is already running")
//return nil
return fmt.Errorf("unable to start: fabric endpoint is already running")
}
if configErr := config.validate(); configErr != nil {
return configErr
Expand Down
16 changes: 8 additions & 8 deletions bus/fabric_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ func TestFabricEndpoint_BridgeMessage(t *testing.T) {

id1 := uuid.New()
req1, _ := json.Marshal(model.Request{
Request: "test-request",
Payload: "test-rq",
Id: &id1,
RequestCommand: "test-request",
Payload: "test-rq",
Id: &id1,
})

wg.Add(1)
Expand All @@ -363,9 +363,9 @@ func TestFabricEndpoint_BridgeMessage(t *testing.T) {

id2 := uuid.New()
req2, _ := json.Marshal(model.Request{
Request: "test-request2",
Payload: "test-rq2",
Id: &id2,
RequestCommand: "test-request2",
Payload: "test-rq2",
Id: &id2,
})

wg.Wait()
Expand All @@ -378,14 +378,14 @@ func TestFabricEndpoint_BridgeMessage(t *testing.T) {

receivedReq := messages[0].Payload.(*model.Request)

assert.Equal(t, receivedReq.Request, "test-request")
assert.Equal(t, receivedReq.RequestCommand, "test-request")
assert.Equal(t, receivedReq.Payload, "test-rq")
assert.Equal(t, *receivedReq.Id, id1)
assert.Nil(t, receivedReq.BrokerDestination)

receivedReq2 := messages[1].Payload.(*model.Request)

assert.Equal(t, receivedReq2.Request, "test-request2")
assert.Equal(t, receivedReq2.RequestCommand, "test-request2")
assert.Equal(t, receivedReq2.Payload, "test-rq2")
assert.Equal(t, *receivedReq2.Id, id2)
assert.Equal(t, receivedReq2.BrokerDestination.ConnectionId, "con2")
Expand Down
108 changes: 54 additions & 54 deletions bus/store_sync_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ func TestStoreSyncService_OpenStoreErrors(t *testing.T) {
id := uuid.New()
bus.SendRequestMessage(syncChan, "invalid-request", nil)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: "invalid-payload",
Id: &id,
RequestCommand: openStoreRequest,
Payload: "invalid-payload",
Id: &id,
}, nil)

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
RequestCommand: openStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
}, nil)
wg.Wait()

Expand All @@ -72,9 +72,9 @@ func TestStoreSyncService_OpenStoreErrors(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "non-existing-store"},
Id: &id,
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "non-existing-store"},
Id: &id,
}, nil)
wg.Wait()

Expand Down Expand Up @@ -111,8 +111,8 @@ func TestStoreSyncService_OpenStore(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
wg.Wait()

Expand All @@ -135,8 +135,8 @@ func TestStoreSyncService_OpenStore(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
wg.Wait()

Expand All @@ -157,8 +157,8 @@ func TestStoreSyncService_OpenStore(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan2, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
wg.Wait()

Expand Down Expand Up @@ -230,33 +230,33 @@ func TestStoreSyncService_CloseStore(t *testing.T) {

wg.Add(2)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
bus.SendRequestMessage(syncChan2, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
wg.Wait()

assert.Equal(t, len(service.syncStoreListeners["test-store"].clientSyncChannels), 2)

bus.SendRequestMessage(syncChan, &model.Request{
Request: closeStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
RequestCommand: closeStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
}, nil)

wg.Add(2)
bus.SendRequestMessage(syncChan, &model.Request{
Request: closeStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
RequestCommand: closeStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
}, nil)
bus.SendRequestMessage(syncChan2, &model.Request{
Request: closeStoreRequest,
Payload: map[string]interface{}{"storeId": ""},
Id: &id,
RequestCommand: closeStoreRequest,
Payload: map[string]interface{}{"storeId": ""},
Id: &id,
}, nil)
wg.Wait()

Expand All @@ -272,21 +272,21 @@ func TestStoreSyncService_CloseStore(t *testing.T) {
service.lock.Unlock()

bus.SendRequestMessage(syncChan2, &model.Request{
Request: closeStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
RequestCommand: closeStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
}, nil)

wg.Add(2)
bus.SendRequestMessage(syncChan2, &model.Request{
Request: closeStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
RequestCommand: closeStoreRequest,
Payload: make(map[string]interface{}),
Id: &id,
}, nil)
bus.SendRequestMessage(syncChan, &model.Request{
Request: closeStoreRequest,
Payload: map[string]interface{}{"storeId": ""},
Id: &id,
RequestCommand: closeStoreRequest,
Payload: map[string]interface{}{"storeId": ""},
Id: &id,
}, nil)
wg.Wait()

Expand Down Expand Up @@ -323,29 +323,29 @@ func TestStoreSyncService_UpdateStoreErrors(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
Payload: map[string]interface{}{},
Id: &id,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{},
Id: &id,
}, nil)
wg.Wait()

assert.Equal(t, syncResp[0].(*model.Response).ErrorMessage, "Invalid UpdateStoreRequest: missing storeId")

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
Id: &id,
}, nil)
wg.Wait()

assert.Equal(t, syncResp[1].(*model.Response).ErrorMessage, "Invalid UpdateStoreRequest: missing itemId")

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store", "itemId": "item1"},
Id: &id,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store", "itemId": "item1"},
Id: &id,
}, nil)
wg.Wait()

Expand Down Expand Up @@ -392,12 +392,12 @@ func TestStoreSyncService_UpdateStore(t *testing.T) {

wg.Add(2)
bus.SendRequestMessage(syncChan, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
bus.SendRequestMessage(syncChan2, &model.Request{
Request: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
RequestCommand: openStoreRequest,
Payload: map[string]interface{}{"storeId": "test-store"},
}, nil)
wg.Wait()

Expand All @@ -407,7 +407,7 @@ func TestStoreSyncService_UpdateStore(t *testing.T) {
wg.Add(2)

bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{
"storeId": "test-store",
"itemId": "item3",
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestStoreSyncService_UpdateStore(t *testing.T) {
assert.Equal(t, syncResp1[3], syncResp2[3])

bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{
"storeId": "test-store",
"itemId": "item4",
Expand All @@ -478,7 +478,7 @@ func TestStoreSyncService_UpdateStore(t *testing.T) {

wg.Add(2)
bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{
"storeId": "test-store",
"itemId": "item3",
Expand All @@ -501,7 +501,7 @@ func TestStoreSyncService_UpdateStore(t *testing.T) {

wg.Add(1)
bus.SendRequestMessage(syncChan, &model.Request{
Request: updateStoreRequest,
RequestCommand: updateStoreRequest,
Payload: map[string]interface{}{
"storeId": "test-store",
"itemId": "item3",
Expand Down
4 changes: 3 additions & 1 deletion model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ func decodeResponsePaylod(resp *Response, typ interface{}) error {
if resp.Error {
return errors.New(resp.ErrorMessage)
}
return mapstructure.Decode(resp.Payload, typ)
err := mapstructure.Decode(resp.Payload, typ)

return err
}
8 changes: 4 additions & 4 deletions model/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMessage_CastPayloadToType_HappyPath(t *testing.T) {

// assert
assert.Nil(t, err)
assert.EqualValues(t, "dummy-value-coming-through", dest.Request)
assert.EqualValues(t, "dummy-value-coming-through", dest.RequestCommand)
}

func TestMessage_CastPayloadToType_BadPayload(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestMessage_CastPayloadToType_BadPayload(t *testing.T) {
// assert
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "failed to unmarshal payload")
assert.NotEqual(t, "dummy-value-coming-through", dest.Request)
assert.NotEqual(t, "dummy-value-coming-through", dest.RequestCommand)
}

func TestMessage_CastPayloadToType_NonPointer(t *testing.T) {
Expand All @@ -48,7 +48,7 @@ func TestMessage_CastPayloadToType_NonPointer(t *testing.T) {

// assert
assert.NotNil(t, err)
assert.NotEqual(t, "dummy-value-coming-through", dest.Request)
assert.NotEqual(t, "dummy-value-coming-through", dest.RequestCommand)
}

func TestMessage_CastPayloadToType_NilPointer(t *testing.T) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestMessage_CastPayloadToType_ErrorResponse(t *testing.T) {
func getNewTestMessage() *Message {
rspPayload := &Response{
Id: &uuid.UUID{},
Payload: Request{Request: "dummy-value-coming-through"},
Payload: Request{RequestCommand: "dummy-value-coming-through"},
}

jsonEncoded, _ := json.Marshal(rspPayload)
Expand Down
2 changes: 1 addition & 1 deletion model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Request struct {
Id *uuid.UUID `json:"id,omitempty"`
Destination string `json:"channel,omitempty"`
Payload interface{} `json:"payload,omitempty"`
RequestCommand string `json:"request,omitempty"`
RequestCommand string `json:"request,omitempty" mapstructure:"request"`
HttpRequest *http.Request `json:"-"`
HttpResponseWriter http.ResponseWriter `json:"-"`
// Populated if the request was sent on a "private" channel and
Expand Down
Loading

0 comments on commit 02a12a5

Please sign in to comment.