Skip to content

Commit

Permalink
added e2e test for encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Jan 21, 2025
1 parent d7b7782 commit 22e114a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/saffron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Saffron CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
run:
name: Run saffron e2e tests

runs-on: ["ubuntu-latest"]

strategy:
matrix:
rust_toolchain_version: ["1.74"]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Use shared Rust toolchain setting up steps
uses: ./.github/actions/toolchain-shared
with:
rust_toolchain_version: ${{ matrix.rust_toolchain_version }}

- name: Apply the Rust smart cacheing
uses: Swatinem/rust-cache@v2

- name: Build the saffron cli binary
run: |
cargo build --release --bin saffron
- name: Run the saffron e2e encoding tests
run: |
./saffron/test-encoding.sh saffron/fixtures/lorem.txt
2 changes: 0 additions & 2 deletions saffron/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
proptest-regressions
fixtures/lorem.bin
fixtures/lorem-decoded.txt
46 changes: 38 additions & 8 deletions saffron/test-encoding.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
#!/bin/bash

# Run encode and decode
cargo run --bin saffron encode -i fixtures/lorem.txt -o fixtures/lorem.bin
cargo run --bin saffron decode -i fixtures/lorem.bin -o fixtures/lorem-decoded.txt
# Check if input file is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_file>"
exit 1
fi

INPUT_FILE="$1"
ENCODED_FILE="${INPUT_FILE%.*}.bin"
DECODED_FILE="${INPUT_FILE%.*}-decoded${INPUT_FILE##*.}"

# Ensure input file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: Input file '$INPUT_FILE' does not exist"
exit 1
fi

# Run encode
echo "Encoding $INPUT_FILE to $ENCODED_FILE"
if ! cargo run --bin saffron encode -i "$INPUT_FILE" -o "$ENCODED_FILE"; then
echo "Encoding failed"
exit 1
fi

# Run decode
echo "Decoding $ENCODED_FILE to $DECODED_FILE"
if ! cargo run --bin saffron decode -i "$ENCODED_FILE" -o "$DECODED_FILE"; then
echo "Decoding failed"
exit 1
fi

# Compare files
if cmp -s fixtures/lorem.txt fixtures/lorem-decoded.txt; then
echo "Files are identical"
echo "Comparing original and decoded files..."
if cmp -s "$INPUT_FILE" "$DECODED_FILE"; then
echo "✓ Success: Files are identical"
echo "Cleaning up temporary files..."
rm -f "$ENCODED_FILE" "$DECODED_FILE"
exit 0
else
echo "Files differ"
diff fixtures/lorem.txt fixtures/lorem-decoded.txt
echo "✗ Error: Files differ"
echo "Keeping temporary files for inspection"
diff "$INPUT_FILE" "$DECODED_FILE"
exit 1
fi
fi

0 comments on commit 22e114a

Please sign in to comment.