File: daemon_windows_test.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (73 lines) | stat: -rw-r--r-- 2,103 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//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)
			}
		})
	}
}