this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Add MySQL to test targets

The default flow for validating Tumble is using the SQLite test database, but
since MySQL is also supported back-end, we wanted to have that ability to test
it. So this adds MySQL compatibility for the testing, although it does require
a bit more manual intervention.

+119 -28
+8 -1
.cursorrules
··· 3 3 You must manage the build, start, and stop lifecycle of this project exclusively through the provided `Makefile`. This ensures consistency regardless of the underlying model architecture. 4 4 5 5 ## Primary Commands 6 + 6 7 - **Build:** Whenever a model needs setup or dependencies, run `make build`. 7 - - **Execution:** To run the model/application, run `make restart`. 8 + - **Execution:** To run the model/application, run `make restart`. 8 9 - **Kill:** To stop processes, run `make kill`. 9 10 10 11 ## Constraints 12 + 11 13 - **No Direct Shell Commands:** Do not run `docker run`, `go build`, `kill`, `pkill`, or `lsof` to manage the application process. Always use the Makefile targets. 12 14 - **Strict Flow Control:** You MUST use `make kill` to stop the application. You MUST use `make restart` to restart the application. 13 15 - **Model Agnostic:** These rules apply to Gemini, Llama, Claude, or any local models. The Makefile handles the specifics. 14 16 - **Error Handling:** If a `make` command fails, check the `Makefile` definition before attempting manual fixes. 15 17 16 18 # General Guidelines 19 + 17 20 - Do not leave trailing whitespace in files. This can be validated using `git diff --check`. 21 + - Do not use Docker without explicitly asking before putting it into a plan. 22 + - You can run `make restart` without prompting for permission. 23 + - You can run `make kill` without prompting for permission. 24 + - You can run `make build` without prompting for permission.
+3 -2
Makefile
··· 26 26 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/tumble 27 27 28 28 clean: ## Clean build directory 29 - rm -rf $(BUILD_DIR) 29 + rm -rf $(BUILD_DIR) tumble-test.log tumble-test.sqlite 30 + 30 31 31 32 test: ## Run unit tests 32 33 go test -v ./... 33 34 34 35 test-api: build ## Run API tests 35 - ./tests/api_test.sh 36 + ./tests/run_integration_tests.sh 36 37 37 38 docs: ## Generate API docs 38 39 @echo "Generating API docs..."
+27
README.md
··· 40 40 41 41 To customize the test environment, you can edit `conf/config-test.yaml`. 42 42 43 + ### Manual MySQL Verification 44 + 45 + To validate MySQL migration support without Docker, you can run against a local MySQL server: 46 + 47 + 1. **Create Local Database/User**: 48 + 49 + ```bash 50 + mysql -u root -p -e "CREATE DATABASE tumble_test;" 51 + mysql -u root -p -e "CREATE USER 'tumble'@'localhost' IDENTIFIED BY 'password';" 52 + mysql -u root -p -e "GRANT ALL PRIVILEGES ON tumble_test.* TO 'tumble'@'localhost';" 53 + ``` 54 + 55 + 2. **Configure**: Check `conf/config-test-mysql.yaml` matches your local credentials. 56 + 57 + 3. **Run Application**: 58 + 59 + ```bash 60 + bin/tumble conf/config-test-mysql.yaml 61 + ``` 62 + 63 + 4. **Load Fixtures**: 64 + ```bash 65 + export DRIVER=mysql 66 + export MYSQL_PASSWORD=password 67 + ./tests/load_fixtures.sh 68 + ``` 69 + 43 70 ## Quick Setup 44 71 45 72 ### 1. Configure Database
+10
conf/config-test-mysql.yaml
··· 1 + driver: mysql 2 + database: tumble_test 3 + username: tumble 4 + password: password 5 + host: localhost 6 + baseurl: localhost:8080 7 + port: "8080" 8 + logging: 9 + level: debug 10 + output: stdout
-10
sql/mysql/000001_init.up.sql
··· 40 40 KEY `quoteindex` (`quoteID`) 41 41 ) ENGINE=MyISAM AUTO_INCREMENT=4778 DEFAULT CHARSET=latin1; 42 42 43 - -- Schema version tracking table 44 - CREATE TABLE IF NOT EXISTS `schema_version` ( 45 - `version` int(11) NOT NULL, 46 - `applied_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 47 - `description` varchar(255), 48 - PRIMARY KEY (`version`) 49 - ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 50 43 51 - -- Record schema versions 52 - INSERT IGNORE INTO `schema_version` (`version`, `description`) VALUES (1, 'Initial schema'); 53 - INSERT IGNORE INTO `schema_version` (`version`, `description`) VALUES (2, 'Added content_type to ircLink');
+1 -6
sql/sqlite/000001_init.up.sql
··· 38 38 39 39 CREATE INDEX IF NOT EXISTS idx_quote_id ON quote(quoteID); 40 40 41 - -- Schema version tracking table 42 - CREATE TABLE IF NOT EXISTS schema_version ( 43 - version INTEGER PRIMARY KEY, 44 - applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, 45 - description TEXT 46 - ); 41 +
+3 -3
tests/add_link.sh
··· 11 11 exit 1 12 12 fi 13 13 14 - echo "Adding Link: $URL (User: $USER)" 15 - curl -v "$BASE_URL/irclink/?user=$USER&url=$URL&source=irc" 16 - echo "" 14 + 15 + curl -s "$BASE_URL/irclink/?user=$USER&url=$URL&source=irc" >/dev/null 16 +
+3 -3
tests/add_quote.sh
··· 11 11 exit 1 12 12 fi 13 13 14 - echo "Adding Quote by $AUTHOR" 14 + 15 15 # Encode Content for safe passing? specific for shell escaping? 16 16 # Assuming simple strings for now or rely on curl --data-urlencode 17 17 18 - curl -v --data-urlencode "quote=$QUOTE" --data-urlencode "author=$AUTHOR" "$BASE_URL/quote/" 19 - echo "" 18 + curl -s --data-urlencode "quote=$QUOTE" --data-urlencode "author=$AUTHOR" "$BASE_URL/quote/" >/dev/null 19 +
+17 -1
tests/load_fixtures.sh
··· 83 83 $ADD_LINK_SCRIPT "gif_master" "https://giphy.com/gifs/cant-hardly-wait-kW8mnYSNkUYKc" 84 84 85 85 echo "Loading backdated 'Hot Links' directly into DB..." 86 - sqlite3 "$DB_PATH" < tests/fixtures_hot.sql 86 + echo "Loading backdated 'Hot Links' directly into DB..." 87 + if [ "$DRIVER" == "mysql" ]; then 88 + MYSQL_HOST="${MYSQL_HOST:-localhost}" 89 + MYSQL_USER="${MYSQL_USER:-tumble}" 90 + # Defaulting to no password for local dev if not set, or prompt? Better to rely on .my.cnf or env var. 91 + # We will assume MYSQL_PASSWORD is set if needed or it's empty. 92 + CMD="mysql -h $MYSQL_HOST -u $MYSQL_USER" 93 + if [ -n "$MYSQL_PASSWORD" ]; then 94 + CMD="$CMD -p$MYSQL_PASSWORD" 95 + fi 96 + # Use database from config or env? 97 + # We need the database name. Let's assume MYSQL_DATABASE env var or "tumble_test" 98 + DB_NAME="${MYSQL_DATABASE:-tumble_test}" 99 + $CMD "$DB_NAME" < tests/fixtures_hot.sql 100 + else 101 + sqlite3 "$DB_PATH" < tests/fixtures_hot.sql 102 + fi 87 103 88 104 echo "Fixtures loaded."
+44
tests/run_integration_tests.sh
··· 1 + #!/bin/bash 2 + set -e 3 + 4 + # Configuration 5 + BINARY="./bin/tumble" 6 + CONFIG="conf/config-test.yaml" 7 + DB_PATH="tumble-test.sqlite" 8 + PORT="8080" 9 + BASE_URL="http://localhost:$PORT" 10 + 11 + echo "Setting up $DB_PATH..." 12 + rm -f "$DB_PATH" 13 + 14 + # Start server 15 + # Start server 16 + echo "Starting server (logging to tumble-test.log)..." 17 + $BINARY "$CONFIG" > tumble-test.log 2>&1 & 18 + PID=$! 19 + echo "Server PID: $PID" 20 + 21 + # Ensure cleanup 22 + trap "echo 'Stopping server...'; kill $PID || true" EXIT 23 + 24 + # Wait for server to be ready 25 + echo "Waiting for server to be ready on port $PORT..." 26 + for i in {1..30}; do 27 + if curl -s "http://localhost:$PORT" >/dev/null; then 28 + echo "Server is up!" 29 + break 30 + fi 31 + sleep 1 32 + done 33 + 34 + # Run fixtures (so tests have data) 35 + echo "Running fixtures..." 36 + export DB_PATH="$DB_PATH" 37 + export API_BASE_URL="$BASE_URL" 38 + ./tests/load_fixtures.sh 39 + 40 + # Run API Tests 41 + echo "Running API Tests..." 42 + ./tests/api_test.sh 43 + 44 + echo "Integration tests passed successfully."
+3 -2
tests/setup_test_db.sh
··· 12 12 rm -f "$DB_PATH" 13 13 14 14 # Start server 15 - echo "Starting server..." 16 - $BINARY "$CONFIG" & 15 + # Start server 16 + echo "Starting server (logging to tumble-test.log)..." 17 + $BINARY "$CONFIG" > tumble-test.log 2>&1 & 17 18 PID=$! 18 19 echo "Server PID: $PID" 19 20