Skip to content

Commit cd62922

Browse files
committed
server: add tests for graphman config check graphql api
1 parent 4e7824e commit cd62922

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
pub mod util;
2+
3+
use graph::log::logger;
4+
use graphman::config::Config;
5+
use serde_json::json;
6+
7+
use self::util::client::send_graphql_request;
8+
use self::util::run_test;
9+
use self::util::server::VALID_TOKEN;
10+
11+
#[test]
12+
fn graphql_can_validate_config_and_subgraphs_settings_config() {
13+
run_test(|| async {
14+
let curr_dir = std::env::current_dir()
15+
.unwrap()
16+
.to_str()
17+
.unwrap()
18+
.to_string();
19+
let config_dir = format!("{}/tests/test_config.toml", curr_dir);
20+
let subgraph_settings_dir = format!("{}/tests/test_subgraph_settings.toml", curr_dir);
21+
std::env::set_var("GRAPH_NODE_CONFIG", config_dir);
22+
std::env::set_var(
23+
"GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS",
24+
subgraph_settings_dir,
25+
);
26+
27+
let resp = send_graphql_request(
28+
json!({
29+
"query": r#"{
30+
config {
31+
check {
32+
configValidated
33+
subgraphSettingsValidated
34+
}
35+
}
36+
}"#
37+
}),
38+
VALID_TOKEN,
39+
)
40+
.await;
41+
42+
let expected_resp = json!({
43+
"data": {
44+
"config": {
45+
"check": {
46+
"configValidated": true,
47+
"subgraphSettingsValidated": true
48+
}
49+
}
50+
}
51+
});
52+
53+
assert_eq!(resp, expected_resp);
54+
});
55+
}
56+
57+
#[test]
58+
fn graphql_can_return_config_as_json_string() {
59+
run_test(|| async {
60+
let curr_dir = std::env::current_dir()
61+
.unwrap()
62+
.to_str()
63+
.unwrap()
64+
.to_string();
65+
let config_dir = format!("{}/tests/test_config.toml", curr_dir);
66+
std::env::set_var("GRAPH_NODE_CONFIG", config_dir.clone());
67+
68+
let resp = send_graphql_request(
69+
json!({
70+
"query": r#"{
71+
config {
72+
check {
73+
config
74+
}
75+
}
76+
}"#
77+
}),
78+
VALID_TOKEN,
79+
)
80+
.await;
81+
82+
let config = Config::from_file(&logger(true), &config_dir, "default")
83+
.unwrap()
84+
.to_json()
85+
.unwrap();
86+
87+
assert_eq!(
88+
resp.get("data")
89+
.unwrap()
90+
.get("config")
91+
.unwrap()
92+
.get("check")
93+
.unwrap()
94+
.get("config")
95+
.unwrap()
96+
.as_str()
97+
.unwrap(),
98+
config
99+
);
100+
});
101+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[general]
2+
query = "query_node_.*"
3+
4+
[store]
5+
[store.primary]
6+
connection = "postgresql://postgres:1.1.1.1@test/primary"
7+
pool_size = [
8+
{ node = "index_node_1_.*", size = 2 },
9+
{ node = "index_node_2_.*", size = 10 },
10+
{ node = "index_node_3_.*", size = 10 },
11+
{ node = "index_node_4_.*", size = 2 },
12+
{ node = "query_node_.*", size = 10 }
13+
]
14+
15+
[store.shard_a]
16+
connection = "postgresql://postgres:1.1.1.1@test/shard-a"
17+
pool_size = [
18+
{ node = "index_node_1_.*", size = 2 },
19+
{ node = "index_node_2_.*", size = 10 },
20+
{ node = "index_node_3_.*", size = 10 },
21+
{ node = "index_node_4_.*", size = 2 },
22+
{ node = "query_node_.*", size = 10 }
23+
]
24+
25+
[deployment]
26+
# Studio subgraphs
27+
[[deployment.rule]]
28+
match = { name = "^prefix/" }
29+
shard = "shard_a"
30+
indexers = [ "index_prefix_0",
31+
"index_prefix_1" ]
32+
33+
[[deployment.rule]]
34+
match = { name = "^custom/.*" }
35+
indexers = [ "index_custom_0" ]
36+
37+
[[deployment.rule]]
38+
shards = [ "primary", "shard_a" ]
39+
indexers = [ "index_node_1_a",
40+
"index_node_2_a",
41+
"index_node_3_a" ]
42+
43+
[chains]
44+
ingestor = "index_0"
45+
46+
[chains.mainnet]
47+
shard = "primary"
48+
provider = [
49+
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
50+
{ label = "mainnet-1", details = { type = "web3call", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }},
51+
{ label = "firehose", details = { type = "firehose", url = "http://localhost:9000", features = [] }},
52+
{ label = "substreams", details = { type = "substreams", url = "http://localhost:9000", features = [] }},
53+
]
54+
55+
[chains.ropsten]
56+
shard = "primary"
57+
provider = [
58+
{ label = "ropsten-0", url = "http://rpc.ropsten.io", transport = "rpc", features = ["archive", "traces"] }
59+
]
60+
61+
[chains.goerli]
62+
shard = "primary"
63+
provider = [
64+
{ label = "goerli-0", url = "http://rpc.goerli.io", transport = "ipc", features = ["archive"] }
65+
]
66+
67+
[chains.kovan]
68+
shard = "primary"
69+
provider = [
70+
{ label = "kovan-0", url = "http://rpc.kovan.io", transport = "ws", features = [] }
71+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[setting]]
2+
match = { name = ".*" }
3+
history_blocks = 10000
4+
5+
[[setting]]
6+
match = { name = "xxxxx" }
7+
history_blocks = 10000
8+
9+
[[setting]]
10+
match = { name = ".*!$" }
11+
history_blocks = 10000

0 commit comments

Comments
 (0)