Merge pull request 'ci/test: add gitea workflow and comprehensive test coverage' (#5) from ci/test-workflow into main

This commit was merged in pull request #5.
This commit is contained in:
2026-05-03 03:30:59 +00:00
2 changed files with 72 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
name: Test PR
on:
pull_request:
branches:
- main
jobs:
test:
if: "!contains(github.event.pull_request.labels.*.name, 'Kind/Documentation')"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Make scripts executable
run: |
chmod +x color-tool
chmod +x tests/run_tests.sh
- name: Run test suite
run: ./tests/run_tests.sh
+50 -1
View File
@@ -47,7 +47,18 @@ ln -s /usr/bin/mkdir "$BIN_DIR/mkdir"
ln -s /usr/bin/mktemp "$BIN_DIR/mktemp"
ln -s /usr/bin/chmod "$BIN_DIR/chmod"
ln -s /usr/bin/rm "$BIN_DIR/rm"
ln -s /usr/bin/curl "$BIN_DIR/curl"
# Mock curl for thecolorapi.com
cat <<'MOCK' > "$BIN_DIR/curl"
#!/bin/bash
if [[ "$*" == *"thecolorapi.com"* ]]; then
echo '{"name": {"value": "Mocked Color Name"}}'
exit 0
fi
exec /usr/bin/curl "$@"
MOCK
chmod +x "$BIN_DIR/curl"
ln -s /usr/bin/mv "$BIN_DIR/mv"
ln -s /usr/bin/tr "$BIN_DIR/tr"
export PATH="$BIN_DIR"
export HOME="$TEST_DIR"
@@ -139,6 +150,44 @@ else
echo "FAIL (notify.log not created)"
fi
# 9. JSON Output
it "outputs selected formats as JSON"
output=$("$COLOR_TOOL" "#00ff00" --output hex,rgb --json --no-copy --no-notify)
if [[ "$output" == *'"hex": "#00ff00"'* ]] && [[ "$output" == *'"rgb": "rgb(0, 255, 0)"'* ]]; then
echo "PASS"
passed=$((passed + 1))
else
echo "FAIL"
echo " Actual output: $output"
fi
# 10. Swatch Output
it "outputs visual swatch"
output=$("$COLOR_TOOL" "#112233" --output hex --swatch --no-copy --no-notify)
if [[ "$output" == *"$(printf "\033[48;2;17;34;51m \033[0m")"* ]] && [[ "$output" == *"#112233"* ]]; then
echo "PASS"
passed=$((passed + 1))
else
echo "FAIL"
echo " Actual output: $output"
fi
# 11. Color Name Fetching
it "fetches color name from thecolorapi.com"
output=$("$COLOR_TOOL" "#ffffff" --output hex --name --no-copy --no-notify)
assert_contains "$output" "(Mocked Color Name)"
# 12. Invalid Color Input
it "rejects invalid colors"
output=$("$COLOR_TOOL" "invalid-color" --no-copy --no-notify 2>&1 || true)
assert_contains "$output" "Error: Invalid color: invalid-color"
# 13. Invalid Format Input
it "rejects invalid formats"
output=$("$COLOR_TOOL" "#000000" --output badfmt --no-copy --no-notify 2>&1 || true)
assert_contains "$output" "Error: Invalid output format: badfmt"
# ── Cleanup ───────────────────────────────────────────────────────────────────
echo "---------------------------------------"
echo "Result: $passed/$total tests passed."