feat: execute durable client commands through supervisor
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package windowsservice
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInstallSpecValidation_HP_WINSVC_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
valid := InstallSpec{ExecutablePath: `C:\Program Files\RVBox\rvbox.exe`, ConfigPath: `C:\ProgramData\RVBox\client.toml`, Startup: StartupAutomatic}
|
||||
if err := valid.Validate(); err != nil {
|
||||
t.Fatalf("valid install spec rejected: %v", err)
|
||||
}
|
||||
for _, invalid := range []InstallSpec{
|
||||
{ExecutablePath: `rvbox.exe`, ConfigPath: valid.ConfigPath, Startup: StartupAutomatic},
|
||||
{ExecutablePath: valid.ExecutablePath, ConfigPath: `client.toml`, Startup: StartupAutomatic},
|
||||
{ExecutablePath: valid.ExecutablePath, ConfigPath: valid.ConfigPath, Startup: StartupMode("disabled")},
|
||||
} {
|
||||
if !errors.Is(invalid.Validate(), ErrInvalidInstallSpec) {
|
||||
t.Fatalf("invalid install spec accepted: %#v", invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceTransitionsAreIdempotentAndExplicit_HP_WINSVC_02(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct {
|
||||
state State
|
||||
command Command
|
||||
want State
|
||||
}{
|
||||
{StateStopped, CommandStart, StateStartPending},
|
||||
{StateStartPending, CommandStart, StateStartPending},
|
||||
{StateRunning, CommandStop, StateStopPending},
|
||||
{StateStopPending, CommandStop, StateStopPending},
|
||||
{StateStopped, CommandRestart, StateStartPending},
|
||||
{StateRunning, CommandRestart, StateStopPending},
|
||||
}
|
||||
for _, test := range tests {
|
||||
got, err := Transition(test.state, test.command)
|
||||
if err != nil || got != test.want {
|
||||
t.Errorf("Transition(%v,%v) = %v,%v; want %v,nil", test.state, test.command, got, err, test.want)
|
||||
}
|
||||
}
|
||||
for _, test := range []struct {
|
||||
state State
|
||||
command Command
|
||||
}{{StateUnknown, CommandStart}, {StateStartPending, CommandStop}} {
|
||||
if test.state == StateStopped && test.command == CommandStop {
|
||||
// Stopping an already stopped service is deliberately idempotent.
|
||||
continue
|
||||
}
|
||||
if _, err := Transition(test.state, test.command); test.state == StateStopped && test.command == CommandStop {
|
||||
t.Fatalf("unreachable idempotent case returned error: %v", err)
|
||||
} else if err == nil {
|
||||
t.Errorf("Transition(%v,%v) unexpectedly accepted", test.state, test.command)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user