@@ -169,3 +169,45 @@ func loadNames(ctx context.Context, src content.Provider, oldvalue ipinfo.ASName
169169 }
170170 return ipinfo .Parse (data )
171171}
172+
173+ // fakeASNAnnotator is just a real asnAnnotator that has a fixed dataset and
174+ // can't be reloaded.
175+ type fakeASNAnnotator struct {
176+ asnAnnotator
177+ }
178+
179+ func (* fakeASNAnnotator ) Reload (ctx context.Context ) {}
180+
181+ // NewFake returns an annotator that know about just one v4 IP (1.2.3.4) and one
182+ // v6 IP (1111:2222:3333:4444:5555:6666:7777:8888). This is useful for testing
183+ // other components when you don't want to carry around canonical datafiles, or
184+ // for building up a local IP annotation service with known outputs for testing.
185+ //
186+ // TODO(http://github.com/m-lab/uuid-annotator/issues/38): Consider moving this
187+ // fake to its own subpackage.
188+ func NewFake () ASNAnnotator {
189+ f := & fakeASNAnnotator {}
190+
191+ // Set up v4 data for 1.2.3.4.
192+ asn4Entry := routeview.IPNet {}
193+ _ , v4net , err := net .ParseCIDR ("1.2.3.4/32" )
194+ rtx .Must (err , "Could not parse fixed string" )
195+ asn4Entry .IPNet = * v4net
196+ asn4Entry .Systems = "5"
197+ f .asn4 = routeview.Index {asn4Entry }
198+
199+ // Set up v6 data for 1111:2222:3333:4444:5555:6666:7777:8888.
200+ asn6Entry := routeview.IPNet {}
201+ _ , v6net , err := net .ParseCIDR ("1111:2222:3333:4444:5555:6666:7777:8888/128" )
202+ rtx .Must (err , "Could not parse fixed string" )
203+ asn6Entry .IPNet = * v6net
204+ asn6Entry .Systems = "9"
205+ f .asn6 = routeview.Index {asn6Entry }
206+
207+ // Set up AS name entries for AS5 and AS9
208+ f .asnames = ipinfo.ASNames {
209+ 5 : "Test Number Five" ,
210+ 9 : "Test Number Nine" ,
211+ }
212+ return f
213+ }
0 commit comments