generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2c0671
commit b423c3f
Showing
6 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package contacts | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/config" | ||
"github.com/bitcoin-sv/spv-wallet/tests" | ||
"github.com/gin-gonic/gin" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
// TestSuite is for testing the entire package using real/mocked services | ||
type TestSuite struct { | ||
tests.TestSuite | ||
} | ||
|
||
// SetupSuite runs at the start of the suite | ||
func (ts *TestSuite) SetupSuite() { | ||
ts.BaseSetupSuite() | ||
} | ||
|
||
// TearDownSuite runs after the suite finishes | ||
func (ts *TestSuite) TearDownSuite() { | ||
ts.BaseTearDownSuite() | ||
} | ||
|
||
// SetupTest runs before each test | ||
func (ts *TestSuite) SetupTest() { | ||
ts.BaseSetupTest() | ||
|
||
// Load the router & register routes | ||
ts.Router = gin.Default() | ||
require.NotNil(ts.T(), ts.Router) | ||
routes := NewHandler(ts.AppConfig, ts.Services) | ||
routes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion)) | ||
} | ||
|
||
// TearDownTest runs after each test | ||
func (ts *TestSuite) TearDownTest() { | ||
ts.BaseTearDownTest() | ||
} | ||
|
||
// TestTestSuite kick-starts all suite tests | ||
func TestTestSuite(t *testing.T) { | ||
suite.Run(t, new(TestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package contacts | ||
|
||
import "github.com/bitcoin-sv/spv-wallet/engine" | ||
|
||
// CreateContact is the model for creating a contact | ||
type CreateContact struct { | ||
Metadata engine.Metadata `json:"metadata"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package contacts | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestBaseRegisterRoutes will test routes | ||
func (ts *TestSuite) TestRegisterRoutes() { | ||
ts.T().Run("test routes", func(t *testing.T) { | ||
testCases := []struct { | ||
method string | ||
url string | ||
}{ | ||
{"POST", "/" + config.APIVersion + "/contact"}, | ||
} | ||
|
||
ts.Router.Routes() | ||
|
||
for _, testCase := range testCases { | ||
found := false | ||
for _, routeInfo := range ts.Router.Routes() { | ||
if testCase.url == routeInfo.Path && testCase.method == routeInfo.Method { | ||
assert.NotNil(t, routeInfo.HandlerFunc) | ||
found = true | ||
break | ||
} | ||
} | ||
assert.True(t, found) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters