Skip to content
Draft
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
68 changes: 68 additions & 0 deletions __tests__/action.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,73 @@ test_comment_id_logic() {
fi
}

# Test Suite: Input Validation
test_input_validation() {
echo ""
echo -e "${YELLOW}Testing: Input Validation${NC}"
echo "========================================"

# Test that at least one check must be enabled
# Note: In action.yml, ${{ inputs.check-commits }} is evaluated to "true"/"false" strings
# before the bash script runs, so we test with string literals here

# Simulate both checks disabled (this should fail)
CHECK_COMMITS="false"
CHECK_PR="false"

if [ "$CHECK_COMMITS" = "false" ] && [ "$CHECK_PR" = "false" ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
echo -e "${GREEN}✓${NC} Both checks disabled should be detected as invalid"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
echo -e "${RED}✗${NC} Both checks disabled should be detected as invalid"
fi

# Test check-commits enabled, check-pr disabled (valid)
CHECK_COMMITS="true"
CHECK_PR="false"

if [ "$CHECK_COMMITS" = "true" ] || [ "$CHECK_PR" = "true" ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
echo -e "${GREEN}✓${NC} Only check-commits enabled should be valid"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
echo -e "${RED}✗${NC} Only check-commits enabled should be valid"
fi

# Test check-commits disabled, check-pr enabled (valid)
CHECK_COMMITS="false"
CHECK_PR="true"

if [ "$CHECK_COMMITS" = "true" ] || [ "$CHECK_PR" = "true" ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
echo -e "${GREEN}✓${NC} Only check-pull-request enabled should be valid"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
echo -e "${RED}✗${NC} Only check-pull-request enabled should be valid"
fi

# Test both checks enabled (valid)
CHECK_COMMITS="true"
CHECK_PR="true"

if [ "$CHECK_COMMITS" = "true" ] || [ "$CHECK_PR" = "true" ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
echo -e "${GREEN}✓${NC} Both checks enabled should be valid"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
echo -e "${RED}✗${NC} Both checks enabled should be valid"
fi
}

# Run all tests
main() {
echo "========================================"
Expand All @@ -283,6 +350,7 @@ main() {
test_short_sha
test_env_checks
test_comment_id_logic
test_input_validation

# Print summary
echo ""
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ runs:
fi
done

# validate that at least one check is enabled
if [ "${{ inputs.check-commits }}" = "false" ] && [ "${{ inputs.check-pull-request }}" = "false" ]; then
echo "::error title=No checks enabled::At least one of 'check-commits' or 'check-pull-request' must be set to true"
exit 1
fi

# have to do some hocus pocus since this isn't a full javascript action
main="${GITHUB_ACTION_PATH}/dist/index.js"
echo "::debug::main.js script location: $main"
Expand Down