mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +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() {
|
||||
// register base module, for database initialization
|
||||
modules.Register("base", nil, nil, nil)
|
||||
|
||||
// register module
|
||||
module = modules.Register("template", prep, start, stop) // add dependencies...
|
||||
|
||||
// register events that other modules can subscribe to
|
||||
module.RegisterEvent(eventStateUpdate)
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
// register module as subsystem
|
||||
err := subsystems.Register(
|
||||
subsystems.Register(
|
||||
"template-subsystem", // ID
|
||||
"Template Subsystem", // name
|
||||
"This subsystem is a template for quick setup", // description
|
||||
module,
|
||||
|
@ -40,12 +37,14 @@ func prep() error {
|
|||
DefaultValue: false,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
// register events that other modules can subscribe to
|
||||
module.RegisterEvent(eventStateUpdate)
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
// register options
|
||||
err = config.Register(&config.Option{
|
||||
err := config.Register(&config.Option{
|
||||
Name: "language",
|
||||
Key: "config:template/language",
|
||||
Description: "Sets the language for the template [TEMPLATE]",
|
||||
|
@ -99,6 +98,7 @@ func serviceWorker(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,30 +11,39 @@ import (
|
|||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// enable module for testing
|
||||
module.Enable()
|
||||
|
||||
// tmp dir for data root (db & config)
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
// start modules
|
||||
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()
|
||||
exitCode = m.Run()
|
||||
}
|
||||
|
||||
// shutdown
|
||||
_ = modules.Shutdown()
|
||||
if modules.GetExitStatusCode() != 0 {
|
||||
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
|
||||
os.RemoveAll(tmpDir)
|
||||
|
|
Loading…
Add table
Reference in a new issue