committed by
GitHub
parent
5609594b2a
commit
58f4058633
@@ -8,76 +8,50 @@ import (
|
||||
"github.com/safing/portmaster/base/api"
|
||||
"github.com/safing/portmaster/base/config"
|
||||
"github.com/safing/portmaster/base/database/dbmodule"
|
||||
"github.com/safing/portmaster/base/notifications"
|
||||
"github.com/safing/portmaster/service/core/base"
|
||||
"github.com/safing/portmaster/service/mgr"
|
||||
"github.com/safing/portmaster/service/netenv"
|
||||
"github.com/safing/portmaster/service/ui"
|
||||
"github.com/safing/portmaster/service/updates"
|
||||
)
|
||||
|
||||
var domainFeed = make(chan string)
|
||||
|
||||
type testInstance struct {
|
||||
db *dbmodule.DBModule
|
||||
base *base.Base
|
||||
api *api.API
|
||||
config *config.Config
|
||||
updates *updates.Updater
|
||||
netenv *netenv.NetEnv
|
||||
db *dbmodule.DBModule
|
||||
base *base.Base
|
||||
config *config.Config
|
||||
netenv *netenv.NetEnv
|
||||
}
|
||||
|
||||
func (stub *testInstance) IntelUpdates() *updates.Updater {
|
||||
return stub.updates
|
||||
}
|
||||
|
||||
func (stub *testInstance) API() *api.API {
|
||||
return stub.api
|
||||
}
|
||||
|
||||
func (stub *testInstance) Config() *config.Config {
|
||||
return stub.config
|
||||
}
|
||||
|
||||
func (stub *testInstance) NetEnv() *netenv.NetEnv {
|
||||
return stub.netenv
|
||||
}
|
||||
|
||||
func (stub *testInstance) Notifications() *notifications.Notifications {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stub *testInstance) Ready() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (stub *testInstance) Restart() {}
|
||||
|
||||
func (stub *testInstance) Shutdown() {}
|
||||
|
||||
func (stub *testInstance) SetCmdLineOperation(f func() error) {}
|
||||
|
||||
func (stub *testInstance) GetEventSPNConnected() *mgr.EventMgr[struct{}] {
|
||||
return mgr.NewEventMgr[struct{}]("spn connect", nil)
|
||||
}
|
||||
func (stub *testInstance) IntelUpdates() *updates.Updater { return nil }
|
||||
func (stub *testInstance) Config() *config.Config { return stub.config }
|
||||
func (stub *testInstance) NetEnv() *netenv.NetEnv { return stub.netenv }
|
||||
func (stub *testInstance) Ready() bool { return true }
|
||||
func (stub *testInstance) SetCmdLineOperation(f func() error) {}
|
||||
func (stub *testInstance) UI() *ui.UI { return nil }
|
||||
func (stub *testInstance) DataDir() string { return _dataDir }
|
||||
|
||||
var _dataDir string
|
||||
|
||||
func runTest(m *testing.M) error {
|
||||
var err error
|
||||
|
||||
// Create a temporary directory for testing
|
||||
_dataDir, err = os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create temporary data directory: %s", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
defer func() { _ = os.RemoveAll(_dataDir) }()
|
||||
|
||||
// Set the default API listen address
|
||||
api.SetDefaultAPIListenAddress("0.0.0.0:8080")
|
||||
ds, err := config.InitializeUnitTestDataroot("test-resolver")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize dataroot: %w", err)
|
||||
}
|
||||
defer func() { _ = os.RemoveAll(ds) }()
|
||||
|
||||
installDir, err := os.MkdirTemp("", "resolver_installdir")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create tmp install dir: %w", err)
|
||||
}
|
||||
defer func() { _ = os.RemoveAll(installDir) }()
|
||||
err = updates.GenerateMockFolder(installDir, "Test Intel", "1.0.0")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate mock installation: %w", err)
|
||||
}
|
||||
|
||||
// Initialize the instance with the necessary components
|
||||
stub := &testInstance{}
|
||||
stub.db, err = dbmodule.New(stub)
|
||||
if err != nil {
|
||||
@@ -91,26 +65,14 @@ func runTest(m *testing.M) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create base: %w", err)
|
||||
}
|
||||
stub.api, err = api.New(stub)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create api: %w", err)
|
||||
}
|
||||
stub.netenv, err = netenv.New(stub)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create netenv: %w", err)
|
||||
}
|
||||
stub.updates, err = updates.New(stub, "Test Intel", updates.Config{
|
||||
Directory: installDir,
|
||||
IndexFile: "index.json",
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create updates: %w", err)
|
||||
}
|
||||
module, err := New(stub)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create module: %w", err)
|
||||
}
|
||||
|
||||
err = stub.db.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start database: %w", err)
|
||||
@@ -123,14 +85,6 @@ func runTest(m *testing.M) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start base: %w", err)
|
||||
}
|
||||
err = stub.api.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start api: %w", err)
|
||||
}
|
||||
err = stub.updates.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start updates: %w", err)
|
||||
}
|
||||
err = stub.netenv.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start netenv: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user