[WIP] Fix unit tests

This commit is contained in:
Vladimir Stoilov
2024-10-08 14:13:08 +03:00
parent a8517cd65f
commit a874ec9412
48 changed files with 264 additions and 4088 deletions

View File

@@ -24,7 +24,7 @@ type testInstance struct {
base *base.Base
}
func (stub *testInstance) Updates() *updates.Updates {
func (stub *testInstance) IntelUpdates() *updates.Updates {
return stub.updates
}
@@ -62,6 +62,16 @@ func runTest(m *testing.M) error {
}
defer func() { _ = os.RemoveAll(ds) }()
installDir, err := os.MkdirTemp("", "hub_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)
}
stub := &testInstance{}
// Init
stub.db, err = dbmodule.New(stub)
@@ -76,7 +86,10 @@ func runTest(m *testing.M) error {
if err != nil {
return fmt.Errorf("failed to create config: %w", err)
}
stub.updates, err = updates.New(stub)
stub.updates, err = updates.New(stub, "Test Intel", updates.UpdateIndex{
Directory: installDir,
IndexFile: "index.json",
})
if err != nil {
return fmt.Errorf("failed to create updates: %w", err)
}

View File

@@ -48,11 +48,12 @@ type Instance struct {
runtime *runtime.Runtime
rng *rng.Rng
core *core.Core
updates *updates.Updates
geoip *geoip.GeoIP
netenv *netenv.NetEnv
filterLists *filterlists.FilterLists
core *core.Core
binaryUpdates *updates.Updates
intelUpdates *updates.Updates
geoip *geoip.GeoIP
netenv *netenv.NetEnv
filterLists *filterlists.FilterLists
access *access.Access
cabin *cabin.Cabin
@@ -74,6 +75,14 @@ func New() (*Instance, error) {
instance := &Instance{}
instance.ctx, instance.cancelCtx = context.WithCancel(context.Background())
binaryUpdateIndex := updates.UpdateIndex{
// FIXME: fill
}
intelUpdateIndex := updates.UpdateIndex{
// FIXME: fill
}
var err error
// Base modules
@@ -111,7 +120,11 @@ func New() (*Instance, error) {
if err != nil {
return instance, fmt.Errorf("create core module: %w", err)
}
instance.updates, err = updates.New(instance)
instance.binaryUpdates, err = updates.New(instance, "Binary Updater", binaryUpdateIndex)
if err != nil {
return instance, fmt.Errorf("create updates module: %w", err)
}
instance.intelUpdates, err = updates.New(instance, "Intel Updater", intelUpdateIndex)
if err != nil {
return instance, fmt.Errorf("create updates module: %w", err)
}
@@ -181,7 +194,8 @@ func New() (*Instance, error) {
instance.rng,
instance.core,
instance.updates,
instance.binaryUpdates,
instance.intelUpdates,
instance.geoip,
instance.netenv,
@@ -255,9 +269,14 @@ func (i *Instance) Base() *base.Base {
return i.base
}
// Updates returns the updates module.
func (i *Instance) Updates() *updates.Updates {
return i.updates
// BinaryUpdates returns the updates module.
func (i *Instance) BinaryUpdates() *updates.Updates {
return i.binaryUpdates
}
// IntelUpdates returns the updates module.
func (i *Instance) IntelUpdates() *updates.Updates {
return i.intelUpdates
}
// GeoIP returns the geoip module.

View File

@@ -62,6 +62,16 @@ func runTest(m *testing.M) error {
}
defer func() { _ = os.RemoveAll(ds) }()
installDir, err := os.MkdirTemp("", "geoip_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)
}
stub := &testInstance{}
log.SetLogLevel(log.DebugLevel)
@@ -78,7 +88,10 @@ func runTest(m *testing.M) error {
if err != nil {
return fmt.Errorf("failed to create config: %w", err)
}
stub.updates, err = updates.New(stub, "Intel Test", updates.UpdateIndex{})
stub.updates, err = updates.New(stub, "Test Intel", updates.UpdateIndex{
Directory: installDir,
IndexFile: "index.json",
})
if err != nil {
return fmt.Errorf("failed to create updates: %w", err)
}