mirror of
https://github.com/safing/portmaster
synced 2025-04-23 04:19:10 +00:00
Adapt core package to portbase changes, add testing setup and teardown methods
This commit is contained in:
parent
4d48b023ae
commit
c72f956fe8
4 changed files with 79 additions and 8 deletions
|
@ -17,15 +17,13 @@ import (
|
|||
var (
|
||||
dataDir string
|
||||
databaseDir string
|
||||
|
||||
baseModule = modules.Register("base", prepBase, nil, nil)
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&dataDir, "data", "", "set data directory")
|
||||
flag.StringVar(&databaseDir, "db", "", "alias to --data (deprecated)")
|
||||
|
||||
notifications.SetPersistenceBasePath("core:notifications")
|
||||
modules.Register("base", prepBase, nil, nil, "info")
|
||||
}
|
||||
|
||||
func prepBase() error {
|
||||
|
@ -59,5 +57,8 @@ func prepBase() error {
|
|||
// set api listen address
|
||||
api.SetDefaultAPIListenAddress("127.0.0.1:817")
|
||||
|
||||
// set notification persistence
|
||||
notifications.SetPersistenceBasePath("core:notifications")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
devMode config.BoolOption
|
||||
defaultDevMode bool
|
||||
)
|
||||
|
||||
|
@ -27,8 +26,9 @@ func registerConfig() error {
|
|||
Name: "Development Mode",
|
||||
Key: "core/devMode",
|
||||
Description: "In Development Mode security restrictions are lifted/softened to enable easier access to Portmaster for debugging and testing purposes.",
|
||||
ExpertiseLevel: config.ExpertiseLevelDeveloper,
|
||||
OptType: config.OptTypeBool,
|
||||
ExpertiseLevel: config.ExpertiseLevelDeveloper,
|
||||
ReleaseLevel: config.ReleaseLevelStable,
|
||||
DefaultValue: defaultDevMode,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"github.com/safing/portbase/modules"
|
||||
)
|
||||
|
||||
var (
|
||||
coreModule = modules.Register("core", nil, startCore, nil, "base", "database", "config", "api", "random")
|
||||
)
|
||||
func init() {
|
||||
modules.Register("core", nil, startCore, nil, "base", "database", "config", "api", "random")
|
||||
}
|
||||
|
||||
func startCore() error {
|
||||
if err := startPlatformSpecific(); err != nil {
|
||||
|
|
70
core/testing.go
Normal file
70
core/testing.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
|
||||
"github.com/safing/portbase/database"
|
||||
|
||||
// module dependencies
|
||||
_ "github.com/safing/portbase/database/storage/hashmap"
|
||||
)
|
||||
|
||||
// InitForTesting initializes the core module directly. This is intended to be only used by unit tests that require the core (and depending) modules.
|
||||
func InitForTesting() (tmpDir string, err error) {
|
||||
tmpDir, err = ioutil.TempDir(os.TempDir(), "pm-testing-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = database.Initialize(tmpDir, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, err = database.Register(&database.Database{
|
||||
Name: "core",
|
||||
Description: "Holds core data, such as settings and profiles",
|
||||
StorageType: "hashmap",
|
||||
PrimaryAPI: "",
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, err = database.Register(&database.Database{
|
||||
Name: "cache",
|
||||
Description: "Cached data, such as Intelligence and DNS Records",
|
||||
StorageType: "hashmap",
|
||||
PrimaryAPI: "",
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// _, err = database.Register(&database.Database{
|
||||
// Name: "history",
|
||||
// Description: "Historic event data",
|
||||
// StorageType: "hashmap",
|
||||
// PrimaryAPI: "",
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// start logging
|
||||
err = log.Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.SetLogLevel(log.TraceLevel)
|
||||
|
||||
return tmpDir, nil
|
||||
}
|
||||
|
||||
// StopTesting shuts the test environment.
|
||||
func StopTesting() {
|
||||
log.Shutdown()
|
||||
}
|
Loading…
Add table
Reference in a new issue