Skip to content

Commit

Permalink
fix(shell): Improve shell script exit code handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AIFlowML committed Jan 3, 2025
1 parent a66628e commit 7d854f2
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/adapter-postgres/src/__tests__/run_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,23 @@ if [ ! -f "$SCHEMA_PATH" ]; then
exit 1
fi

$DOCKER_COMPOSE_CMD -f docker-compose.test.yml exec -T postgres-test psql -U postgres -d eliza_test -f - < "$SCHEMA_PATH"
if [ $? -ne 0 ]; then
# Fix: Check exit code directly instead of using $?
if ! $DOCKER_COMPOSE_CMD -f docker-compose.test.yml exec -T postgres-test psql -U postgres -d eliza_test -f - < "$SCHEMA_PATH"; then
echo -e "${RED}Failed to load schema${NC}"
exit 1
fi
echo -e "${GREEN}Schema loaded successfully!${NC}"

# Run the tests
echo -e "${YELLOW}Running tests...${NC}"
pnpm vitest vector-extension.test.ts
if ! pnpm vitest vector-extension.test.ts; then
echo -e "${RED}Tests failed!${NC}"
$DOCKER_COMPOSE_CMD -f docker-compose.test.yml down
exit 1
fi

# Capture test exit code
TEST_EXIT_CODE=$?
echo -e "${GREEN}Tests completed successfully!${NC}"

# Clean up
echo -e "${YELLOW}Cleaning up test environment...${NC}"
$DOCKER_COMPOSE_CMD -f docker-compose.test.yml down

# Exit with test exit code
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}Tests completed successfully!${NC}"
else
echo -e "${RED}Tests failed!${NC}"
fi

exit $TEST_EXIT_CODE
$DOCKER_COMPOSE_CMD -f docker-compose.test.yml down

0 comments on commit 7d854f2

Please sign in to comment.