From 04da18cfb28bfc494834b54292be8100f6f0b879 Mon Sep 17 00:00:00 2001 From: Thomas Yang Date: Wed, 2 Nov 2022 14:36:44 -0400 Subject: [PATCH] Add test cases for EventData/UserData in windowsEventLogRecord --- .../wineventlog/wineventlogrecord_test.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 plugins/inputs/windows_event_log/wineventlog/wineventlogrecord_test.go diff --git a/plugins/inputs/windows_event_log/wineventlog/wineventlogrecord_test.go b/plugins/inputs/windows_event_log/wineventlog/wineventlogrecord_test.go new file mode 100644 index 0000000000..3ecf8ec9b0 --- /dev/null +++ b/plugins/inputs/windows_event_log/wineventlog/wineventlogrecord_test.go @@ -0,0 +1,67 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: MIT + +//go:build windows +// +build windows + +package wineventlog + +import ( + "encoding/xml" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestUnmarshalWinEvtRecord(t *testing.T) { + tests := []struct { + xml string + wEvtRecord windowsEventLogRecord + }{ + { + xml: ` + + + 2022-10-28T22:33:25Z + RulesEngine + 2 + + + `, + wEvtRecord: windowsEventLogRecord{ + EventData: EventData{ + Data: []Datum{ + {"2022-10-28T22:33:25Z"}, + {"RulesEngine"}, + {"2"}, + }, + }, + }, + }, + { + xml: ` + + + + 0 + 2022-10-26T20:24:13.4253261Z + + + + `, + wEvtRecord: windowsEventLogRecord{ + UserData: UserData{ + Data: []Datum{ + {"0"}, + {"2022-10-26T20:24:13.4253261Z"}, + }, + }, + }, + }, + } + + for _, test := range tests { + record := new(windowsEventLogRecord) + xml.Unmarshal([]byte(test.xml), record) + assert.Equal(t, test.wEvtRecord, record) + } +}