forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_services_integration_test.go
68 lines (59 loc) · 1.78 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
60
61
62
63
64
65
66
67
68
// +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 TestListIntegration(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()
winServices := &WinServices{
ServiceNames: KnownServices,
}
winServices.Init()
services, err := winServices.listServices(scmgr)
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 TestEmptyListIntegration(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()
winServices := &WinServices{
ServiceNames: []string{},
}
winServices.Init()
services, err := winServices.listServices(scmgr)
require.NoError(t, err)
require.Condition(t, func() bool { return len(services) > 20 }, "Too few service")
}
func TestGatherErrorsIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
ws := &WinServices{
Log: testutil.Logger{},
ServiceNames: InvalidServices,
mgrProvider: &MgProvider{},
}
ws.Init()
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")
}