mirror of
https://github.com/hanzo-ds/rs.git
synced 2026-10-30 20:49:56 +00:00
Cut from the upstream v0.13.3 release tag (not HEAD) so this is a pure
rename with no behaviour change. v0.13.3 is what our consumers already
resolve to: insights/rust's Cargo.lock pins clickhouse 0.13.3 and its
manifest already declares `datastore` at 0.13.x.
The load-bearing change is the HTTP auth header rename. The Datastore
server reads only X-Datastore-User / X-Datastore-Key; the upstream names
return `401 Code: 194 Authentication failed`. Every un-renamed HTTP
client is therefore unable to authenticate at all — this is a
correctness fix, not branding.
- crate `clickhouse` -> `datastore`, `clickhouse-derive` -> `datastore-derive`;
versions preserved exactly (0.13.3 / 0.2.0).
- derive macro emits `datastore::Row` in lockstep, so downstream
`#[derive(Row)]` keeps resolving.
- User-Agent reports `datastore-rs/{version}`.
- test-harness env vars CLICKHOUSE_* -> DATASTORE_*; compose uses
ghcr.io/hanzoai/datastore with /etc/datastore-server config paths.
- doc links point at docs.hanzo.ai/datastore.
- `publish = false`: the `datastore` name on crates.io belongs to an
unrelated crate, so consume this by git tag, never by version range.
CHANGELOG is truncated to a fork notice rather than find-replaced —
rewriting upstream release history would manufacture changes Datastore
never shipped. References to upstream issues keep their numbers.
82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
use crate::{create_simple_table, flush_query_log, SimpleRow};
|
|
use datastore::sql::Identifier;
|
|
use datastore::Client;
|
|
|
|
const PKG_VER: &str = env!("CARGO_PKG_VERSION");
|
|
const RUST_VER: &str = env!("CARGO_PKG_RUST_VERSION");
|
|
const OS: &str = std::env::consts::OS;
|
|
|
|
#[tokio::test]
|
|
async fn default_user_agent() {
|
|
let table_name = "chrs_default_user_agent";
|
|
let client = prepare_database!();
|
|
let expected_user_agent = format!("datastore-rs/{PKG_VER} (lv:rust/{RUST_VER}, os:{OS})");
|
|
assert_queries_user_agents(&client, table_name, &expected_user_agent).await;
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn user_agent_with_single_product_info() {
|
|
let table_name = "chrs_user_agent_with_single_product_info";
|
|
let client = prepare_database!().with_product_info("my-app", "0.1.0");
|
|
let expected_user_agent =
|
|
format!("my-app/0.1.0 datastore-rs/{PKG_VER} (lv:rust/{RUST_VER}, os:{OS})");
|
|
assert_queries_user_agents(&client, table_name, &expected_user_agent).await;
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn user_agent_with_multiple_product_info() {
|
|
let table_name = "chrs_user_agent_with_multiple_product_info";
|
|
let client = prepare_database!()
|
|
.with_product_info("my-datasource", "2.5.0")
|
|
.with_product_info("my-app", "0.1.0");
|
|
let expected_user_agent = format!(
|
|
"my-app/0.1.0 my-datasource/2.5.0 datastore-rs/{PKG_VER} (lv:rust/{RUST_VER}, os:{OS})"
|
|
);
|
|
assert_queries_user_agents(&client, table_name, &expected_user_agent).await;
|
|
}
|
|
|
|
async fn assert_queries_user_agents(client: &Client, table_name: &str, expected_user_agent: &str) {
|
|
let row = SimpleRow::new(42, "foo");
|
|
|
|
create_simple_table(client, table_name).await;
|
|
|
|
let mut insert = client.insert(table_name).unwrap();
|
|
insert.write(&row).await.unwrap();
|
|
insert.end().await.unwrap();
|
|
|
|
let rows = client
|
|
.query("SELECT ?fields FROM ?")
|
|
.bind(Identifier(table_name))
|
|
.fetch_all::<SimpleRow>()
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(rows.len(), 1);
|
|
assert_eq!(rows[0], row);
|
|
|
|
flush_query_log(client).await;
|
|
|
|
let recorded_user_agents = client
|
|
.query(&format!(
|
|
"
|
|
SELECT http_user_agent
|
|
FROM system.query_log
|
|
WHERE type = 'QueryFinish'
|
|
AND (
|
|
query LIKE 'SELECT%FROM%{table_name}%'
|
|
OR
|
|
query LIKE 'INSERT%INTO%{table_name}%'
|
|
)
|
|
ORDER BY event_time_microseconds DESC
|
|
LIMIT 2
|
|
"
|
|
))
|
|
.fetch_all::<String>()
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(recorded_user_agents.len(), 2);
|
|
assert_eq!(recorded_user_agents[0], expected_user_agent);
|
|
assert_eq!(recorded_user_agents[1], expected_user_agent);
|
|
}
|