Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Jun 6, 2024
1 parent e38678d commit 06d300f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions internal/engine/experimentbuilder_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
package engine

import (
"context"
"errors"
"testing"

"github.com/ooni/probe-cli/v3/internal/model"
)

func TestExperimentBuilderEngineWebConnectivity(t *testing.T) {
// create a session for testing that does not use the network at all
sess := newSessionForTestingNoLookups(t)

// create an experiment builder for Web Connectivity
builder, err := sess.NewExperimentBuilder("WebConnectivity")
if err != nil {
t.Fatal(err)
}

// create suitable loader config
config := &model.ExperimentTargetLoaderConfig{
CheckInConfig: &model.OOAPICheckInConfig{
// nothing
},
Session: sess,
StaticInputs: nil,
SourceFiles: nil,
}

// create the loader
loader := builder.NewTargetLoader(config)

// create cancelled context to interrupt immediately so that we
// don't use the network when running this test
ctx, cancel := context.WithCancel(context.Background())
cancel()

// attempt to load targets
targets, err := loader.Load(ctx)

// make sure we've got the expected error
if !errors.Is(err, context.Canceled) {
t.Fatal("unexpected err", err)
}

// make sure there are no targets
if len(targets) != 0 {
t.Fatal("expected zero length targets")
}
}

0 comments on commit 06d300f

Please sign in to comment.