-
Notifications
You must be signed in to change notification settings - Fork 0
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
fecb4fc
commit 0d13e25
Showing
5 changed files
with
154 additions
and
10 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,26 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
Run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: Run tests | ||
run: | | ||
go test mcv_test.go |
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,111 @@ | ||
package main | ||
|
||
import ( | ||
"monolog-cli-viewer/src/data" | ||
"monolog-cli-viewer/src/templates" | ||
"monolog-cli-viewer/src/viewer" | ||
"testing" | ||
"text/template" | ||
) | ||
|
||
var templ *template.Template | ||
|
||
func init() { | ||
templ, _ = templates.GetTemplatateByName(templates.DefaultTemplateName) | ||
} | ||
|
||
func TestDefault(t *testing.T) { | ||
viewer.SetSettings(viewer.Settings{ | ||
NoNewLine: false, | ||
ShowFileChangeLine: false, | ||
ShowParsedLinesOnly: false, | ||
Template: templ, | ||
}) | ||
|
||
runTests(t, "TestDefault", []string{ | ||
"NOTICE:default\t2023-11-09 15:29:06\tSome test message\r\n{\"session\":{\"id\":\"bq2fk4i3nhkgbj4eua964g5r63\"},\"user\":{\"id\":1}}\r\n\n", | ||
"DEBUG:security\t2023-11-14 00:37:26\tChecking support on authenticator.\r\n{\"authenticator\":\"App\\\\Security\\\\AppAuthenticator\",\"firewall_name\":\"main\"}\r\n\n", | ||
"2023-10-23 11:03:16: [9a4e77e9afa8] [ERROR] [Whatever] Login Error\n\n", | ||
"", | ||
"INFO:default\t2023-10-23 11:07:47\tUser logged in \r\n{\"user\":{\"id\":\"54767261-98c6-4a57-9064-0d35fd06d1fc\"}}\r\n\n", | ||
}) | ||
} | ||
|
||
func TestNoNewLine(t *testing.T) { | ||
viewer.SetSettings(viewer.Settings{ | ||
NoNewLine: true, | ||
ShowFileChangeLine: false, | ||
ShowParsedLinesOnly: false, | ||
Template: templ, | ||
}) | ||
|
||
runTests(t, "TestDefault", []string{ | ||
"NOTICE:default\t2023-11-09 15:29:06\tSome test message\r\n{\"session\":{\"id\":\"bq2fk4i3nhkgbj4eua964g5r63\"},\"user\":{\"id\":1}}\r\n", | ||
"DEBUG:security\t2023-11-14 00:37:26\tChecking support on authenticator.\r\n{\"authenticator\":\"App\\\\Security\\\\AppAuthenticator\",\"firewall_name\":\"main\"}\r\n", | ||
"2023-10-23 11:03:16: [9a4e77e9afa8] [ERROR] [Whatever] Login Error\n", | ||
"", | ||
"INFO:default\t2023-10-23 11:07:47\tUser logged in \r\n{\"user\":{\"id\":\"54767261-98c6-4a57-9064-0d35fd06d1fc\"}}\r\n", | ||
}) | ||
} | ||
|
||
func TestShowFileChange(t *testing.T) { | ||
viewer.SetSettings(viewer.Settings{ | ||
NoNewLine: false, | ||
ShowFileChangeLine: true, | ||
ShowParsedLinesOnly: false, | ||
Template: templ, | ||
}) | ||
|
||
runTests(t, "TestDefault", []string{ | ||
"NOTICE:default\t2023-11-09 15:29:06\tSome test message\r\n{\"session\":{\"id\":\"bq2fk4i3nhkgbj4eua964g5r63\"},\"user\":{\"id\":1}}\r\n\n", | ||
"DEBUG:security\t2023-11-14 00:37:26\tChecking support on authenticator.\r\n{\"authenticator\":\"App\\\\Security\\\\AppAuthenticator\",\"firewall_name\":\"main\"}\r\n\n", | ||
"2023-10-23 11:03:16: [9a4e77e9afa8] [ERROR] [Whatever] Login Error\n\n", | ||
"==> some/path/to\\file.log <==\n\n", | ||
"INFO:default\t2023-10-23 11:07:47\tUser logged in \r\n{\"user\":{\"id\":\"54767261-98c6-4a57-9064-0d35fd06d1fc\"}}\r\n\n", | ||
}) | ||
} | ||
|
||
func TestParsedLinesOnly(t *testing.T) { | ||
viewer.SetSettings(viewer.Settings{ | ||
NoNewLine: false, | ||
ShowFileChangeLine: false, | ||
ShowParsedLinesOnly: true, | ||
Template: templ, | ||
}) | ||
|
||
runTests(t, "TestDefault", []string{ | ||
"NOTICE:default\t2023-11-09 15:29:06\tSome test message\r\n{\"session\":{\"id\":\"bq2fk4i3nhkgbj4eua964g5r63\"},\"user\":{\"id\":1}}\r\n\n", | ||
"DEBUG:security\t2023-11-14 00:37:26\tChecking support on authenticator.\r\n{\"authenticator\":\"App\\\\Security\\\\AppAuthenticator\",\"firewall_name\":\"main\"}\r\n\n", | ||
"", | ||
"", | ||
"INFO:default\t2023-10-23 11:07:47\tUser logged in \r\n{\"user\":{\"id\":\"54767261-98c6-4a57-9064-0d35fd06d1fc\"}}\r\n\n", | ||
}) | ||
} | ||
|
||
func TestNoNewLineFileChangeParsedOnly(t *testing.T) { | ||
viewer.SetSettings(viewer.Settings{ | ||
NoNewLine: true, | ||
ShowFileChangeLine: true, | ||
ShowParsedLinesOnly: true, | ||
Template: templ, | ||
}) | ||
|
||
runTests(t, "TestDefault", []string{ | ||
"NOTICE:default\t2023-11-09 15:29:06\tSome test message\r\n{\"session\":{\"id\":\"bq2fk4i3nhkgbj4eua964g5r63\"},\"user\":{\"id\":1}}\r\n", | ||
"DEBUG:security\t2023-11-14 00:37:26\tChecking support on authenticator.\r\n{\"authenticator\":\"App\\\\Security\\\\AppAuthenticator\",\"firewall_name\":\"main\"}\r\n", | ||
"", | ||
"==> some/path/to\\file.log <==\n", | ||
"INFO:default\t2023-10-23 11:07:47\tUser logged in \r\n{\"user\":{\"id\":\"54767261-98c6-4a57-9064-0d35fd06d1fc\"}}\r\n", | ||
}) | ||
} | ||
|
||
func runTests(t *testing.T, name string, expected []string) { | ||
for id, line := range data.GetTestData() { | ||
logLineItem := viewer.InitLogLine(line) | ||
result := logLineItem.GetFormattedString() | ||
|
||
if result != expected[id] { | ||
t.Errorf("Invalid string value on '%s' item '%d'. Expected '%s', got '%s'", "testDefault", id, expected[id], result) | ||
} | ||
} | ||
} |
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,11 @@ | ||
package data | ||
|
||
func GetTestData() []string { | ||
return []string{ | ||
`{"message":"Some test message","context":{"user":{"id":1},"session":{"id":"bq2fk4i3nhkgbj4eua964g5r63"}},"level":"NOTICE","channel":"default","timestamp":"1699540146122"}`, | ||
`{"message":"Checking support on authenticator.","context":{"firewall_name":"main","authenticator":"App\\Security\\AppAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2023-11-14T00:37:26.623539+02:00","extra":{}}`, | ||
`2023-10-23 11:03:16: [9a4e77e9afa8] [ERROR] [Whatever] Login Error`, | ||
`==> some/path/to\file.log <==`, | ||
`[2023-10-23T11:07:47.038324+00:00] default.INFO: User logged in {"user":{"id":"54767261-98c6-4a57-9064-0d35fd06d1fc"}} []`, | ||
} | ||
} |