-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: construct TargetLoader using ExperimentBuilder (#1617)
This diff completes the set of preliminary richer input diffs. We build the TargetLoader using the ExperimentBuilder, which in turn uses a registry.Factory under the hood. This means that we can load targets for each experiment, because the actual implementation of the TargetLoader can be experiment dependent. Part of ooni/probe#2607
- Loading branch information
1 parent
f6a2051
commit 3424bd0
Showing
50 changed files
with
464 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Package experimentname contains code to manipulate experiment names. | ||
package experimentname | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/strcasex" | ||
|
||
// Canonicalize allows code to provide experiment names | ||
// in a more flexible way, where we have aliases. | ||
// | ||
// Because we allow for uppercase experiment names for backwards | ||
// compatibility with MK, we need to add some exceptions here when | ||
// mapping (e.g., DNSCheck => dnscheck). | ||
func Canonicalize(name string) string { | ||
switch name = strcasex.ToSnake(name); name { | ||
case "ndt_7": | ||
name = "ndt" // since 2020-03-18, we use ndt7 to implement ndt by default | ||
case "dns_check": | ||
name = "dnscheck" | ||
case "stun_reachability": | ||
name = "stunreachability" | ||
case "web_connectivity@v_0_5": | ||
name = "[email protected]" | ||
default: | ||
} | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Package experimentname contains code to manipulate experiment names. | ||
package experimentname | ||
|
||
import "testing" | ||
|
||
func TestCanonicalize(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expect string | ||
}{ | ||
{ | ||
input: "example", | ||
expect: "example", | ||
}, | ||
{ | ||
input: "Example", | ||
expect: "example", | ||
}, | ||
{ | ||
input: "ndt7", | ||
expect: "ndt", | ||
}, | ||
{ | ||
input: "Ndt7", | ||
expect: "ndt", | ||
}, | ||
{ | ||
input: "DNSCheck", | ||
expect: "dnscheck", | ||
}, | ||
{ | ||
input: "dns_check", | ||
expect: "dnscheck", | ||
}, | ||
{ | ||
input: "STUNReachability", | ||
expect: "stunreachability", | ||
}, | ||
{ | ||
input: "stun_reachability", | ||
expect: "stunreachability", | ||
}, | ||
{ | ||
input: "[email protected]", | ||
expect: "[email protected]", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.input, func(t *testing.T) { | ||
if got := Canonicalize(tt.input); got != tt.expect { | ||
t.Errorf("Canonicalize() = %v, want %v", got, tt.expect) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.