-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate: translate genpolicy logs, show warnings
Signed-off-by: Paul Meyer <[email protected]>
- Loading branch information
1 parent
f60c643
commit 896004d
Showing
2 changed files
with
143 additions
and
4 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
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,77 @@ | ||
// Copyright 2024 Edgeless Systems GmbH | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGenpolicyLogPrefixReg(t *testing.T) { | ||
testCases := []struct { | ||
logLine string | ||
wantMatch bool | ||
wantLevel string | ||
wantPosition string | ||
wantMessage string | ||
}{ | ||
{ | ||
logLine: `[2024-06-26T09:09:40Z INFO genpolicy::registry] ============================================`, | ||
wantMatch: true, | ||
wantLevel: "INFO", | ||
wantPosition: "genpolicy::registry", | ||
wantMessage: "============================================", | ||
}, | ||
{ | ||
logLine: `[2024-06-26T09:09:40Z INFO genpolicy::registry] Pulling manifest and config for "mcr.microsoft.com/oss/kubernetes/pause:3.6"`, | ||
wantMatch: true, | ||
wantLevel: "INFO", | ||
wantPosition: "genpolicy::registry", | ||
wantMessage: `Pulling manifest and config for "mcr.microsoft.com/oss/kubernetes/pause:3.6"`, | ||
}, | ||
{ | ||
logLine: `[2024-06-26T09:09:41Z INFO genpolicy::registry] Using cache file`, | ||
wantMatch: true, | ||
wantLevel: "INFO", | ||
wantPosition: "genpolicy::registry", | ||
wantMessage: "Using cache file", | ||
}, | ||
{ | ||
logLine: `[2024-06-26T09:09:41Z INFO genpolicy::registry] dm-verity root hash: 1e306eb31693964ac837ac74bc57b50c87c549f58b0da2789e3915f923f21b81`, | ||
wantMatch: true, | ||
wantLevel: "INFO", | ||
wantPosition: "genpolicy::registry", | ||
wantMessage: "dm-verity root hash: 1e306eb31693964ac837ac74bc57b50c87c549f58b0da2789e3915f923f21b81", | ||
}, | ||
{ | ||
logLine: `[2024-06-26T09:09:44Z WARN genpolicy::registry] Using cache file`, | ||
wantMatch: true, | ||
wantLevel: "WARN", | ||
wantPosition: "genpolicy::registry", | ||
wantMessage: "Using cache file", | ||
}, | ||
{ | ||
logLine: `Success!"`, | ||
wantMatch: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
match := genpolicyLogPrefixReg.FindStringSubmatch(tc.logLine) | ||
|
||
if !tc.wantMatch { | ||
assert.Nil(match) | ||
return | ||
} | ||
assert.Len(match, 4) | ||
assert.Equal(tc.wantLevel, match[1]) | ||
assert.Equal(tc.wantPosition, match[2]) | ||
assert.Equal(tc.wantMessage, match[3]) | ||
}) | ||
} | ||
} |