-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathexperiment_test.go
More file actions
74 lines (71 loc) · 1.96 KB
/
experiment_test.go
File metadata and controls
74 lines (71 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package engine
import (
"testing"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestExperimentHonoursSharingDefaults(t *testing.T) {
measure := func(info *GeolocateResults) *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 *GeolocateResults
expect func(*model.Measurement) bool
}
allspecs := []spec{{
name: "probeIP",
locationInfo: &GeolocateResults{ProbeIP: "8.8.8.8"},
expect: func(m *model.Measurement) bool {
return m.ProbeIP == model.DefaultProbeIP
},
}, {
name: "probeASN",
locationInfo: &GeolocateResults{ASN: 30722},
expect: func(m *model.Measurement) bool {
return m.ProbeASN == "AS30722"
},
}, {
name: "probeCC",
locationInfo: &GeolocateResults{CountryCode: "IT"},
expect: func(m *model.Measurement) bool {
return m.ProbeCC == "IT"
},
}, {
name: "probeNetworkName",
locationInfo: &GeolocateResults{NetworkName: "Vodafone Italia"},
expect: func(m *model.Measurement) bool {
return m.ProbeNetworkName == "Vodafone Italia"
},
}, {
name: "resolverIP",
locationInfo: &GeolocateResults{ResolverIP: "9.9.9.9"},
expect: func(m *model.Measurement) bool {
return m.ResolverIP == "9.9.9.9"
},
}, {
name: "resolverASN",
locationInfo: &GeolocateResults{ResolverASN: 44},
expect: func(m *model.Measurement) bool {
return m.ResolverASN == "AS44"
},
}, {
name: "resolverNetworkName",
locationInfo: &GeolocateResults{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")
}
})
}
}