-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
335d366
commit 0e34d50
Showing
1 changed file
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build windows | ||
|
||
package etw | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
confpkg "github.com/elastic/elastic-agent-libs/config" | ||
) | ||
|
||
func Test_validateConfig(t *testing.T) { | ||
testCases := []struct { | ||
name string // Sub-test name. | ||
config config // Load config parameters. | ||
wantError string // Expected error | ||
}{ | ||
{ | ||
name: "valid config", | ||
config: config{ | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
SessionName: "MySession-DNSServer", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
MatchAllKeyword: 0, | ||
}, | ||
}, | ||
{ | ||
name: "minimal config", | ||
config: config{ | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
}, | ||
}, | ||
{ | ||
name: "missing source config", | ||
config: config{ | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "provider, existing logfile or running session must be set", | ||
}, | ||
{ | ||
name: "invalid trace level", | ||
config: config{ | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
TraceLevel: "failed", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "invalid Trace Level value 'failed'", | ||
}, | ||
{ | ||
name: "conflict provider GUID and name", | ||
config: config{ | ||
ProviderGUID: "{eb79061a-a566-4698-1234-3ed2807033a0}", | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: provider GUID and provider name cannot be defined together", | ||
}, | ||
{ | ||
name: "conflict provider GUID and logfile", | ||
config: config{ | ||
ProviderGUID: "{eb79061a-a566-4698-1234-3ed2807033a0}", | ||
Logfile: "C:\\Windows\\System32\\winevt\\File.etl", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: provider GUID and file cannot be defined together", | ||
}, | ||
{ | ||
name: "conflict provider GUID and session", | ||
config: config{ | ||
ProviderGUID: "{eb79061a-a566-4698-1234-3ed2807033a0}", | ||
Session: "EventLog-Application", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: provider GUID and existing session cannot be defined together", | ||
}, | ||
{ | ||
name: "conflict provider name and logfile", | ||
config: config{ | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
Logfile: "C:\\Windows\\System32\\winevt\\File.etl", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: provider name and file cannot be defined together", | ||
}, | ||
{ | ||
name: "conflict provider name and session", | ||
config: config{ | ||
ProviderName: "Microsoft-Windows-DNSServer", | ||
Session: "EventLog-Application", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: provider name and existing session cannot be defined together", | ||
}, | ||
{ | ||
name: "conflict logfile and session", | ||
config: config{ | ||
Logfile: "C:\\Windows\\System32\\winevt\\File.etl", | ||
Session: "EventLog-Application", | ||
TraceLevel: "verbose", | ||
MatchAnyKeyword: 0xffffffffffffffff, | ||
}, | ||
wantError: "configuration constraint error: file and existing session cannot be defined together", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
c := confpkg.MustNewConfigFrom(tc.config) | ||
config := defaultConfig() | ||
err := c.Unpack(&config) | ||
|
||
// Validate responses | ||
if assert.Error(t, err) { | ||
assert.Contains(t, err.Error(), tc.wantError) | ||
} | ||
}) | ||
} | ||
} |