Files
status-go/internal/protocol/node_config_persistence_test.go
Igor Sirotin f3e4363808 refactor: move protocol to internal/protocol
Part of the Go project layout migration, item 27.

Pure move plus import-path rewrite across 502 files. No API or behaviour
change. `internal/` keeps the messaging application logic unimportable
from outside the module, which is what the issue asks for -- status-go is
consumed through the C-bindings in mobile/, not as a Go library.

Things that had to follow the move, beyond the Go imports:

- tools/generate-handlers/template.txt. messenger_handlers.go is
  generated, and the template hard-codes the imports it emits, so the
  generated file kept importing protocol/common and failed typecheck.
- .gitignore. The ignore rule for that generated file was pinned to the
  old path; without moving it, a 1486-line generated file starts being
  tracked.
- Makefile: the logosstorage and torrent test targets (both the archive
  packages and ./protocol itself), the archive README, migration-protocol.
- scripts/run_unit_tests.sh, which names the protocol package explicitly
  to shard its tests.
- scripts/cleanup_generated_files.sh and .golangci.yml.

scripts/migration_check.sh also needed a fix that is not specific to this
move: it validated every file the branch touched under a migration dir
against the timestamp naming rule, and a directory rename makes every
migration in it look newly added. It now excludes renames, so moving a
migration is not mistaken for adding one.

refs #7067
2026-08-21 10:11:05 +02:00

91 lines
2.2 KiB
Go

package protocol
import (
"database/sql"
"testing"
"github.com/status-im/status-go/internal/nodecfg"
"github.com/status-im/status-go/params"
"github.com/stretchr/testify/suite"
)
func TestNodeConfigPersistence(t *testing.T) {
suite.Run(t, new(NodeConfigPersistenceTestSuite))
}
type NodeConfigPersistenceTestSuite struct {
suite.Suite
db *sql.DB
config *params.NodeConfig
}
func (s *NodeConfigPersistenceTestSuite) SetupTest() {
db, err := openTestDB()
s.Require().NoError(err)
s.db = db
s.config, err = nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
// write value to the db, otherwise log_config table won't be created
err = nodecfg.SaveNodeConfig(s.db, s.config)
s.Require().NoError(err)
}
func (s *NodeConfigPersistenceTestSuite) Test_SaveMaxLogBackups() {
// GIVEN
maxLogBackupsBeforeChanges := s.config.LogMaxBackups
// WHEN
err := nodecfg.SetMaxLogBackups(s.db, uint(maxLogBackupsBeforeChanges+10))
s.Require().NoError(err)
// THEN
dbNodeConfig, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.Require().Equal(maxLogBackupsBeforeChanges+10, dbNodeConfig.LogMaxBackups)
}
func (s *NodeConfigPersistenceTestSuite) Test_SetLogLevelError() {
// WHEN
err := nodecfg.SetLogLevel(s.db, "ERROR")
s.Require().NoError(err)
// THEN
dbNodeConfig, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.Require().Equal("ERROR", dbNodeConfig.LogLevel)
}
func (s *NodeConfigPersistenceTestSuite) Test_SetLogLevelDebug() {
// WHEN
err := nodecfg.SetLogLevel(s.db, "DEBUG")
s.Require().NoError(err)
// THEN
dbNodeConfig, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.Require().Equal("DEBUG", dbNodeConfig.LogLevel)
}
func (s *NodeConfigPersistenceTestSuite) Test_SetLogEnabled() {
// WHEN
err := nodecfg.SetLogEnabled(s.db, false)
s.Require().NoError(err)
// THEN
dbNodeConfig, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.Require().Equal(false, dbNodeConfig.LogEnabled)
// WHEN
err = nodecfg.SetLogEnabled(s.db, true)
s.Require().NoError(err)
// THEN
dbNodeConfig, err = nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.Require().Equal(true, dbNodeConfig.LogEnabled)
}