@@ -8,7 +8,45 @@ pub struct SubgraphArgs {
88}
99
1010impl SubgraphArgs {
11- pub async fn to_subgraph_client ( & self ) -> Result < OrderbookSubgraphClient , ParseError > {
11+ pub fn to_subgraph_client ( & self ) -> Result < OrderbookSubgraphClient , ParseError > {
1212 Ok ( OrderbookSubgraphClient :: new ( Url :: parse ( self . url . as_str ( ) ) ?) )
1313 }
1414}
15+
16+ #[ cfg( test) ]
17+ mod tests {
18+ use super :: * ;
19+
20+ #[ test]
21+ fn test_to_subgraph_client_ok ( ) {
22+ let url = "https://api.thegraph.com/subgraphs/name/org1/sg1" ;
23+ let subgraph_args = SubgraphArgs {
24+ url : url. to_string ( ) ,
25+ } ;
26+ let subgraph_client = subgraph_args. to_subgraph_client ( ) . unwrap ( ) ;
27+ assert_eq ! ( subgraph_client. url( ) . as_str( ) , url) ;
28+ }
29+
30+ #[ test]
31+ fn test_to_subgraph_client_err ( ) {
32+ let url = "api.thegraph.com/subgraphs/name/org1/sg1" . to_string ( ) ;
33+ let subgraph_args = SubgraphArgs { url } ;
34+ let err = subgraph_args. to_subgraph_client ( ) . unwrap_err ( ) ;
35+ assert_eq ! ( err, ParseError :: RelativeUrlWithoutBase ) ;
36+
37+ let url = "https:///" . to_string ( ) ;
38+ let subgraph_args = SubgraphArgs { url } ;
39+ let err = subgraph_args. to_subgraph_client ( ) . unwrap_err ( ) ;
40+ assert_eq ! ( err, ParseError :: EmptyHost ) ;
41+
42+ let url = "" . to_string ( ) ;
43+ let subgraph_args = SubgraphArgs { url } ;
44+ let err = subgraph_args. to_subgraph_client ( ) . unwrap_err ( ) ;
45+ assert_eq ! ( err, ParseError :: RelativeUrlWithoutBase ) ;
46+
47+ let url = ":" . to_string ( ) ;
48+ let subgraph_args = SubgraphArgs { url } ;
49+ let err = subgraph_args. to_subgraph_client ( ) . unwrap_err ( ) ;
50+ assert_eq ! ( err, ParseError :: RelativeUrlWithoutBase ) ;
51+ }
52+ }
0 commit comments