Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some E2E testing #4

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
run-python-e2e-tests:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Cache
uses: actions/cache@v3.2.6
with:
path: |
~/.cargo
target
key: build-${{ runner.os }}
restore-keys: |
build-${{ runner.os }}
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
- run: pip install -r requirements.txt
- run: mkdir tests/markdown_files
- name: Run dev Custard in background
run: cargo run -- 4000 tests/markdown_files
# - name: Wait for Custard
# run: sleep 1
# - name: Run Python test(s)
# run: pytest tests/python
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
__pycache__
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==7.4.3
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use notify::{RecursiveMode, Watcher};
use frontmatter_file::FrontmatterFile;
use utf8_filepath::UTF8FilePath;

async fn health() -> Result<(), StatusCode> {
Ok(())
}

async fn frontmatter_query_post(
State(markdown_files): State<frontmatter_file::map::ArcMutex>,
Json(query): Json<FrontmatterQuery>,
Expand Down Expand Up @@ -186,6 +190,7 @@ async fn run() -> Result<()> {
watcher.watch(&current_dir, RecursiveMode::NonRecursive)?;

let app = Router::new()
.route("/health", routing::get(health))
.route("/frontmatter/query", routing::post(frontmatter_query_post))
.route("/frontmatter/list", routing::get(frontmatter_list_get))
.route(
Expand Down
48 changes: 48 additions & 0 deletions tests/python/test_file_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import urllib.request
from time import sleep

import pytest

@pytest.fixture
def test_file_path():
file_path = "tests/markdown_files/test.md"
yield file_path
if os.path.exists(file_path):
os.remove(file_path)

def test_file_tracking(test_file_path: str):
with urllib.request.urlopen("http://127.0.0.1:4000/health") as response:
assert response.getcode() == 200

# File doesn't exist
with pytest.raises(urllib.request.HTTPError):
with urllib.request.urlopen("http://127.0.0.1:4000/frontmatter/file/test.md") as response:
assert response.getcode() == 404

with open(test_file_path, "x") as f:
f.write("Just call me mark!\n")
f.flush()
sleep(1)

# Custard recognizes created file
with urllib.request.urlopen("http://127.0.0.1:4000/frontmatter/file/test.md") as response:
assert response.getcode() == 200
with open(test_file_path, "a") as f:
f.write("I'm a markdown file!\n")
f.flush()
sleep(1)

# Custard has updated on file edit
with urllib.request.urlopen("http://127.0.0.1:4000/frontmatter/file/test.md") as response:
assert response.read().decode() == """Just call me mark!
I'm a markdown file!
"""
os.remove(test_file_path)
sleep(1)

# Custard recognizes file deleted
with pytest.raises(urllib.request.HTTPError):
with urllib.request.urlopen("http://127.0.0.1:4000/frontmatter/file/test.md") as response:
assert response.getcode() == 404

Loading