Skip to content

Commit acfdd7e

Browse files
Copilotrbtr
andcommitted
Add tests for Windows service functionality
- Add unit tests for service functions on non-Windows platforms - Verify proper error handling when service functions are called on Linux - Ensure isWindowsService returns false on non-Windows platforms Co-authored-by: rbtr <[email protected]>
1 parent 405fa9d commit acfdd7e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cns/service/service_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package main
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
// TestServiceFunctionsOnNonWindows tests that service functions return appropriate errors on non-Windows platforms
13+
func TestServiceFunctionsOnNonWindows(t *testing.T) {
14+
t.Run("installService should fail on non-Windows", func(t *testing.T) {
15+
err := installService()
16+
assert.Error(t, err)
17+
assert.Contains(t, err.Error(), "only supported on Windows")
18+
})
19+
20+
t.Run("uninstallService should fail on non-Windows", func(t *testing.T) {
21+
err := uninstallService()
22+
assert.Error(t, err)
23+
assert.Contains(t, err.Error(), "only supported on Windows")
24+
})
25+
26+
t.Run("runAsService should fail on non-Windows", func(t *testing.T) {
27+
err := runAsService()
28+
assert.Error(t, err)
29+
assert.Contains(t, err.Error(), "only supported on Windows")
30+
})
31+
32+
t.Run("isWindowsService should return false on non-Windows", func(t *testing.T) {
33+
isService, err := isWindowsService()
34+
assert.NoError(t, err)
35+
assert.False(t, isService)
36+
})
37+
}

0 commit comments

Comments
 (0)