forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
win_services_integration_test.go
59 lines (50 loc) · 1.58 KB
/
win_services_integration_test.go
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
// +build windows
//these tests must be run under administrator account
package win_services
import (
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
var InvalidServices = []string{"XYZ1@", "ZYZ@", "SDF_@#"}
var KnownServices = []string{"LanmanServer", "TermService"}
func TestList(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
provider := &MgProvider{}
scmgr, err := provider.Connect()
require.NoError(t, err)
defer scmgr.Disconnect()
services, err := listServices(scmgr, KnownServices)
require.NoError(t, err)
require.Len(t, services, 2, "Different number of services")
require.Equal(t, services[0], KnownServices[0])
require.Equal(t, services[1], KnownServices[1])
}
func TestEmptyList(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
provider := &MgProvider{}
scmgr, err := provider.Connect()
require.NoError(t, err)
defer scmgr.Disconnect()
services, err := listServices(scmgr, []string{})
require.NoError(t, err)
require.Condition(t, func() bool { return len(services) > 20 }, "Too few service")
}
func TestGatherErrors(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
ws := &WinServices{
Log: testutil.Logger{},
ServiceNames: InvalidServices,
mgrProvider: &MgProvider{},
}
require.Len(t, ws.ServiceNames, 3, "Different number of services")
var acc testutil.Accumulator
require.NoError(t, ws.Gather(&acc))
require.Len(t, acc.Errors, 3, "There should be 3 errors after gather")
}