eventlog_test

package
v0.59.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Rendered for windows/amd64

Overview

Package eventlog_test provides helpers for testing code that uses the eventlog package

Index

Constants

View Source
const (
	// FakeAPIName identifies this API in GetAPITesterByName
	FakeAPIName = "Fake"
)
View Source
const (

	// WindowsAPIName identifies this API in GetAPITesterByName
	WindowsAPIName = "Windows"
)

Variables

This section is empty.

Functions

func GetEnabledAPITesters

func GetEnabledAPITesters() []string

GetEnabledAPITesters returns the APIs that are available to test as specified by enabledAPIsFlag

Types

type APITester

type APITester interface {
	Name() string
	API() evtapi.API
	InstallChannel(channel string) error
	RemoveChannel(channel string) error
	InstallSource(channel string, source string) error
	RemoveSource(channel string, name string) error
	GenerateEvents(channelName string, numEvents uint) error
	StartEventLogService(t *testing.T)
	KillEventLogService(t *testing.T)
}

APITester defines the interface used to test Windows Event Log API implementations. Notably it has helpers for adding/removing event logs and sources which would normally be the work of an installer.

func GetAPITesterByName

func GetAPITesterByName(name string, t testing.TB) APITester

GetAPITesterByName returns a new APITester interface with the backing type identified by name.

type FakeAPITester

type FakeAPITester struct {
	// contains filtered or unexported fields
}

FakeAPITester uses a limited in-memory re-implementation of the Windows EventLog APIs and provides utilities to the test framework that will simulate behavior and not make any changes to the host system

func NewFakeAPITester

func NewFakeAPITester() *FakeAPITester

NewFakeAPITester constructs a new API tester for a fake Windows Event Log API

func (*FakeAPITester) API

func (ti *FakeAPITester) API() evtapi.API

API returns the fake API

func (*FakeAPITester) GenerateEvents

func (ti *FakeAPITester) GenerateEvents(channelName string, numEvents uint) error

GenerateEvents creates numEvents new event records

func (*FakeAPITester) InstallChannel

func (ti *FakeAPITester) InstallChannel(channel string) error

InstallChannel adds a new event log

func (*FakeAPITester) InstallSource

func (ti *FakeAPITester) InstallSource(channel string, source string) error

InstallSource adds a new source to an event log channel

func (*FakeAPITester) KillEventLogService added in v0.51.1

func (ti *FakeAPITester) KillEventLogService(
	t *testing.T,
)

KillEventLogService is TODO for the fake API

func (*FakeAPITester) Name

func (ti *FakeAPITester) Name() string

Name returns the name that identifies this tester for use by GetAPITesterByName

func (*FakeAPITester) RemoveChannel

func (ti *FakeAPITester) RemoveChannel(channel string) error

RemoveChannel removes an event log

func (*FakeAPITester) RemoveSource

func (ti *FakeAPITester) RemoveSource(channel string, source string) error

RemoveSource removes a source from an event log channel

func (*FakeAPITester) StartEventLogService added in v0.51.1

func (ti *FakeAPITester) StartEventLogService(
	t *testing.T,
)

StartEventLogService is TODO for the fake API

type WindowsAPITester

type WindowsAPITester struct {
	// contains filtered or unexported fields
}

WindowsAPITester uses the real Windows EventLog APIs and provides utilities to the test framework that will modify the host system (e.g. install event log source, generate events).

func NewWindowsAPITester

func NewWindowsAPITester() *WindowsAPITester

NewWindowsAPITester constructs a new API tester for the Windows Event Log API

func (*WindowsAPITester) API

func (ti *WindowsAPITester) API() evtapi.API

API returns the Windows API

func (*WindowsAPITester) GenerateEvents

func (ti *WindowsAPITester) GenerateEvents(channelName string, numEvents uint) error

GenerateEvents creates numEvents new event records

func (*WindowsAPITester) InstallChannel

func (ti *WindowsAPITester) InstallChannel(channel string) error

InstallChannel adds a new event log. New event logs are created by creating registry keys.

func (*WindowsAPITester) InstallSource

func (ti *WindowsAPITester) InstallSource(channel string, source string) error

InstallSource adds a new source to an event log. New sources are created by creating registry keys. eventcreate.exe is used for the EventMessageFile because it has a generic message format that enables EvtFormatMessage to succeed

func (*WindowsAPITester) KillEventLogService added in v0.51.1

func (ti *WindowsAPITester) KillEventLogService(t *testing.T)

KillEventLogService stops the Windows Event Log service and adds a Cleanup task to the test to restart it at the end of the test.

func (*WindowsAPITester) Name

func (ti *WindowsAPITester) Name() string

Name returns the name that identifies this tester for use by GetAPITesterByName

func (*WindowsAPITester) RemoveChannel

func (ti *WindowsAPITester) RemoveChannel(channel string) error

RemoveChannel removes an event log. Event logs are removed by deleting registry keys.

func (*WindowsAPITester) RemoveSource

func (ti *WindowsAPITester) RemoveSource(channel string, source string) error

RemoveSource removes a source from an event log channel. Sources are removed by deleting registry keys.

func (*WindowsAPITester) StartEventLogService added in v0.51.1

func (ti *WindowsAPITester) StartEventLogService(t *testing.T)

StartEventLogService starts the Windows Event Log service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL