mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Fix template to work with new changes
This commit is contained in:
parent
7ab46a8d1e
commit
6166ce84af
2 changed files with 34 additions and 25 deletions
|
@ -18,16 +18,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// register base module, for database initialization
|
||||||
|
modules.Register("base", nil, nil, nil)
|
||||||
|
|
||||||
// register module
|
// register module
|
||||||
module = modules.Register("template", prep, start, stop) // add dependencies...
|
module = modules.Register("template", prep, start, stop) // add dependencies...
|
||||||
|
subsystems.Register(
|
||||||
// register events that other modules can subscribe to
|
"template-subsystem", // ID
|
||||||
module.RegisterEvent(eventStateUpdate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func prep() error {
|
|
||||||
// register module as subsystem
|
|
||||||
err := subsystems.Register(
|
|
||||||
"Template Subsystem", // name
|
"Template Subsystem", // name
|
||||||
"This subsystem is a template for quick setup", // description
|
"This subsystem is a template for quick setup", // description
|
||||||
module,
|
module,
|
||||||
|
@ -40,12 +37,14 @@ func prep() error {
|
||||||
DefaultValue: false,
|
DefaultValue: false,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// register events that other modules can subscribe to
|
||||||
|
module.RegisterEvent(eventStateUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prep() error {
|
||||||
// register options
|
// register options
|
||||||
err = config.Register(&config.Option{
|
err := config.Register(&config.Option{
|
||||||
Name: "language",
|
Name: "language",
|
||||||
Key: "config:template/language",
|
Key: "config:template/language",
|
||||||
Description: "Sets the language for the template [TEMPLATE]",
|
Description: "Sets the language for the template [TEMPLATE]",
|
||||||
|
@ -99,6 +98,7 @@ func serviceWorker(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,30 +11,39 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
// enable module for testing
|
||||||
|
module.Enable()
|
||||||
|
|
||||||
// tmp dir for data root (db & config)
|
// tmp dir for data root (db & config)
|
||||||
tmpDir, err := ioutil.TempDir("", "portbase-testing-")
|
tmpDir, err := ioutil.TempDir("", "portbase-testing-")
|
||||||
// initialize data dir
|
|
||||||
if err == nil {
|
|
||||||
err = dataroot.Initialize(tmpDir, 0755)
|
|
||||||
}
|
|
||||||
// start modules
|
|
||||||
if err == nil {
|
|
||||||
err = modules.Start()
|
|
||||||
}
|
|
||||||
// handle setup error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to setup test: %s", err)
|
fmt.Fprintf(os.Stderr, "failed to create tmp dir: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
// initialize data dir
|
||||||
|
err = dataroot.Initialize(tmpDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to initialize data root: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run tests
|
// start modules
|
||||||
exitCode := m.Run()
|
var exitCode int
|
||||||
|
err = modules.Start()
|
||||||
|
if err != nil {
|
||||||
|
// starting failed
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to setup test: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
} else {
|
||||||
|
// run tests
|
||||||
|
exitCode = m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
_ = modules.Shutdown()
|
_ = modules.Shutdown()
|
||||||
if modules.GetExitStatusCode() != 0 {
|
if modules.GetExitStatusCode() != 0 {
|
||||||
exitCode = modules.GetExitStatusCode()
|
exitCode = modules.GetExitStatusCode()
|
||||||
fmt.Fprintf(os.Stderr, "failed to cleanly shutdown test: %s", err)
|
fmt.Fprintf(os.Stderr, "failed to cleanly shutdown test: %s\n", err)
|
||||||
}
|
}
|
||||||
// clean up and exit
|
// clean up and exit
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
|
|
Loading…
Add table
Reference in a new issue