mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Fix keeping matches in the report history
This commit is contained in:
@@ -877,7 +877,6 @@ func (p *parser) storeReportHistory(state string) {
|
||||
history := r.Value.(ReportHistoryEntry)
|
||||
history.Log = nil
|
||||
history.Prelude = nil
|
||||
history.Matches = nil
|
||||
|
||||
r.Value = history
|
||||
}
|
||||
|
@@ -883,23 +883,35 @@ func TestParserProgressPlayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParserPatterns(t *testing.T) {
|
||||
parser := New(Config{
|
||||
p := New(Config{
|
||||
LogHistory: 3,
|
||||
Patterns: []string{
|
||||
"^foobar",
|
||||
"foobar$",
|
||||
},
|
||||
})
|
||||
|
||||
parser.Parse("some foobar more")
|
||||
require.Empty(t, parser.Report().Matches)
|
||||
p.Parse("some foobar more")
|
||||
require.Empty(t, p.Report().Matches)
|
||||
|
||||
parser.Parse("foobar some more")
|
||||
require.Equal(t, 1, len(parser.Report().Matches))
|
||||
require.Equal(t, "foobar some more", parser.Report().Matches[0])
|
||||
p.Parse("foobar some more")
|
||||
require.Equal(t, 1, len(p.Report().Matches))
|
||||
require.Equal(t, "foobar some more", p.Report().Matches[0])
|
||||
|
||||
parser.Parse("some more foobar")
|
||||
require.Equal(t, 2, len(parser.Report().Matches))
|
||||
require.Equal(t, "some more foobar", parser.Report().Matches[1])
|
||||
p.Parse("some more foobar")
|
||||
require.Equal(t, 2, len(p.Report().Matches))
|
||||
require.Equal(t, "some more foobar", p.Report().Matches[1])
|
||||
|
||||
pp, ok := p.(*parser)
|
||||
require.True(t, ok)
|
||||
|
||||
pp.storeReportHistory("something")
|
||||
|
||||
report := p.ReportHistory()
|
||||
require.Equal(t, 1, len(report))
|
||||
require.Equal(t, 2, len(report[0].Matches))
|
||||
require.Equal(t, "foobar some more", report[0].Matches[0])
|
||||
require.Equal(t, "some more foobar", report[0].Matches[1])
|
||||
}
|
||||
|
||||
func TestParserPatternsError(t *testing.T) {
|
||||
|
@@ -49,6 +49,7 @@ func (report *ProcessReport) Unmarshal(l *app.Log) {
|
||||
CreatedAt: h.CreatedAt.Unix(),
|
||||
Prelude: h.Prelude,
|
||||
Log: make([][2]string, len(h.Log)),
|
||||
Matches: h.Matches,
|
||||
ExitedAt: h.ExitedAt.Unix(),
|
||||
ExitState: h.ExitState,
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ func getDummyRestreamer(portrange net.Portranger, validatorIn, validatorOut ffmp
|
||||
Portrange: portrange,
|
||||
ValidatorInput: validatorIn,
|
||||
ValidatorOutput: validatorOut,
|
||||
LogHistoryLength: 3,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -404,6 +405,27 @@ func TestReloadProcess(t *testing.T) {
|
||||
rs.StopProcess(process.ID)
|
||||
}
|
||||
|
||||
func TestParseProcessPattern(t *testing.T) {
|
||||
rs, err := getDummyRestreamer(nil, nil, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
process := getDummyProcess()
|
||||
process.LogPatterns = []string{"libx264"}
|
||||
|
||||
rs.AddProcess(process)
|
||||
rs.StartProcess(process.ID)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
rs.StopProcess(process.ID)
|
||||
|
||||
log, err := rs.GetProcessLog(process.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 1, len(log.History))
|
||||
require.Equal(t, 8, len(log.History[0].Matches))
|
||||
}
|
||||
|
||||
func TestProbeProcess(t *testing.T) {
|
||||
rs, err := getDummyRestreamer(nil, nil, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user