-
Notifications
You must be signed in to change notification settings - Fork 103
[sql-8]: run itests against all DB types #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+239
−15
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a091fc
config: introduce the concept of DevConfig
ellemouton 381d7d1
config: Postgres and SQLite config options for accounts to dev build
ellemouton b6891b4
itest: run itests against chosen backend
ellemouton 5eba328
.github: run itests against all types of account stores
ellemouton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ run: | |
- watchtowerrpc | ||
- neutrinorpc | ||
- peersrpc | ||
- dev | ||
|
||
linters-settings: | ||
govet: | ||
|
This file contains hidden or 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 hidden or 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,117 @@ | ||
//go:build dev | ||
|
||
package terminal | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/lightninglabs/lightning-terminal/accounts" | ||
"github.com/lightninglabs/lightning-terminal/db" | ||
"github.com/lightningnetwork/lnd/clock" | ||
) | ||
|
||
const ( | ||
// DatabaseBackendSqlite is the name of the SQLite database backend. | ||
DatabaseBackendSqlite = "sqlite" | ||
|
||
// DatabaseBackendPostgres is the name of the Postgres database backend. | ||
DatabaseBackendPostgres = "postgres" | ||
|
||
// DatabaseBackendBbolt is the name of the bbolt database backend. | ||
DatabaseBackendBbolt = "bbolt" | ||
|
||
// defaultSqliteDatabaseFileName is the default name of the SQLite | ||
// database file. | ||
defaultSqliteDatabaseFileName = "litd.db" | ||
) | ||
|
||
// defaultSqliteDatabasePath is the default path under which we store | ||
// the SQLite database file. | ||
var defaultSqliteDatabasePath = filepath.Join( | ||
DefaultLitDir, DefaultNetwork, defaultSqliteDatabaseFileName, | ||
) | ||
|
||
// DevConfig is a struct that holds the configuration options for a development | ||
// environment. The purpose of this struct is to hold config options for | ||
// features not yet available in production. Since our itests are built with | ||
// the dev tag, we can test these features in our itests. | ||
// | ||
// nolint:lll | ||
type DevConfig struct { | ||
// DatabaseBackend is the database backend we will use for storing all | ||
// account related data. While this feature is still in development, we | ||
// include the bbolt type here so that our itests can continue to be | ||
// tested against a bbolt backend. Once the full bbolt to SQL migration | ||
// is complete, however, we will remove the bbolt option. | ||
DatabaseBackend string `long:"databasebackend" description:"The database backend to use for storing all account related data." choice:"bbolt" choice:"sqlite" choice:"postgres"` | ||
|
||
// Sqlite holds the configuration options for a SQLite database | ||
// backend. | ||
Sqlite *db.SqliteConfig `group:"sqlite" namespace:"sqlite"` | ||
|
||
// Postgres holds the configuration options for a Postgres database | ||
Postgres *db.PostgresConfig `group:"postgres" namespace:"postgres"` | ||
} | ||
|
||
// Validate checks that all the values set in our DevConfig are valid and uses | ||
// the passed parameters to override any defaults if necessary. | ||
func (c *DevConfig) Validate(dbDir, network string) error { | ||
// We'll update the database file location if it wasn't set. | ||
if c.Sqlite.DatabaseFileName == defaultSqliteDatabasePath { | ||
c.Sqlite.DatabaseFileName = filepath.Join( | ||
dbDir, network, defaultSqliteDatabaseFileName, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// defaultDevConfig returns a new DevConfig with default values set. | ||
func defaultDevConfig() *DevConfig { | ||
return &DevConfig{ | ||
Sqlite: &db.SqliteConfig{ | ||
DatabaseFileName: defaultSqliteDatabasePath, | ||
}, | ||
Postgres: &db.PostgresConfig{ | ||
Host: "localhost", | ||
Port: 5432, | ||
MaxOpenConnections: 10, | ||
}, | ||
} | ||
} | ||
|
||
// NewAccountStore creates a new account store based on the chosen database | ||
// backend. | ||
func NewAccountStore(cfg *Config, clock clock.Clock) (accounts.Store, error) { | ||
switch cfg.DatabaseBackend { | ||
case DatabaseBackendSqlite: | ||
// Before we initialize the SQLite store, we'll make sure that | ||
// the directory where we will store the database file exists. | ||
networkDir := filepath.Join(cfg.LitDir, cfg.Network) | ||
err := makeDirectories(networkDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sqlStore, err := db.NewSqliteStore(cfg.Sqlite) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return accounts.NewSQLStore(sqlStore.BaseDB, clock), nil | ||
|
||
case DatabaseBackendPostgres: | ||
sqlStore, err := db.NewPostgresStore(cfg.Postgres) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return accounts.NewSQLStore(sqlStore.BaseDB, clock), nil | ||
|
||
default: | ||
return accounts.NewBoltStore( | ||
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, | ||
clock, | ||
) | ||
} | ||
} |
This file contains hidden or 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,33 @@ | ||
//go:build !dev | ||
|
||
package terminal | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/lightninglabs/lightning-terminal/accounts" | ||
"github.com/lightningnetwork/lnd/clock" | ||
) | ||
|
||
// DevConfig is an empty shell struct that allows us to build without the dev | ||
// tag. This struct is embedded in the main Config struct, and it adds no new | ||
// functionality in a production build. | ||
type DevConfig struct{} | ||
|
||
// defaultDevConfig returns an empty DevConfig struct. | ||
func defaultDevConfig() *DevConfig { | ||
return &DevConfig{} | ||
} | ||
|
||
// Validate is a no-op function during a production build. | ||
func (c *DevConfig) Validate(_, _ string) error { | ||
return nil | ||
} | ||
|
||
// NewAccountStore creates a new account store using the default Bolt backend | ||
// since in production, this is the only backend supported currently. | ||
func NewAccountStore(cfg *Config, clock clock.Clock) (accounts.Store, error) { | ||
return accounts.NewBoltStore( | ||
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, clock, | ||
) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉