Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Sep 12, 2017
1 parent 9ce5be5 commit 51cd8cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package handlers

import (
// "encoding/hex"
// "errors"
"net/http"
"net/http/httptest"
// "net/url"
"strings"
"testing"

"github.com/facebookgo/inject"
. "github.com/smartystreets/goconvey/convey"
"github.com/stellar/gateway/bridge/config"
"github.com/stellar/gateway/horizon"
Expand All @@ -21,31 +17,20 @@ import (

func TestRequestHandlerBuilder(t *testing.T) {
c := &config.Config{NetworkPassphrase: "Test SDF Network ; September 2015"}

mockHorizon := new(mocks.MockHorizon)
mockHTTPClient := new(mocks.MockHTTPClient)
mockTransactionSubmitter := new(mocks.MockTransactionSubmitter)
mockFederationResolver := new(mocks.MockFederationResolver)
mockStellartomlResolver := new(mocks.MockStellartomlResolver)
requestHandler := RequestHandler{}

// Inject mocks
var g inject.Graph

err := g.Provide(
&inject.Object{Value: &requestHandler},
&inject.Object{Value: c},
&inject.Object{Value: mockHorizon},
&inject.Object{Value: mockHTTPClient},
&inject.Object{Value: mockTransactionSubmitter},
&inject.Object{Value: mockFederationResolver},
&inject.Object{Value: mockStellartomlResolver},
)
if err != nil {
panic(err)
}

if err := g.Populate(); err != nil {
panic(err)
requestHandler := RequestHandler{
Config: c,
Client: mockHTTPClient,
Horizon: mockHorizon,
TransactionSubmitter: mockTransactionSubmitter,
FederationResolver: mockFederationResolver,
StellarTomlResolver: mockStellartomlResolver,
}

testServer := httptest.NewServer(http.HandlerFunc(requestHandler.Builder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"testing"

"github.com/facebookgo/inject"
. "github.com/smartystreets/goconvey/convey"
"github.com/stellar/gateway/bridge/config"
"github.com/stellar/gateway/horizon"
Expand Down Expand Up @@ -37,26 +36,14 @@ func TestRequestHandlerPayment(t *testing.T) {
mockTransactionSubmitter := new(mocks.MockTransactionSubmitter)
mockFederationResolver := new(mocks.MockFederationResolver)
mockStellartomlResolver := new(mocks.MockStellartomlResolver)
requestHandler := RequestHandler{}

// Inject mocks
var g inject.Graph

err := g.Provide(
&inject.Object{Value: &requestHandler},
&inject.Object{Value: c},
&inject.Object{Value: mockHorizon},
&inject.Object{Value: mockHTTPClient},
&inject.Object{Value: mockTransactionSubmitter},
&inject.Object{Value: mockFederationResolver},
&inject.Object{Value: mockStellartomlResolver},
)
if err != nil {
panic(err)
}

if err := g.Populate(); err != nil {
panic(err)
requestHandler := RequestHandler{
Config: c,
Client: mockHTTPClient,
Horizon: mockHorizon,
TransactionSubmitter: mockTransactionSubmitter,
FederationResolver: mockFederationResolver,
StellarTomlResolver: mockStellartomlResolver,
}

testServer := httptest.NewServer(http.HandlerFunc(requestHandler.Payment))
Expand Down
16 changes: 16 additions & 0 deletions src/github.com/stellar/gateway/mocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ func (m *MockRepository) GetReceivedPaymentByOperationID(operationID int64) (*en
return a.Get(0).(*entities.ReceivedPayment), a.Error(1)
}

func (m *MockRepository) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPayment, error) {
a := m.Called(page, limit)
if a.Get(0) == nil {
return nil, a.Error(1)
}
return a.Get(0).([]*entities.ReceivedPayment), a.Error(1)
}

func (m *MockRepository) GetSentTransactions(page, limit int) ([]*entities.SentTransaction, error) {
a := m.Called(page, limit)
if a.Get(0) == nil {
return nil, a.Error(1)
}
return a.Get(0).([]*entities.SentTransaction), a.Error(1)
}

// MockSignerVerifier ...
type MockSignerVerifier struct {
mock.Mock
Expand Down

0 comments on commit 51cd8cf

Please sign in to comment.