@@ -6,44 +6,22 @@ import (
66 "net/http"
77 "net/http/httptest"
88 "net/url"
9- "reflect"
109 "testing"
1110
11+ "github.com/go-test/deep"
1212 "github.com/m-lab/go/rtx"
13+ v2 "github.com/m-lab/locate/api/v2"
1314 "github.com/m-lab/locate/static"
1415)
1516
16- var legacyNames = `[
17- {
18- "ip": [
19- "128.177.119.203",
20- "2001:438:fffd:2b::203"
21- ],
22- "country": "US",
23- "city": "New York_NY",
24- "fqdn": "ndt-iupui-mlab1-lga06.measurement-lab.org",
25- "site": "lga06"
26- },
27- {
28- "ip": [
29- "4.35.94.37",
30- "2001:1900:2100:14::37"
31- ],
32- "country": "US",
33- "city": "New York_NY",
34- "fqdn": "ndt-iupui-mlab3-lga05.measurement-lab.org",
35- "site": "lga05"
36- }
37- ]`
38-
3917var projectNames = `[
4018 {
4119 "ip": [
4220 "128.177.119.203",
4321 "2001:438:fffd:2b::203"
4422 ],
4523 "country": "US",
46- "city": "New York_NY ",
24+ "city": "New York ",
4725 "fqdn": "ndt-mlab1-lga06.mlab-staging.measurement-lab.org",
4826 "site": "lga06"
4927 },
@@ -53,7 +31,7 @@ var projectNames = `[
5331 "2001:1900:2100:14::37"
5432 ],
5533 "country": "US",
56- "city": "New York_NY ",
34+ "city": "New York ",
5735 "fqdn": "ndt-mlab3-lga05.mlab-staging.measurement-lab.org",
5836 "site": "lga05"
5937 }
@@ -66,8 +44,8 @@ var shortNames = `[
6644 "2001:5a0:4300::152"
6745 ],
6846 "country": "US",
69- "city": "New York_NY ",
70- "fqdn": "ndt-mlab2-lga03.measurement-lab.org",
47+ "city": "New York ",
48+ "fqdn": "ndt-mlab2-lga03.mlab-sandbox. measurement-lab.org",
7149 "site": "lga03"
7250 },
7351 {
@@ -76,8 +54,8 @@ var shortNames = `[
7654 "2001:550:1d00:100::165"
7755 ],
7856 "country": "US",
79- "city": "New York_NY ",
80- "fqdn": "ndt-mlab3-lga08.measurement-lab.org",
57+ "city": "New York ",
58+ "fqdn": "ndt-mlab3-lga08.mlab-sandbox. measurement-lab.org",
8159 "site": "lga08"
8260 }
8361]`
@@ -89,7 +67,7 @@ var badNames = `[
8967 "2001:5a0:4300::152"
9068 ],
9169 "country": "US",
92- "city": "New York_NY ",
70+ "city": "New York ",
9371 "fqdn": "invalid-hostname.measurementlab.net",
9472 "site": "lga03"
9573 },
@@ -99,7 +77,7 @@ var badNames = `[
9977 "2001:550:1d00:100::165"
10078 ],
10179 "country": "US",
102- "city": "New York_NY ",
80+ "city": "New York ",
10381 "fqdn": "invalid-hostname-2.measurementlab.net",
10482 "site": "lga08"
10583 }
@@ -132,29 +110,31 @@ func TestNearest(t *testing.T) {
132110 breakReader bool
133111 badScheme string
134112 badURL string
135- want []string
113+ want []v2. Target
136114 wantErr bool
137115 }{
138- {
139- name : "success-legacy-names" ,
140- service : "ndt/ndt5" ,
141- lat : "40.3" ,
142- lon : "-70.1" ,
143- content : legacyNames ,
144- status : http .StatusOK ,
145- want : []string {
146- "mlab1-lga06.mlab-testing.measurement-lab.org" , "mlab3-lga05.mlab-testing.measurement-lab.org" ,
147- },
148- },
149116 {
150117 name : "success-project-names" ,
151118 service : "ndt/ndt5" ,
152119 lat : "40.3" ,
153120 lon : "-70.1" ,
154121 content : projectNames ,
155122 status : http .StatusOK ,
156- want : []string {
157- "mlab1-lga06.mlab-staging.measurement-lab.org" , "mlab3-lga05.mlab-staging.measurement-lab.org" ,
123+ want : []v2.Target {
124+ {
125+ Machine : "mlab1-lga06.mlab-staging.measurement-lab.org" ,
126+ Location : & v2.Location {
127+ City : "New York" ,
128+ Country : "US" ,
129+ },
130+ },
131+ {
132+ Machine : "mlab3-lga05.mlab-staging.measurement-lab.org" ,
133+ Location : & v2.Location {
134+ City : "New York" ,
135+ Country : "US" ,
136+ },
137+ },
158138 },
159139 },
160140 {
@@ -164,8 +144,21 @@ func TestNearest(t *testing.T) {
164144 lon : "-70.1" ,
165145 content : shortNames ,
166146 status : http .StatusOK ,
167- want : []string {
168- "mlab2-lga03.mlab-testing.measurement-lab.org" , "mlab3-lga08.mlab-testing.measurement-lab.org" ,
147+ want : []v2.Target {
148+ {
149+ Machine : "mlab2-lga03.mlab-sandbox.measurement-lab.org" ,
150+ Location : & v2.Location {
151+ City : "New York" ,
152+ Country : "US" ,
153+ },
154+ },
155+ {
156+ Machine : "mlab3-lga08.mlab-sandbox.measurement-lab.org" ,
157+ Location : & v2.Location {
158+ City : "New York" ,
159+ Country : "US" ,
160+ },
161+ },
169162 },
170163 },
171164 {
@@ -175,7 +168,7 @@ func TestNearest(t *testing.T) {
175168 lon : "-70.1" ,
176169 content : badNames ,
177170 status : http .StatusOK ,
178- want : []string {},
171+ want : []v2. Target {},
179172 },
180173 {
181174 name : "error-no-content" ,
@@ -241,8 +234,8 @@ func TestNearest(t *testing.T) {
241234 t .Errorf ("Nearest() error = %v, wantErr %v" , err , tt .wantErr )
242235 return
243236 }
244- if ! reflect . DeepEqual (got , tt .want ) {
245- t .Errorf ("Nearest() = %v, want %v" , got , tt .want )
237+ if diff := deep . Equal (got , tt .want ); diff != nil {
238+ t .Errorf ("Nearest() = %# v, want %v" , diff , tt .want )
246239 }
247240 })
248241 }
0 commit comments