1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/daemon_windows_test.go
Sebastiaan van Stijn a1150245cc
Update to Go 1.17.0, and gofmt with Go 1.17
Movified from 686be57d0a, and re-ran
gofmt again to address for files not present in 20.10 and vice-versa.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 686be57d0a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-07 23:27:50 +02:00

73 lines
2.1 KiB
Go

//go:build windows
// +build windows
package daemon // import "github.com/docker/docker/daemon"
import (
"strings"
"testing"
"golang.org/x/sys/windows/svc/mgr"
)
const existingService = "Power"
func TestEnsureServicesExist(t *testing.T) {
m, err := mgr.Connect()
if err != nil {
t.Fatal("failed to connect to service manager, this test needs admin")
}
defer m.Disconnect()
s, err := m.OpenService(existingService)
if err != nil {
t.Fatalf("expected to find known inbox service %q, this test needs a known inbox service to run correctly", existingService)
}
defer s.Close()
input := []string{existingService}
err = ensureServicesInstalled(input)
if err != nil {
t.Fatalf("unexpected error for input %q: %q", input, err)
}
}
func TestEnsureServicesExistErrors(t *testing.T) {
m, err := mgr.Connect()
if err != nil {
t.Fatal("failed to connect to service manager, this test needs admin")
}
defer m.Disconnect()
s, err := m.OpenService(existingService)
if err != nil {
t.Fatalf("expected to find known inbox service %q, this test needs a known inbox service to run correctly", existingService)
}
defer s.Close()
for _, testcase := range []struct {
input []string
expectedError string
}{
{
input: []string{"daemon_windows_test_fakeservice"},
expectedError: "failed to open service daemon_windows_test_fakeservice",
},
{
input: []string{"daemon_windows_test_fakeservice1", "daemon_windows_test_fakeservice2"},
expectedError: "failed to open service daemon_windows_test_fakeservice1",
},
{
input: []string{existingService, "daemon_windows_test_fakeservice"},
expectedError: "failed to open service daemon_windows_test_fakeservice",
},
} {
t.Run(strings.Join(testcase.input, ";"), func(t *testing.T) {
err := ensureServicesInstalled(testcase.input)
if err == nil {
t.Fatalf("expected error for input %v", testcase.input)
}
if !strings.Contains(err.Error(), testcase.expectedError) {
t.Fatalf("expected error %q to contain %q", err.Error(), testcase.expectedError)
}
})
}
}