Files
Igor Sirotin 23febf1645 refactor: dissolve the root common package
`common` was a grab-bag with no domain: the issue's own preamble names
it as the kind of package that must not exist. Every symbol moves to the
package that owns it, and the directory is deleted.

  common/dbsetup            -> internal/db/dbsetup
  common/devices.go         -> internal/platform
  common/pausable*.go       -> internal/pausable
  LogOnPanic                -> internal/panics
  TruncateWithDot(N)        -> internal/logutils
  RecoverKey, ValidateDisplayName, display-name errors -> protocol/common
  IpfsGatewayURL            -> internal/ipfs.GatewayURL
  Archives/TorrentTorrentsRelativePath, MainnetEthereumNetworkURL -> params
  StatusService             -> pkg/backend/node
  ErrBigIntSetFromString    -> services/wallet
  IsNil, Ptr                -> inlined at their call sites
  IsENSName                 -> deleted, it had no callers

Notes:
- LogOnPanic gets its own package rather than living in logutils. It
  reports to Sentry, and logutils is imported by nearly everything: put
  the guard in logutils and the Sentry SDK lands in every dependency
  graph in the tree (213 -> 250 packages). internal/panics imports
  logutils and sentry, which is the direction root `common` had.
- TruncateWithDot is log redaction, not string formatting: every one of
  its 121 call sites is inside a log or error message, so it belongs
  next to the logger.
- Moving RecoverKey and ValidateDisplayName into protocol/common removes
  the common -> protocol layering inversion; all their callers were
  already inside protocol/.
- Makefile lint-panics target follows LogOnPanic to its new path.

refs #7067
2026-08-20 20:59:45 +02:00

75 lines
1.7 KiB
Go

package testutils
import (
"database/sql"
"fmt"
"io/ioutil"
"os"
"github.com/google/uuid"
bindata "github.com/status-im/migrate/v4/source/go_bindata"
"github.com/status-im/status-go/internal/db/dbsetup"
"github.com/status-im/status-go/internal/db/sqlite"
)
const kdfIterationsNumberForTests = 1
// SetupTestSQLDB creates a temporary sqlite database file, initialises and then returns with a teardown func
func SetupTestSQLDB(dbInit dbsetup.DatabaseInitializer, prefix string) (*sql.DB, func() error, error) {
tmpfile, err := ioutil.TempFile("", prefix)
if err != nil {
return nil, nil, err
}
db, err := dbInit.Initialize(tmpfile.Name(), "password", kdfIterationsNumberForTests)
if err != nil {
return nil, nil, err
}
return db, func() error {
err := db.Close()
if err != nil {
return err
}
return os.Remove(tmpfile.Name())
}, nil
}
func SetupTestMemorySQLDB(dbInit dbsetup.DatabaseInitializer) (*sql.DB, error) {
db, err := dbInit.Initialize(dbsetup.InMemoryPath, "password", kdfIterationsNumberForTests)
if err != nil {
return nil, err
}
return db, nil
}
type TestDBInitializer struct {
assetSources []*bindata.AssetSource
}
func NewTestDBInitializer(assetSource []*bindata.AssetSource) TestDBInitializer {
return TestDBInitializer{
assetSources: assetSource,
}
}
func (dbi TestDBInitializer) Initialize(dbPath string, password string, kdfIterations int) (*sql.DB, error) {
db, err := sqlite.OpenDB(dbPath, password, kdfIterations)
if err != nil {
return nil, err
}
for _, as := range dbi.assetSources {
err = sqlite.Migrate(db, as, sqlite.MigrateOptions{
MigrationTableName: "status_schema_migrations_" + fmt.Sprintf("%x", uuid.New()),
})
if err != nil {
return nil, err
}
}
return db, nil
}