2021-02-02 12:05:47 +01:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExperimentHonoursSharingDefaults(t *testing.T) {
|
|
|
|
measure := func(info *geolocate.Results) *model.Measurement {
|
|
|
|
sess := &Session{location: info}
|
|
|
|
builder, err := sess.NewExperimentBuilder("example")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-07-08 12:29:23 +02:00
|
|
|
exp := builder.NewExperiment().(*experiment)
|
2021-02-02 12:05:47 +01:00
|
|
|
return exp.newMeasurement("")
|
|
|
|
}
|
|
|
|
type spec struct {
|
|
|
|
name string
|
|
|
|
locationInfo *geolocate.Results
|
|
|
|
expect func(*model.Measurement) bool
|
|
|
|
}
|
|
|
|
allspecs := []spec{{
|
|
|
|
name: "probeIP",
|
|
|
|
locationInfo: &geolocate.Results{ProbeIP: "8.8.8.8"},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
2022-08-28 20:00:25 +02:00
|
|
|
return m.ProbeIP == model.DefaultProbeIP
|
2021-02-02 12:05:47 +01:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "probeASN",
|
|
|
|
locationInfo: &geolocate.Results{ASN: 30722},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ProbeASN == "AS30722"
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "probeCC",
|
|
|
|
locationInfo: &geolocate.Results{CountryCode: "IT"},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ProbeCC == "IT"
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "probeNetworkName",
|
|
|
|
locationInfo: &geolocate.Results{NetworkName: "Vodafone Italia"},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ProbeNetworkName == "Vodafone Italia"
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "resolverIP",
|
|
|
|
locationInfo: &geolocate.Results{ResolverIP: "9.9.9.9"},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ResolverIP == "9.9.9.9"
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "resolverASN",
|
|
|
|
locationInfo: &geolocate.Results{ResolverASN: 44},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ResolverASN == "AS44"
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "resolverNetworkName",
|
|
|
|
locationInfo: &geolocate.Results{ResolverNetworkName: "Google LLC"},
|
|
|
|
expect: func(m *model.Measurement) bool {
|
|
|
|
return m.ResolverNetworkName == "Google LLC"
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
for _, spec := range allspecs {
|
|
|
|
t.Run(spec.name, func(t *testing.T) {
|
|
|
|
if !spec.expect(measure(spec.locationInfo)) {
|
|
|
|
t.Fatal("expectation failed")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|