actually commit my changes this time...

This commit is contained in:
Ashley Mensah
2025-11-05 17:11:23 +01:00
parent 030ddae51e
commit 8aa1b23a22
6 changed files with 28 additions and 1 deletions

View File

@@ -61,6 +61,9 @@ type UpdateManager struct {
// updateMutex protect update and expectedVersion fields // updateMutex protect update and expectedVersion fields
updateMutex sync.Mutex updateMutex sync.Mutex
// updateFunc is used for testing to mock the triggerUpdate behavior
updateFunc func(ctx context.Context, targetVersion string) error
} }
func NewUpdateManager(statusRecorder *peer.Status, stateManager *statemanager.Manager) *UpdateManager { func NewUpdateManager(statusRecorder *peer.Status, stateManager *statemanager.Manager) *UpdateManager {
@@ -79,7 +82,6 @@ func NewUpdateManager(statusRecorder *peer.Status, stateManager *statemanager.Ma
// CheckUpdateSuccess checks if the update was successful. It works without to start the update manager. // CheckUpdateSuccess checks if the update was successful. It works without to start the update manager.
func (u *UpdateManager) CheckUpdateSuccess(ctx context.Context) { func (u *UpdateManager) CheckUpdateSuccess(ctx context.Context) {
u.updateStateManager(ctx) u.updateStateManager(ctx)
return
} }
func (u *UpdateManager) Start(ctx context.Context) { func (u *UpdateManager) Start(ctx context.Context) {

View File

@@ -18,6 +18,11 @@ const (
) )
func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error { func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error {
// Use test function if set (for testing only)
if u.updateFunc != nil {
return u.updateFunc(ctx, targetVersion)
}
cmd := exec.CommandContext(ctx, "pkgutil", "--pkg-info", "io.netbird.client") cmd := exec.CommandContext(ctx, "pkgutil", "--pkg-info", "io.netbird.client")
outBytes, err := cmd.Output() outBytes, err := cmd.Output()
if err != nil && cmd.ProcessState.ExitCode() == 1 { if err != nil && cmd.ProcessState.ExitCode() == 1 {

View File

@@ -5,6 +5,11 @@ package updatemanager
import "context" import "context"
func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error { func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error {
// Use test function if set (for testing purposes)
if u.updateFunc != nil {
return u.updateFunc(ctx, targetVersion)
}
// TODO: Implement // TODO: Implement
return nil return nil
} }

View File

@@ -5,6 +5,11 @@ package updatemanager
import "context" import "context"
func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error { func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error {
// Use test function if set (for testing purposes)
if u.updateFunc != nil {
return u.updateFunc(ctx, targetVersion)
}
// TODO: Implement // TODO: Implement
return nil return nil
} }

View File

@@ -5,6 +5,11 @@ package updatemanager
import "context" import "context"
func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error { func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error {
// Use test function if set (for testing purposes)
if u.updateFunc != nil {
return u.updateFunc(ctx, targetVersion)
}
// TODO: Implement // TODO: Implement
return nil return nil
} }

View File

@@ -26,6 +26,11 @@ const (
type installerType string type installerType string
func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error { func (u *UpdateManager) triggerUpdate(ctx context.Context, targetVersion string) error {
// Use test function if set (for testing purposes)
if u.updateFunc != nil {
return u.updateFunc(ctx, targetVersion)
}
method := installation() method := installation()
return install(ctx, method, targetVersion) return install(ctx, method, targetVersion)
} }