mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-19 02:28:59 +00:00
Make native agent tests Windows-safe
This commit is contained in:
parent
a3ef1226b7
commit
1894d2e665
6 changed files with 21 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
|
@ -2083,7 +2084,7 @@ func TestAgentIDFilePersistence(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("stat: %v", err)
|
||||
}
|
||||
if mode := info.Mode().Perm(); mode != 0o600 {
|
||||
if mode := info.Mode().Perm(); runtime.GOOS != "windows" && mode != 0o600 {
|
||||
t.Errorf("file permissions = %v, want 0600", mode)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1179,7 +1179,10 @@ func TestPerformUpdateErrors(t *testing.T) {
|
|||
closeFileFn = origClose
|
||||
restartProcessFn = origRestart
|
||||
})
|
||||
closeFileFn = func(*os.File) error { return errors.New("close fail") }
|
||||
closeFileFn = func(file *os.File) error {
|
||||
_ = file.Close()
|
||||
return errors.New("close fail")
|
||||
}
|
||||
restartProcessFn = func(string) error { return nil }
|
||||
|
||||
u.client = &http.Client{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
|
@ -710,7 +711,7 @@ func qnapPersistentPath(stateDir, agentName string) string {
|
|||
if stateDir == "" {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(stateDir, name)
|
||||
return path.Join(stateDir, name)
|
||||
}
|
||||
|
||||
func normalizeAgentName(agentName string) (string, error) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -630,6 +631,9 @@ func TestHandleCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandleStopCommand(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("systemd stop-command behavior is not available on Windows")
|
||||
}
|
||||
t.Run("disable error sends failure ack", func(t *testing.T) {
|
||||
writeSystemctl(t, "echo 'access denied' >&2\nexit 1")
|
||||
|
||||
|
|
|
|||
|
|
@ -772,7 +772,8 @@ func TestSelfUpdate(t *testing.T) {
|
|||
swap(t, &osExecutableFn, func() (string, error) {
|
||||
return execPath, nil
|
||||
})
|
||||
swap(t, &closeFileFn, func(*os.File) error {
|
||||
swap(t, &closeFileFn, func(file *os.File) error {
|
||||
_ = file.Close()
|
||||
return errors.New("close failed")
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -30,6 +31,9 @@ func writeSystemctl(t *testing.T, script string) string {
|
|||
}
|
||||
|
||||
func TestDisableSystemdService(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("systemd is not available on Windows")
|
||||
}
|
||||
t.Run("no systemctl", func(t *testing.T) {
|
||||
prev := os.Getenv("PATH")
|
||||
_ = os.Setenv("PATH", "")
|
||||
|
|
@ -73,6 +77,9 @@ func TestDisableSystemdService(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStopSystemdService(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("systemd is not available on Windows")
|
||||
}
|
||||
t.Run("no systemctl", func(t *testing.T) {
|
||||
prev := os.Getenv("PATH")
|
||||
_ = os.Setenv("PATH", "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue