149 lines
4.4 KiB
YAML
149 lines
4.4 KiB
YAML
name: Test Files Hash Action
|
|
|
|
on:
|
|
push:
|
|
branches: [main, develop]
|
|
pull_request:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
name: Test Action
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Run Unit Tests
|
|
run: node run-tests.js
|
|
|
|
- name: Test Action - Single File
|
|
id: test-single
|
|
uses: ./
|
|
with:
|
|
files: 'examples/sample1.txt'
|
|
algorithm: 'sha256'
|
|
|
|
- name: Verify Single File Output
|
|
run: |
|
|
echo "Hash: ${{ steps.test-single.outputs.hash }}"
|
|
echo "File Count: ${{ steps.test-single.outputs.file-count }}"
|
|
if [ "${{ steps.test-single.outputs.file-count }}" != "1" ]; then
|
|
echo "❌ Expected file count 1, got ${{ steps.test-single.outputs.file-count }}"
|
|
exit 1
|
|
fi
|
|
if [ -z "${{ steps.test-single.outputs.hash }}" ]; then
|
|
echo "❌ Hash output is empty"
|
|
exit 1
|
|
fi
|
|
echo "✅ Single file test passed"
|
|
|
|
- name: Test Action - Multiple Files
|
|
id: test-multiple
|
|
uses: ./
|
|
with:
|
|
files: 'examples/*.txt'
|
|
algorithm: 'md5'
|
|
|
|
- name: Verify Multiple Files Output
|
|
run: |
|
|
echo "Hash: ${{ steps.test-multiple.outputs.hash }}"
|
|
echo "File Count: ${{ steps.test-multiple.outputs.file-count }}"
|
|
if [ "${{ steps.test-multiple.outputs.file-count }}" != "1" ]; then
|
|
echo "❌ Expected file count 1, got ${{ steps.test-multiple.outputs.file-count }}"
|
|
exit 1
|
|
fi
|
|
echo "✅ Multiple files test passed"
|
|
|
|
- name: Test Action - All Examples
|
|
id: test-all
|
|
uses: ./
|
|
with:
|
|
files: 'examples/*'
|
|
algorithm: 'sha1'
|
|
|
|
- name: Verify All Files Output
|
|
run: |
|
|
echo "Hash: ${{ steps.test-all.outputs.hash }}"
|
|
echo "File Count: ${{ steps.test-all.outputs.file-count }}"
|
|
if [ "${{ steps.test-all.outputs.file-count }}" != "3" ]; then
|
|
echo "❌ Expected file count 3, got ${{ steps.test-all.outputs.file-count }}"
|
|
exit 1
|
|
fi
|
|
echo "✅ All files test passed"
|
|
|
|
- name: Test Action - Different Algorithm
|
|
id: test-sha512
|
|
uses: ./
|
|
with:
|
|
files: 'README.md'
|
|
algorithm: 'sha512'
|
|
|
|
- name: Verify SHA512 Output
|
|
run: |
|
|
echo "Hash: ${{ steps.test-sha512.outputs.hash }}"
|
|
echo "File Count: ${{ steps.test-sha512.outputs.file-count }}"
|
|
if [ "${{ steps.test-sha512.outputs.file-count }}" != "1" ]; then
|
|
echo "❌ Expected file count 1, got ${{ steps.test-sha512.outputs.file-count }}"
|
|
exit 1
|
|
fi
|
|
# SHA512 hash should be 128 characters long
|
|
hash_length=$(echo "${{ steps.test-sha512.outputs.hash }}" | wc -c)
|
|
if [ $hash_length -ne 129 ]; then # 128 + 1 for newline
|
|
echo "❌ SHA512 hash length should be 128, got $((hash_length-1))"
|
|
exit 1
|
|
fi
|
|
echo "✅ SHA512 test passed"
|
|
|
|
- name: Test Action - Missing Files (should fail)
|
|
id: test-missing
|
|
continue-on-error: true
|
|
uses: ./
|
|
with:
|
|
files: 'non-existent-file.txt'
|
|
algorithm: 'sha256'
|
|
|
|
- name: Verify Missing Files Handling
|
|
run: |
|
|
if [ "${{ steps.test-missing.outcome }}" == "success" ]; then
|
|
echo "❌ Expected action to fail on missing file"
|
|
exit 1
|
|
fi
|
|
echo "✅ Missing files test passed"
|
|
|
|
test-matrix:
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
node-version: ['18', '20']
|
|
name: Test on ${{ matrix.os }} with Node ${{ matrix.node-version }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v4
|
|
with:
|
|
version: 9
|
|
|
|
- name: Setup Node.js ${{ matrix.node-version }}
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ matrix.node-version }}
|
|
cache: 'pnpm'
|
|
|
|
- name: Test Action
|
|
uses: ./
|
|
with:
|
|
files: 'examples/sample1.txt'
|
|
algorithm: 'sha256'
|