Adapt updates package to new updater module in portbase, clean up
This commit is contained in:
53
updates/testing.go
Normal file
53
updates/testing.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/updater"
|
||||
"github.com/safing/portbase/utils"
|
||||
)
|
||||
|
||||
// InitForTesting initializes the update module directly. This is intended to be only used by unit tests that require the updates module.
|
||||
func InitForTesting() error {
|
||||
// create registry
|
||||
registry = &updater.ResourceRegistry{
|
||||
Name: "testing-updates",
|
||||
UpdateURLs: []string{
|
||||
"https://updates.safing.io",
|
||||
},
|
||||
Beta: false,
|
||||
DevMode: false,
|
||||
Online: true,
|
||||
}
|
||||
|
||||
// set data dir
|
||||
root := utils.NewDirStructure(
|
||||
filepath.Join(os.TempDir(), "pm-testing"),
|
||||
0755,
|
||||
)
|
||||
err := root.Ensure()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// initialize
|
||||
err = registry.Initialize(root.ChildDir("updates", 0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = registry.LoadIndexes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = registry.ScanStorage("")
|
||||
if err != nil {
|
||||
log.Warningf("updates: error during storage scan: %s", err)
|
||||
}
|
||||
|
||||
registry.SelectVersions()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user