-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
972f8d5
commit 9b08f52
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
defmodule Ch.HeadersTest do | ||
use ExUnit.Case, async: true | ||
|
||
setup do | ||
{:ok, conn} = Ch.start_link() | ||
{:ok, conn: conn} | ||
end | ||
|
||
test "can request gzipped response through headers", %{conn: conn} do | ||
assert {:ok, %{rows: rows, headers: headers}} = | ||
Ch.query(conn, "select number from system.numbers limit 100", [], | ||
decode: false, | ||
settings: [enable_http_compression: 1], | ||
headers: [{"accept-encoding", "gzip"}] | ||
) | ||
|
||
assert :proplists.get_value("content-type", headers) == "application/octet-stream" | ||
assert :proplists.get_value("content-encoding", headers) == "gzip" | ||
assert :proplists.get_value("x-clickhouse-format", headers) == "RowBinaryWithNamesAndTypes" | ||
|
||
# https://en.wikipedia.org/wiki/Gzip | ||
assert <<0x1F, 0x8B, _rest::bytes>> = IO.iodata_to_binary(rows) | ||
end | ||
|
||
test "can request lz4 response through headers", %{conn: conn} do | ||
assert {:ok, %{rows: rows, headers: headers}} = | ||
Ch.query(conn, "select number from system.numbers limit 100", [], | ||
decode: false, | ||
settings: [enable_http_compression: 1], | ||
headers: [{"accept-encoding", "lz4"}] | ||
) | ||
|
||
assert :proplists.get_value("content-type", headers) == "application/octet-stream" | ||
assert :proplists.get_value("content-encoding", headers) == "lz4" | ||
assert :proplists.get_value("x-clickhouse-format", headers) == "RowBinaryWithNamesAndTypes" | ||
|
||
# https://en.wikipedia.org/wiki/LZ4_(compression_algorithm) | ||
assert <<0x04, 0x22, 0x4D, 0x18, _rest::bytes>> = IO.iodata_to_binary(rows) | ||
end | ||
|
||
test "can request zstd response through headers", %{conn: conn} do | ||
assert {:ok, %{rows: rows, headers: headers}} = | ||
Ch.query(conn, "select number from system.numbers limit 100", [], | ||
decode: false, | ||
settings: [enable_http_compression: 1], | ||
headers: [{"accept-encoding", "zstd"}] | ||
) | ||
|
||
assert :proplists.get_value("content-type", headers) == "application/octet-stream" | ||
assert :proplists.get_value("content-encoding", headers) == "zstd" | ||
assert :proplists.get_value("x-clickhouse-format", headers) == "RowBinaryWithNamesAndTypes" | ||
|
||
# https://en.wikipedia.org/wiki/LZ4_(compression_algorithm) | ||
assert <<0x28, 0xB5, 0x2F, 0xFD, _rest::bytes>> = IO.iodata_to_binary(rows) | ||
end | ||
end |