Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: MeasurementTarget -> MeasurementInput #1609

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/engine/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (e *experiment) newMeasurement(input string) *model.Measurement {
utctimenow := time.Now().UTC()
m := &model.Measurement{
DataFormatVersion: model.OOAPIReportDefaultDataFormatVersion,
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
MeasurementStartTime: utctimenow.Format(model.MeasurementDateFormat),
MeasurementStartTimeSaved: utctimenow,
ProbeIP: model.DefaultProbeIP,
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/dnscheck/dnscheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestDNSCheckWait(t *testing.T) {
}
measurer := &Measurer{Endpoints: endpoints}
run := func(input string) {
measurement := model.Measurement{Input: model.MeasurementTarget(input)}
measurement := model.Measurement{Input: model.MeasurementInput(input)}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: &measurement,
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/dnsping/dnsping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestMeasurer_run(t *testing.T) {
}
ctx := context.Background()
meas := &model.Measurement{
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
}
sess := &mocks.Session{
MockLogger: func() model.Logger { return model.DiscardLogger },
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/psiphon/psiphon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRunWithCancelledContext(t *testing.T) {
func TestRunWithCustomInputAndCancelledContext(t *testing.T) {
expected := "http://x.org"
measurement := &model.Measurement{
Input: model.MeasurementTarget(expected),
Input: model.MeasurementInput(expected),
}
measurer := psiphon.NewExperimentMeasurer(psiphon.Config{})
measurer.(*psiphon.Measurer).BeforeGetHook = func(g urlgetter.Getter) {
Expand Down
16 changes: 8 additions & 8 deletions internal/experiment/quicping/quicping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestInvalidHost(t *testing.T) {
Repetitions: 1,
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("a.a.a.a")
measurement.Input = model.MeasurementInput("a.a.a.a")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand All @@ -55,7 +55,7 @@ func TestURLInput(t *testing.T) {
Repetitions: 1,
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("https://google.com/")
measurement.Input = model.MeasurementInput("https://google.com/")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand All @@ -79,7 +79,7 @@ func TestSuccess(t *testing.T) {
}
measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("google.com")
measurement.Input = model.MeasurementInput("google.com")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestWithCancelledContext(t *testing.T) {

measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("google.com")
measurement.Input = model.MeasurementInput("google.com")
sess := &mockable.Session{MockableLogger: log.Log}
ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestListenFails(t *testing.T) {
},
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("google.com")
measurement.Input = model.MeasurementInput("google.com")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestWriteFails(t *testing.T) {
Repetitions: 1,
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("google.com")
measurement.Input = model.MeasurementInput("google.com")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestReadFails(t *testing.T) {
Repetitions: 1,
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("google.com")
measurement.Input = model.MeasurementInput("google.com")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestNoResponse(t *testing.T) {
Repetitions: 1,
})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("ooni.org")
measurement.Input = model.MeasurementInput("ooni.org")
sess := &mockable.Session{MockableLogger: log.Log}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMeasurerRun(t *testing.T) {
}

meas := &model.Measurement{
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
}
sess := &mocks.Session{
MockLogger: func() model.Logger { return model.DiscardLogger },
Expand Down
4 changes: 2 additions & 2 deletions internal/experiment/sniblocking/sniblocking.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ func processall(

// maybeURLToSNI handles the case where the input is from the test-lists
// and hence every input is a URL rather than a domain.
func maybeURLToSNI(input model.MeasurementTarget) (model.MeasurementTarget, error) {
func maybeURLToSNI(input model.MeasurementInput) (model.MeasurementInput, error) {
parsed, err := url.Parse(string(input))
if err != nil {
return "", err
}
if parsed.Path == string(input) {
return input, nil
}
return model.MeasurementTarget(parsed.Hostname()), nil
return model.MeasurementInput(parsed.Hostname()), nil
}

// Run implements ExperimentMeasurer.Run.
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/sniblocking/sniblocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func TestMeasurerRun(t *testing.T) {
})
measurer.(*Measurer).cache = cache
measurement := &model.Measurement{
Input: model.MeasurementTarget(testsni),
Input: model.MeasurementInput(testsni),
}
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(model.DiscardLogger),
Expand Down
16 changes: 8 additions & 8 deletions internal/experiment/stunreachability/stunreachability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestRunWithoutInput(t *testing.T) {
func TestRunWithInvalidURL(t *testing.T) {
measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("\t") // <- invalid URL
measurement.Input = model.MeasurementInput("\t") // <- invalid URL
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand All @@ -61,7 +61,7 @@ func TestRunWithInvalidURL(t *testing.T) {
func TestRunWithNoPort(t *testing.T) {
measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("stun://stun.ekiga.net")
measurement.Input = model.MeasurementInput("stun://stun.ekiga.net")
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand All @@ -76,7 +76,7 @@ func TestRunWithNoPort(t *testing.T) {
func TestRunWithUnsupportedURLScheme(t *testing.T) {
measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget("https://stun.ekiga.net:3478")
measurement.Input = model.MeasurementInput("https://stun.ekiga.net:3478")
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand All @@ -95,7 +95,7 @@ func TestRunWithInput(t *testing.T) {

measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget(defaultInput)
measurement.Input = model.MeasurementInput(defaultInput)
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestCancelledContext(t *testing.T) {
cancel() // immediately fail everything
measurer := NewExperimentMeasurer(Config{})
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget(defaultInput)
measurement.Input = model.MeasurementInput(defaultInput)
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestNewClientFailure(t *testing.T) {
}
measurer := NewExperimentMeasurer(*config)
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget(defaultInput)
measurement.Input = model.MeasurementInput(defaultInput)
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestStartFailure(t *testing.T) {
}
measurer := NewExperimentMeasurer(*config)
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget(defaultInput)
measurement.Input = model.MeasurementInput(defaultInput)
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestReadFailure(t *testing.T) {
}
measurer := NewExperimentMeasurer(*config)
measurement := new(model.Measurement)
measurement.Input = model.MeasurementTarget(defaultInput)
measurement.Input = model.MeasurementInput(defaultInput)
args := &model.ExperimentArgs{
Callbacks: model.NewPrinterCallbacks(log.Log),
Measurement: measurement,
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/tcpping/tcpping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestMeasurer_run(t *testing.T) {
}
ctx := context.Background()
meas := &model.Measurement{
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
}
sess := &mocks.Session{
MockLogger: func() model.Logger { return model.DiscardLogger },
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/tlsmiddlebox/measurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestMeasurer_input_failure(t *testing.T) {
SNIControl: sniControl,
})
meas := &model.Measurement{
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
}
sess := &mocks.Session{
MockLogger: func() model.Logger {
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/tlsping/tlsping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMeasurerRun(t *testing.T) {
}

meas := &model.Measurement{
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
}
sess := &mocks.Session{
MockLogger: func() model.Logger { return model.DiscardLogger },
Expand Down
2 changes: 1 addition & 1 deletion internal/inputparser/inputparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var ErrUnsupportedScheme = errors.New("inputparser: unsupported URL.Scheme")

// Parse parses the experiment input using the given config and returns
// to the caller either the resulting URL or an error.
func Parse(config *Config, input model.MeasurementTarget) (*url.URL, error) {
func Parse(config *Config, input model.MeasurementInput) (*url.URL, error) {
runtimex.Assert(config != nil, "passed nil config")
runtimex.Assert(input != "", "passed empty input")

Expand Down
2 changes: 1 addition & 1 deletion internal/inputparser/inputparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestParse(t *testing.T) {
config *Config

// input is the MANDATORY string-format input-URL to parse.
input model.MeasurementTarget
input model.MeasurementInput

// expectURL is the OPTIONAL URL we expect in output.
expectURL *url.URL
Expand Down
2 changes: 1 addition & 1 deletion internal/model/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type ExperimentAsyncTestKeys struct {
Extensions map[string]int64

// Input is the input this measurement refers to.
Input MeasurementTarget
Input MeasurementInput

// MeasurementRuntime is the total measurement runtime.
MeasurementRuntime float64
Expand Down
10 changes: 5 additions & 5 deletions internal/model/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func MeasurementFormatTimeNowUTC() string {
return time.Now().UTC().Format(MeasurementDateFormat)
}

// MeasurementTarget is the target of a OONI measurement.
type MeasurementTarget string
// MeasurementInput is the input of an OONI measurement.
type MeasurementInput string

// MarshalJSON serializes the MeasurementTarget.
func (t MeasurementTarget) MarshalJSON() ([]byte, error) {
// MarshalJSON serializes the [MeasurementInput].
func (t MeasurementInput) MarshalJSON() ([]byte, error) {
if t == "" {
return json.Marshal(nil)
}
Expand All @@ -84,7 +84,7 @@ type Measurement struct {
ID string `json:"id,omitempty"`

// Input is the measurement input
Input MeasurementTarget `json:"input"`
Input MeasurementInput `json:"input"`

// InputHashes contains input hashes
InputHashes []string `json:"input_hashes,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions internal/model/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestMeasurementFormatTimeNowUTC(t *testing.T) {
})
}

func TestMeasurementTargetMarshalJSON(t *testing.T) {
var mt MeasurementTarget
func TestMeasurementInputMarshalJSON(t *testing.T) {
var mt MeasurementInput
data, err := json.Marshal(mt)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -83,7 +83,7 @@ func makeMeasurement(config makeMeasurementConfig) *Measurement {
return &Measurement{
DataFormatVersion: "0.3.0",
ID: "bdd20d7a-bba5-40dd-a111-9863d7908572",
Input: MeasurementTarget(config.Input),
Input: MeasurementInput(config.Input),
MeasurementStartTime: "2018-11-01 15:33:20",
ProbeIP: config.ProbeIP,
ProbeASN: config.ProbeASN,
Expand Down
2 changes: 1 addition & 1 deletion internal/oonirun/inputprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (fipe *FakeInputProcessorExperiment) MeasureAsync(
// is MERGING annotations as opposed to overwriting them.
m.AddAnnotation("antani", "antani")
m.AddAnnotation("foo", "baz") // would be bar below
m.Input = model.MeasurementTarget(input)
m.Input = model.MeasurementInput(input)
fipe.M = append(fipe.M, m)
out := make(chan *model.Measurement)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/webconnectivityqa/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func newMeasurement(input string, measurer model.ExperimentMeasurer, t0 time.Tim
DataFormatVersion: "0.2.0",
Extensions: nil,
ID: "",
Input: model.MeasurementTarget(input),
Input: model.MeasurementInput(input),
InputHashes: nil,
MeasurementStartTime: t0.Format(model.MeasurementDateFormat),
MeasurementStartTimeSaved: t0,
Expand Down
Loading