Files
ctrld/cmd/cli/service_test.go
Cuong Manh Le c60cf33af3 all: implement self-upgrade flag from API
So upgrading don't have to be initiated manually, helping large
deployments to upgrade to latest ctrld version easily.
2025-03-26 23:18:04 +07:00

29 lines
802 B
Go

package cli
import (
"strings"
"testing"
)
func Test_ensureSystemdKillMode(t *testing.T) {
tests := []struct {
name string
unitFile string
wantChange bool
}{
{"no KillMode", "[Service]\nExecStart=/bin/sleep 1", true},
{"not KillMode=process", "[Service]\nExecStart=/bin/sleep 1\nKillMode=mixed", true},
{"KillMode=process", "[Service]\nExecStart=/bin/sleep 1\nKillMode=process", false},
{"invalid unit file", "[Service\nExecStart=/bin/sleep 1\nKillMode=process", false},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
if _, change := ensureSystemdKillMode(strings.NewReader(tc.unitFile)); tc.wantChange != change {
t.Errorf("ensureSystemdKillMode(%q) = %v, want %v", tc.unitFile, change, tc.wantChange)
}
})
}
}