v2 tests fix (#1956)

* v2 tests fix
* test: added tests for sqlite
This commit is contained in:
Alexandr Stelnykovych
2025-08-07 02:04:38 +03:00
committed by GitHub
parent 5609594b2a
commit 58f4058633
15 changed files with 347 additions and 447 deletions

View File

@@ -10,22 +10,17 @@ import (
"github.com/safing/portmaster/base/notifications"
"github.com/safing/portmaster/service/mgr"
"github.com/safing/portmaster/service/ui"
)
type testInstance struct{}
func (i *testInstance) Restart() {}
func (i *testInstance) Shutdown() {}
func (i *testInstance) Notifications() *notifications.Notifications {
return nil
}
func (i *testInstance) Ready() bool {
return true
}
func (i *testInstance) SetCmdLineOperation(f func() error) {}
func (i *testInstance) Restart() {}
func (i *testInstance) Shutdown() {}
func (i *testInstance) Notifications() *notifications.Notifications { return nil }
func (i *testInstance) Ready() bool { return true }
func (i *testInstance) SetCmdLineOperation(f func() error) {}
func (i *testInstance) UI() *ui.UI { return nil }
func TestPerformUpdate(t *testing.T) {
t.Parallel()
@@ -39,11 +34,13 @@ func TestPerformUpdate(t *testing.T) {
t.Fatal(err)
}
defer func() { _ = os.RemoveAll(installedDir) }()
updateDir, err := os.MkdirTemp("", "updates_new_")
if err != nil {
t.Fatal(err)
}
defer func() { _ = os.RemoveAll(updateDir) }()
purgeDir, err := os.MkdirTemp("", "updates_purge_")
if err != nil {
t.Fatal(err)
@@ -109,7 +106,7 @@ func TestPerformUpdate(t *testing.T) {
// GenerateMockFolder generates mock index folder for testing.
func GenerateMockFolder(dir, name, version string, published time.Time) error {
// Make sure dir exists
_ = os.MkdirAll(dir, defaultDirMode)
_ = os.MkdirAll(dir, 0o750)
// Create empty files
file, err := os.Create(filepath.Join(dir, "portmaster"))
@@ -147,7 +144,7 @@ func GenerateMockFolder(dir, name, version string, published time.Time) error {
fmt.Fprintf(os.Stderr, "failed to marshal index: %s\n", err)
}
err = os.WriteFile(filepath.Join(dir, "index.json"), indexJSON, defaultFileMode)
err = os.WriteFile(filepath.Join(dir, "index.json"), indexJSON, 0o600)
if err != nil {
return err
}