Skip to content

Commit

Permalink
chore(oonimkall): log the events when testing (#1624)
Browse files Browse the repository at this point in the history
This diff, which is part of ooni/probe#2752,
prints the event occurring when testing, which is useful for me to
better understand what is going on while changing the package.

Extracted from #1620.
  • Loading branch information
bassosimone authored Jun 19, 2024
1 parent 09b5750 commit 6be5db5
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions pkg/oonimkall/taskrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ func TestTaskRunnerRun(t *testing.T) {

// reduceEventsKeysIgnoreLog reduces the list of event keys
// counting equal subsequent keys and ignoring log events
reduceEventsKeysIgnoreLog := func(events []*event) (out []eventKeyCount) {
reduceEventsKeysIgnoreLog := func(t *testing.T, events []*event) (out []eventKeyCount) {
var current eventKeyCount
for _, ev := range events {
t.Log(ev)
if ev.Key == eventTypeLog {
continue
}
Expand Down Expand Up @@ -303,7 +304,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -321,7 +322,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -339,7 +340,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -361,7 +362,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -382,7 +383,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -405,7 +406,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -427,7 +428,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -448,7 +449,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -469,7 +470,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -498,7 +499,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -531,7 +532,7 @@ func TestTaskRunnerRun(t *testing.T) {
"architecture": "arm64",
}
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand All @@ -556,7 +557,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -604,7 +605,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -651,7 +652,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -681,7 +682,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -721,7 +722,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -766,7 +767,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollectContext(ctx, runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -796,7 +797,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down Expand Up @@ -830,7 +831,7 @@ func TestTaskRunnerRun(t *testing.T) {
}
runner.newSession = fake.NewSession
events := runAndCollect(runner, emitter)
reduced := reduceEventsKeysIgnoreLog(events)
reduced := reduceEventsKeysIgnoreLog(t, events)
expect := []eventKeyCount{
{Key: eventTypeStatusQueued, Count: 1},
{Key: eventTypeStatusStarted, Count: 1},
Expand Down

0 comments on commit 6be5db5

Please sign in to comment.