mirror of
https://github.com/safing/portbase
synced 2025-09-15 17:49:51 +00:00
Add module template, update run method
This commit is contained in:
parent
b4f014574b
commit
3f17d0e7a9
4 changed files with 170 additions and 36 deletions
42
template/module_test.go
Normal file
42
template/module_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/safing/portbase/dataroot"
|
||||
"github.com/safing/portbase/modules"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// 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)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// run tests
|
||||
exitCode := m.Run()
|
||||
|
||||
// shutdown
|
||||
_ = modules.Shutdown()
|
||||
if modules.GetExitStatusCode() != 0 {
|
||||
exitCode = modules.GetExitStatusCode()
|
||||
fmt.Fprintf(os.Stderr, "failed to cleanly shutdown test: %s", err)
|
||||
}
|
||||
// clean up and exit
|
||||
os.RemoveAll(tmpDir)
|
||||
os.Exit(exitCode)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue