Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme setup instructions #495

Merged
Merged
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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@ Granite is looking for volunteers to take over maintainership of the repository,
5. Create a new Pull Request

## Running tests
Granite uses Crystal's built in test framework. The tests can be run with `$ crystal spec`.
Granite uses Crystal's built in test framework. The tests can be run either within a [dockerized testing environment](#docker-setup) or [locally](#local-setup).

The test suite depends on access to a PostgreSQL, MySQL, and SQLite database to ensure the adapters work as intended.

### Docker setup

There is a self-contained testing environment provided via the `docker-compose.yml` file in this repository.
We are testing against multiple databases so you have to specify which docker-compose file you would like to use.
Replace "{database_type}" with "mysql" or "pg" or "sqlite". Before you can run the docker configuration you have to set the appropriate
env variables. To do so you can either load them yourself or modify the `.env` file that docker-compose loads by default.

You can find postgres versions at https://hub.docker.com/_/postgres/
You can find mysql versions at https://hub.docker.com/_/mysql/
- You can find postgres versions at https://hub.docker.com/_/postgres/
- You can find mysql versions at https://hub.docker.com/_/mysql/

After you have docker installed do the following to run tests:
#### Environment variable setup
##### Option 1
Export `.env` with `$ source ./export.sh` or `$ source .env`.

##### Option 2
Modify the `.env` file that docker-compose loads by default. The `.env` file can either be copied to the same directory as the docker-compose.{database_type}.yml files or passed as an option to the docker-compose commands `--env-file ./foo/.env`.

#### First run
> Replace "{database_type}" with "mysql" or "pg" or "sqlite".

```
$ docker-compose -f docker/docker-compose.{database_type}.yml build spec
Expand Down Expand Up @@ -91,5 +96,5 @@ CREATE DATABASE granite_db;
GRANT ALL PRIVILEGES ON granite_db.* TO 'granite'@'localhost' WITH GRANT OPTION;
```

4. Export `.env` with `$ source .env`
4. Export `.env` with `$ source ./export.sh` or `$ source .env`.
5. `$ crystal spec`
21 changes: 10 additions & 11 deletions export.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export PG_DATABASE_URL=postgres://granite:password@localhost:5432/granite_db
export PG_REPLICA_URL=postgres://granite:password@localhost:5432/granite__replica_db
export MYSQL_DATABASE_URL=mysql://granite:password@localhost:3306/granite_db
export MYSQL_REPLICA_URL=mysql://granite:password@localhost:3306/granite_replica_db
export SQLITE_DATABASE_URL=sqlite3:./granite.db
export SQLITE_REPLICA_URL=sqlite3:./granite_replica.db
export PG_VERSION=15.2
export MYSQL_VERSION=5.7
export SQLITE_VERSION=3110000
export SQLITE_VERSION_YEAR=2016
export CURRENT_ADAPTER=sqlite
#!/bin/bash

if [ -f .env ]; then
while IFS= read -r line; do
export "$line"
done < .env
echo "Environment variables from .env file have been exported."
else
echo "Error: The .env file does not exist."
fi
Loading