Skip to content

Commit 77d24be

Browse files
authored
fix: panics on tests across engine (#1746)
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [ ] reference issue for this pull request: <!-- add URL here --> - [ ] if you changed anything related to how experiments work and you need to reflect these changes in the ooni/spec repository, please link to the related ooni/spec pull request: <!-- add URL here --> - [ ] if you changed code inside an experiment, make sure you bump its version number <!-- Reminder: Location of the issue tracker: https://github.com/ooni/probe --> ## Description This diff fixes several instances of panics we see in tests across the engine repo which went unnoticed in the other diffs.
1 parent d53f983 commit 77d24be

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

internal/engine/experiment_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
"github.com/ooni/probe-cli/v3/internal/experiment/dnscheck"
1212
"github.com/ooni/probe-cli/v3/internal/experiment/example"
1313
"github.com/ooni/probe-cli/v3/internal/experiment/signal"
14+
"github.com/ooni/probe-cli/v3/internal/kvstore"
1415
"github.com/ooni/probe-cli/v3/internal/model"
1516
)
1617

1718
func TestExperimentHonoursSharingDefaults(t *testing.T) {
1819
measure := func(info *enginelocate.Results) *model.Measurement {
19-
sess := &Session{location: info}
20+
sess := &Session{location: info, kvStore: &kvstore.Memory{}}
2021
builder, err := sess.NewExperimentBuilder("example")
2122
if err != nil {
2223
t.Fatal(err)

internal/engine/session_internal_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ func TestNewSessionWithFakeTunnelAndCancelledContext(t *testing.T) {
337337
func TestSessionNewExperimentBuilder(t *testing.T) {
338338
t.Run("for a normal experiment", func(t *testing.T) {
339339
sess := &Session{
340-
logger: model.DiscardLogger,
340+
kvStore: &kvstore.Memory{},
341+
logger: model.DiscardLogger,
341342
}
342343
builder, err := sess.NewExperimentBuilder("ndt7")
343344
if err != nil {

internal/oonirun/experiment_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ func TestExperimentRunWithFailureToSubmitAndShuffle(t *testing.T) {
128128

129129
// This test ensures that we honour InitialOptions then ExtraOptions.
130130
func TestExperimentSetOptions(t *testing.T) {
131+
ctx := context.Background()
132+
session, err := engine.NewSession(ctx, engine.SessionConfig{
133+
Logger: model.DiscardLogger,
134+
SoftwareName: "ooniprobe-test",
135+
SoftwareVersion: "1.0",
136+
})
137+
if err != nil {
138+
t.Fatal(err)
139+
}
131140

132141
// create the Experiment we're using for this test
133142
exp := &Experiment{
@@ -140,7 +149,7 @@ func TestExperimentSetOptions(t *testing.T) {
140149
// TODO(bassosimone): A zero-value session works here. The proper change
141150
// however would be to write a engine.NewExperimentBuilder factory that takes
142151
// as input an interface for the session. This would help testing.
143-
Session: &engine.Session{},
152+
Session: session,
144153
}
145154

146155
// create the experiment builder manually

pkg/oonimkall/taskrunner_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ func TestTaskRunnerRun(t *testing.T) {
276276
MockResolverNetworkName: func() string {
277277
return "GARR"
278278
},
279+
MockGeoipDB: func() string {
280+
return ""
281+
},
279282
},
280283

281284
Loader: &mocks.ExperimentTargetLoader{

0 commit comments

Comments
 (0)