mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-21 22:54:48 +01:00
Add simple tear down test method
This commit is contained in:
@@ -91,8 +91,13 @@ func (suite *GetTxTestSuite) SetupSuite() {
|
||||
suite.userToken = userTokens[0]
|
||||
}
|
||||
|
||||
func (suite *GetTxTestSuite) TearDownSuite() {
|
||||
func (suite *GetTxTestSuite) TearDownSuite() {}
|
||||
|
||||
func (suite *GetTxTestSuite) TearDownTest() {
|
||||
err := clearTable("invoices", suite.Service.Config.DatabaseUri)
|
||||
if err != nil {
|
||||
fmt.Printf("Error tearing down test %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *GetTxTestSuite) TestGetOutgoingInvoices() {
|
||||
|
||||
@@ -26,9 +26,9 @@ import (
|
||||
|
||||
func LndHubTestServiceInit() (svc *service.LndhubService, err error) {
|
||||
// change this if you want to run tests using sqlite
|
||||
//dbUri := "file:data_test.db"
|
||||
dbUri := "file:data_test.db"
|
||||
//make sure the datbase is empty every time you run the test suite
|
||||
dbUri := "postgresql://user:password@localhost/lndhub?sslmode=disable"
|
||||
//dbUri := "postgresql://user:password@localhost/lndhub?sslmode=disable"
|
||||
c := &service.Config{
|
||||
DatabaseUri: dbUri,
|
||||
JWTSecret: []byte("SECRET"),
|
||||
@@ -84,6 +84,20 @@ func LndHubTestServiceInit() (svc *service.LndhubService, err error) {
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
// simple method to use in tear down test, there might be a better way
|
||||
func clearTable(table string, dbUri string) error {
|
||||
dbConn, err := db.Open(dbUri)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to database: %w", err)
|
||||
}
|
||||
|
||||
_, err = dbConn.Exec(fmt.Sprintf("DELETE FROM %s", table))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to clear table: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createUsers(svc *service.LndhubService, usersToCreate int) (logins []controllers.CreateUserResponseBody, tokens []string, err error) {
|
||||
logins = []controllers.CreateUserResponseBody{}
|
||||
tokens = []string{}
|
||||
|
||||
Reference in New Issue
Block a user