2017-08-07 21:36:15 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
//these tests must be run under administrator account
|
|
|
|
package win_services
|
|
|
|
|
|
|
|
import (
|
2018-09-11 23:04:16 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-08-07 21:36:15 +00:00
|
|
|
"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")
|
|
|
|
}
|
2018-09-11 23:04:16 +00:00
|
|
|
provider := &MgProvider{}
|
|
|
|
scmgr, err := provider.Connect()
|
2017-08-07 21:36:15 +00:00
|
|
|
require.NoError(t, err)
|
2018-09-11 23:04:16 +00:00
|
|
|
defer scmgr.Disconnect()
|
2017-08-07 21:36:15 +00:00
|
|
|
|
2018-09-11 23:04:16 +00:00
|
|
|
services, err := listServices(scmgr, KnownServices)
|
2017-08-07 21:36:15 +00:00
|
|
|
require.NoError(t, err)
|
2018-09-11 23:04:16 +00:00
|
|
|
require.Len(t, services, 2, "Different number of services")
|
|
|
|
require.Equal(t, services[0], KnownServices[0])
|
|
|
|
require.Equal(t, services[1], KnownServices[1])
|
2017-08-07 21:36:15 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 23:04:16 +00:00
|
|
|
func TestEmptyList(t *testing.T) {
|
2017-08-07 21:36:15 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2018-09-11 23:04:16 +00:00
|
|
|
provider := &MgProvider{}
|
|
|
|
scmgr, err := provider.Connect()
|
2017-08-07 21:36:15 +00:00
|
|
|
require.NoError(t, err)
|
2018-09-11 23:04:16 +00:00
|
|
|
defer scmgr.Disconnect()
|
2017-08-07 21:36:15 +00:00
|
|
|
|
2018-09-11 23:04:16 +00:00
|
|
|
services, err := listServices(scmgr, []string{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Condition(t, func() bool { return len(services) > 20 }, "Too few service")
|
2017-08-07 21:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGatherErrors(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2019-09-23 22:39:50 +00:00
|
|
|
ws := &WinServices{
|
|
|
|
Log: testutil.Logger{},
|
|
|
|
ServiceNames: InvalidServices,
|
|
|
|
mgrProvider: &MgProvider{},
|
|
|
|
}
|
2018-09-11 23:04:16 +00:00
|
|
|
require.Len(t, ws.ServiceNames, 3, "Different number of services")
|
2017-08-07 21:36:15 +00:00
|
|
|
var acc testutil.Accumulator
|
|
|
|
require.NoError(t, ws.Gather(&acc))
|
2018-09-11 23:04:16 +00:00
|
|
|
require.Len(t, acc.Errors, 3, "There should be 3 errors after gather")
|
2017-08-07 21:36:15 +00:00
|
|
|
}
|