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 4eb8147 commit e38678d
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions internal/registry/factory_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package registry

import (
"context"
"errors"
"fmt"
"math"
"os"
"testing"

"github.com/apex/log"
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/checkincache"
"github.com/ooni/probe-cli/v3/internal/experiment/webconnectivitylte"
"github.com/ooni/probe-cli/v3/internal/experimentname"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/mocks"
"github.com/ooni/probe-cli/v3/internal/model"
)

Expand Down Expand Up @@ -295,6 +298,15 @@ func TestExperimentBuilderSetOptionAny(t *testing.T) {
FieldValue: 1.11,
ExpectErr: ErrCannotSetIntegerOption,
ExpectConfig: &fakeExperimentConfig{},
}, {
TestCaseName: "[int] for float64 with zero fractional value",
InitialConfig: &fakeExperimentConfig{},
FieldName: "Value",
FieldValue: float64(16.0),
ExpectErr: nil,
ExpectConfig: &fakeExperimentConfig{
Value: 16,
},
}, {
TestCaseName: "[string] for serialized bool value while setting a string value",
InitialConfig: &fakeExperimentConfig{},
Expand Down Expand Up @@ -802,3 +814,49 @@ func TestNewFactory(t *testing.T) {
}
})
}

// Make sure the target loader for web connectivity is WAI when using no static inputs.
func TestFactoryNewTargetLoaderWebConnectivity(t *testing.T) {
// construct the proper factory instance
store := &kvstore.Memory{}
factory, err := NewFactory("web_connectivity", store, log.Log)
if err != nil {
t.Fatal(err)
}

// define the expected error.
expected := errors.New("antani")

// create suitable loader config.
config := &model.ExperimentTargetLoaderConfig{
CheckInConfig: &model.OOAPICheckInConfig{
// nothing
},
Session: &mocks.Session{
MockCheckIn: func(ctx context.Context, config *model.OOAPICheckInConfig) (*model.OOAPICheckInResult, error) {
return nil, expected
},
MockLogger: func() model.Logger {
return log.Log
},
},
StaticInputs: nil,
SourceFiles: nil,
}

// obtain the loader
loader := factory.NewTargetLoader(config)

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

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

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

0 comments on commit e38678d

Please sign in to comment.