Skip to main content

arrow_integration_testing/flight_server_scenarios/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Collection of utilities for testing the Flight server.
6use std::net::SocketAddr;
7
8use arrow_flight::{FlightEndpoint, Location, Ticket};
9use tokio::net::TcpListener;
10
11pub mod auth_basic_proto;
12pub mod integration_test;
13pub mod middleware;
14
15type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
16type Result<T = (), E = Error> = std::result::Result<T, E>;
17
18/// Listen on a port and return the address
19pub async fn listen_on(port: u16) -> Result<SocketAddr> {
20    let addr: SocketAddr = format!("0.0.0.0:{port}").parse()?;
21
22    let listener = TcpListener::bind(addr).await?;
23    let addr = listener.local_addr()?;
24
25    Ok(addr)
26}
27
28/// Create a FlightEndpoint with a ticket and location
29pub fn endpoint(ticket: &str, location_uri: impl Into<String>) -> FlightEndpoint {
30    FlightEndpoint {
31        ticket: Some(Ticket {
32            ticket: ticket.as_bytes().to_vec().into(),
33        }),
34        location: vec![Location {
35            uri: location_uri.into(),
36        }],
37        expiration_time: None,
38        app_metadata: vec![].into(),
39    }
40}