-
Notifications
You must be signed in to change notification settings - Fork 33
/
geolocation_lookup.rs
122 lines (110 loc) · 3.51 KB
/
geolocation_lookup.rs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use crate::common::{Test, TestResult};
use hyper::{body::to_bytes, StatusCode};
#[tokio::test(flavor = "multi_thread")]
async fn json_geolocation_lookup_works() -> TestResult {
const FASTLY_TOML: &str = r#"
name = "json-geolocation-lookup"
description = "json geolocation lookup test"
authors = ["Test User <test_user@fastly.com>"]
language = "rust"
[local_server]
[local_server.geolocation]
use_default_loopback = false
file = "../test-fixtures/data/geolocation-mapping.json"
format = "json"
"#;
let resp = Test::using_fixture("geolocation-lookup.wasm")
.using_fastly_toml(FASTLY_TOML)?
.against_empty()
.await;
assert_eq!(resp.status(), StatusCode::OK);
assert!(to_bytes(resp.into_body())
.await
.expect("can read body")
.to_vec()
.is_empty());
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn inline_toml_geolocation_lookup_works() -> TestResult {
const FASTLY_TOML: &str = r#"
name = "inline-toml-geolocation-lookup"
description = "inline toml geolocation lookup test"
authors = ["Test User <test_user@fastly.com>"]
language = "rust"
[local_server]
[local_server.geolocation]
use_default_loopback = false
format = "inline-toml"
[local_server.geolocation.addresses]
[local_server.geolocation.addresses."127.0.0.1"]
as_name = "Fastly Test"
as_number = 12345
area_code = 123
city = "Test City"
conn_speed = "broadband"
conn_type = "wired"
continent = "NA"
country_code = "CA"
country_code3 = "CAN"
country_name = "Canada"
latitude = 12.345
longitude = 54.321
metro_code = 0
postal_code = "12345"
proxy_description = "?"
proxy_type = "?"
region = "BC"
utc_offset = -700
[local_server.geolocation.addresses."0000:0000:0000:0000:0000:0000:0000:0001"]
as_name = "Fastly Test IPv6"
as_number = 12345
area_code = 123
city = "Test City IPv6"
conn_speed = "broadband"
conn_type = "wired"
continent = "NA"
country_code = "CA"
country_code3 = "CAN"
country_name = "Canada"
latitude = 12.345
longitude = 54.321
metro_code = 0
postal_code = "12345"
proxy_description = "?"
proxy_type = "?"
region = "BC"
utc_offset = -700
"#;
let resp = Test::using_fixture("geolocation-lookup.wasm")
.using_fastly_toml(FASTLY_TOML)?
.against_empty()
.await;
assert_eq!(resp.status(), StatusCode::OK);
assert!(to_bytes(resp.into_body())
.await
.expect("can read body")
.to_vec()
.is_empty());
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn default_configuration_geolocation_lookup_works() -> TestResult {
const FASTLY_TOML: &str = r#"
name = "default-config-geolocation-lookup"
description = "default config geolocation lookup test"
authors = ["Test User <test_user@fastly.com>"]
language = "rust"
"#;
let resp = Test::using_fixture("geolocation-lookup-default.wasm")
.using_fastly_toml(FASTLY_TOML)?
.against_empty()
.await;
assert_eq!(resp.status(), StatusCode::OK);
assert!(to_bytes(resp.into_body())
.await
.expect("can read body")
.to_vec()
.is_empty());
Ok(())
}