110a11828b
A bunch of packages (including oohelperd) just need the ability to use MaxMind-like databases. They don't need the additional functionality implemented by the geolocate package. Such a package, in fact, is mostly (if not only) needed by the engine package. Therefore, move code to query MaxMind-like databases to a separate package, and avoid depending on geolocate in all the packages for which it's sufficient to use geoipx. Part of https://github.com/ooni/probe/issues/2240
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package engine
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
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)
|
|
}
|
|
exp := builder.NewExperiment().(*experiment)
|
|
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 {
|
|
return m.ProbeIP == model.DefaultProbeIP
|
|
},
|
|
}, {
|
|
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")
|
|
}
|
|
})
|
|
}
|
|
}
|