@@ -99,47 +99,81 @@ impl From<supergraph_sdl_query::ResponseData> for UplinkResponse<SchemaState> {
99
99
100
100
#[ cfg( test) ]
101
101
mod test {
102
- use std:: str:: FromStr ;
103
- use std:: time:: Duration ;
104
-
105
- use futures:: stream:: StreamExt ;
106
- use secrecy:: SecretString ;
107
- use url:: Url ;
108
-
109
- use crate :: uplink:: AWS_URL ;
110
- use crate :: uplink:: Endpoints ;
111
- use crate :: uplink:: GCP_URL ;
112
- use crate :: uplink:: UplinkConfig ;
113
- use crate :: uplink:: schema:: schema_stream:: SupergraphSdlQuery ;
114
- use crate :: uplink:: stream_from_uplink;
115
-
116
- #[ tokio:: test]
117
- async fn integration_test ( ) {
118
- for url in & [ GCP_URL , AWS_URL ] {
119
- if let ( Ok ( apollo_key) , Ok ( apollo_graph_ref) ) = (
120
- std:: env:: var ( "TEST_APOLLO_KEY" ) ,
121
- std:: env:: var ( "TEST_APOLLO_GRAPH_REF" ) ,
122
- ) {
123
- let results = stream_from_uplink :: < SupergraphSdlQuery , String > ( UplinkConfig {
124
- apollo_key : SecretString :: from ( apollo_key) ,
125
- apollo_graph_ref,
126
- endpoints : Some ( Endpoints :: fallback ( vec ! [
127
- Url :: from_str( url) . expect( "url must be valid" ) ,
128
- ] ) ) ,
129
- poll_interval : Duration :: from_secs ( 1 ) ,
130
- timeout : Duration :: from_secs ( 5 ) ,
131
- } )
132
- . take ( 1 )
133
- . collect :: < Vec < _ > > ( )
134
- . await ;
135
-
136
- let schema = results
137
- . first ( )
138
- . unwrap_or_else ( || panic ! ( "expected one result from {url}" ) )
139
- . as_ref ( )
140
- . unwrap_or_else ( |_| panic ! ( "schema should be OK from {url}" ) ) ;
141
- assert ! ( schema. contains( "type Product" ) )
142
- }
143
- }
102
+ use super :: * ;
103
+
104
+ #[ test]
105
+ fn test_uplink_request_to_graphql_variables ( ) {
106
+ let request = UplinkRequest {
107
+ api_key : "test_key" . to_string ( ) ,
108
+ graph_ref : "test_ref" . to_string ( ) ,
109
+ id : Some ( "test_id" . to_string ( ) ) ,
110
+ } ;
111
+
112
+ let variables: supergraph_sdl_query:: Variables = request. into ( ) ;
113
+
114
+ assert_eq ! ( variables. api_key, "test_key" ) ;
115
+ assert_eq ! ( variables. graph_ref, "test_ref" ) ;
116
+ assert_eq ! ( variables. if_after_id, Some ( "test_id" . to_string( ) ) ) ;
117
+ }
118
+
119
+ #[ test]
120
+ fn test_graphql_response_to_uplink_response_new ( ) {
121
+ let response = supergraph_sdl_query:: ResponseData {
122
+ router_config : SupergraphSdlQueryRouterConfig :: RouterConfigResult (
123
+ supergraph_sdl_query:: SupergraphSdlQueryRouterConfigOnRouterConfigResult {
124
+ supergraph_sdl : "test_sdl" . to_string ( ) ,
125
+ id : "result_id" . to_string ( ) ,
126
+ min_delay_seconds : 42.0 ,
127
+ } ,
128
+ ) ,
129
+ } ;
130
+
131
+ let uplink_response: UplinkResponse < String > = response. into ( ) ;
132
+
133
+ assert ! ( matches!(
134
+ uplink_response,
135
+ UplinkResponse :: New { response, id, delay }
136
+ if response == "test_sdl" && id == "result_id" && delay == 42
137
+ ) ) ;
138
+ }
139
+
140
+ #[ test]
141
+ fn test_graphql_response_to_uplink_response_unchanged ( ) {
142
+ let response = supergraph_sdl_query:: ResponseData {
143
+ router_config : SupergraphSdlQueryRouterConfig :: Unchanged (
144
+ supergraph_sdl_query:: SupergraphSdlQueryRouterConfigOnUnchanged {
145
+ id : "unchanged_id" . to_string ( ) ,
146
+ min_delay_seconds : 30.0 ,
147
+ } ,
148
+ ) ,
149
+ } ;
150
+
151
+ let uplink_response: UplinkResponse < String > = response. into ( ) ;
152
+
153
+ assert ! ( matches!(
154
+ uplink_response,
155
+ UplinkResponse :: Unchanged { id, delay }
156
+ if id == Some ( "unchanged_id" . to_string( ) ) && delay == Some ( 30 )
157
+ ) ) ;
158
+ }
159
+
160
+ #[ test]
161
+ fn test_graphql_response_to_uplink_response_error ( ) {
162
+ let response = supergraph_sdl_query:: ResponseData {
163
+ router_config : SupergraphSdlQueryRouterConfig :: FetchError (
164
+ supergraph_sdl_query:: SupergraphSdlQueryRouterConfigOnFetchError {
165
+ code : FetchErrorCode :: RETRY_LATER ,
166
+ message : "Try again later" . to_string ( ) ,
167
+ } ,
168
+ ) ,
169
+ } ;
170
+
171
+ let uplink_response: UplinkResponse < String > = response. into ( ) ;
172
+
173
+ assert ! ( matches!(
174
+ uplink_response,
175
+ UplinkResponse :: Error { retry_later, code, message }
176
+ if retry_later && code == "RETRY_LATER" && message == "Try again later"
177
+ ) ) ;
144
178
}
145
179
}
0 commit comments