Skip to content

Commit dda76bd

Browse files
authored
chore: improve test coverage (#426)
* chore: improve test coverage * fix: remove temporary files to save disk space * save disk space * save disk space * save disk space * save disk space * combine native and wasm test * remove wasm test * add logflare test case * format test code
1 parent 4557a1f commit dda76bd

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed

.github/workflows/coverage.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
pkg-config \
4949
postgresql-15 \
5050
postgresql-server-dev-15
51+
sudo apt-get -y autoremove && sudo apt-get -y clean
5152
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/
5253
5354
- run: cargo install cargo-pgrx --version 0.12.9

wrappers/.ci/docker-compose-native.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ services:
147147
interval: 11s
148148
timeout: 6s
149149
retries: 3
150+
151+
logflare:
152+
container_name: logflare-local
153+
build:
154+
context: ../dockerfiles/logflare
155+
ports:
156+
- "4343:4343"
157+
healthcheck:
158+
test: curl --fail http://0.0.0.0:4343/v1/endpoint || exit 1
159+
interval: 11s
160+
timeout: 6s
161+
retries: 3
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.13.2-slim
2+
3+
WORKDIR /usr/src/app
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends curl
7+
8+
COPY . .
9+
RUN pip install -r requirements.txt
10+
11+
CMD [ "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "4343" ]
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"result": [
3+
{
4+
"event_message": "Sent 200 in 4ms",
5+
"id": "84e1ed2a-3627-4d70-b311-c0e7c0bed313",
6+
"metadata": [
7+
{
8+
"application_name": null,
9+
"callers": [],
10+
"context": [
11+
{
12+
"application": "phoenix",
13+
"domain": [
14+
"elixir"
15+
],
16+
"file": "lib/phoenix/logger.ex",
17+
"function": "phoenix_endpoint_stop/4",
18+
"gl": "<0.2934.0>",
19+
"line": 231,
20+
"mfa": [
21+
"Elixir.Phoenix.Logger",
22+
"phoenix_endpoint_stop",
23+
"4"
24+
],
25+
"module": "Elixir.Phoenix.Logger",
26+
"pid": "<0.2224935.0>",
27+
"registered_name": null,
28+
"time": 1739866449830697,
29+
"vm": [
30+
{
31+
"node": "realtime@2a05:d01c:582:c001:78f1:89cb:ccc2:e853"
32+
}
33+
]
34+
}
35+
],
36+
"depth": null,
37+
"error_code": null,
38+
"error_logger": [],
39+
"error_string": null,
40+
"external_id": null,
41+
"formatter_error_params": [],
42+
"func": null,
43+
"internal_log_event": null,
44+
"level": "info",
45+
"logger_pubsub_backend": [],
46+
"measurements": [],
47+
"mod": null,
48+
"project": null,
49+
"region": "eu-west-2",
50+
"request_id": "GCU_UWKIIGEd25gAQTbB",
51+
"stacktrace": [],
52+
"target": null,
53+
"tenant": null,
54+
"tenant_params": []
55+
}
56+
],
57+
"timestamp": 1739866449830000
58+
},
59+
{
60+
"event_message": "GET /",
61+
"id": "f45121ea-1738-46c9-a506-9ee52ff8220f",
62+
"metadata": [
63+
{
64+
"application_name": null,
65+
"callers": [],
66+
"context": [
67+
{
68+
"application": "phoenix",
69+
"domain": [
70+
"elixir"
71+
],
72+
"file": "lib/phoenix/logger.ex",
73+
"function": "phoenix_endpoint_start/4",
74+
"gl": "<0.2934.0>",
75+
"line": 217,
76+
"mfa": [
77+
"Elixir.Phoenix.Logger",
78+
"phoenix_endpoint_start",
79+
"4"
80+
],
81+
"module": "Elixir.Phoenix.Logger",
82+
"pid": "<0.2224935.0>",
83+
"registered_name": null,
84+
"time": 1739866449826598,
85+
"vm": [
86+
{
87+
"node": "realtime@2a05:d01c:582:c001:78f1:89cb:ccc2:e853"
88+
}
89+
]
90+
}
91+
],
92+
"depth": null,
93+
"error_code": null,
94+
"error_logger": [],
95+
"error_string": null,
96+
"external_id": null,
97+
"formatter_error_params": [],
98+
"func": null,
99+
"internal_log_event": null,
100+
"level": "info",
101+
"logger_pubsub_backend": [],
102+
"measurements": [],
103+
"mod": null,
104+
"project": null,
105+
"region": "eu-west-2",
106+
"request_id": "GCU_UWKIIGEd25gAQTbB",
107+
"stacktrace": [],
108+
"target": null,
109+
"tenant": null,
110+
"tenant_params": []
111+
}
112+
],
113+
"timestamp": 1739866449826000
114+
}
115+
]
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastapi
2+
uvicorn
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import http.server
4+
import socketserver
5+
import json
6+
7+
from typing import Union
8+
from fastapi import APIRouter, FastAPI, HTTPException
9+
10+
router = APIRouter(prefix="/v1")
11+
data = json.loads(open("data.json").read())
12+
13+
@router.get("/{endpoint:path}")
14+
def endpoint():
15+
return data
16+
17+
app = FastAPI()
18+
app.include_router(router)

wrappers/src/fdw/logflare_fdw/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::module_inception)]
22
mod logflare_fdw;
3+
mod tests;
34

45
use http::header::InvalidHeaderValue;
56
use pgrx::pg_sys::panic::ErrorReport;
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#[cfg(any(test, feature = "pg_test"))]
2+
#[pgrx::pg_schema]
3+
mod tests {
4+
use pgrx::prelude::*;
5+
6+
#[pg_test]
7+
fn logflare_smoketest() {
8+
Spi::connect(|mut c| {
9+
c.update(
10+
r#"CREATE FOREIGN DATA WRAPPER logflare_wrapper
11+
HANDLER logflare_fdw_handler VALIDATOR logflare_fdw_validator"#,
12+
None,
13+
None,
14+
)
15+
.unwrap();
16+
c.update(
17+
r#"CREATE SERVER logflare_server
18+
FOREIGN DATA WRAPPER logflare_wrapper
19+
OPTIONS (
20+
api_url 'http://localhost:4343/v1/endpoint',
21+
api_key 'apiKey'
22+
)"#,
23+
None,
24+
None,
25+
)
26+
.unwrap();
27+
c.update(
28+
r#"
29+
CREATE FOREIGN TABLE logflare_table (
30+
id text,
31+
timestamp bigint,
32+
event_message text,
33+
_result text
34+
)
35+
SERVER logflare_server
36+
OPTIONS (
37+
endpoint '3d48cbfe-5d65-494f-be06-910479aed6c1'
38+
)
39+
"#,
40+
None,
41+
None,
42+
)
43+
.unwrap();
44+
45+
let results = c
46+
.select("SELECT * FROM logflare_table", None, None)
47+
.unwrap()
48+
.filter_map(|r| r.get_by_name::<&str, _>("id").unwrap())
49+
.collect::<Vec<_>>();
50+
51+
assert_eq!(
52+
results,
53+
vec![
54+
"84e1ed2a-3627-4d70-b311-c0e7c0bed313",
55+
"f45121ea-1738-46c9-a506-9ee52ff8220f"
56+
]
57+
);
58+
});
59+
}
60+
}

0 commit comments

Comments
 (0)