Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ key features:

```yaml
steps:
- uses: ikalnytskyi/action-setup-postgres@v2
- uses: ikalnytskyi/action-setup-postgres@v3
```

#### Advanced

```yaml
steps:
- uses: ikalnytskyi/action-setup-postgres@v2
- uses: ikalnytskyi/action-setup-postgres@v3
with:
username: ci
password: sw0rdfish
database: test
port: "34837"
port: 34837
id: postgres

- run: pytest -vv tests/
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ runs:
- name: Setup and start PostgreSQL
run: |
export PGDATA="$RUNNER_TEMP/pgdata"
pg_ctl init
pg_ctl init --options="--encoding=UTF-8 --locale=en_US.UTF-8"

# Forbid creating unix sockets since they are created by default in the
# directory we don't have permissions to.
Expand Down
28 changes: 28 additions & 0 deletions test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def test_connection_uri():
assert connection_uri == expected_connection_uri


def test_server_encoding(connection: psycopg.Connection):
"""Test that PostgreSQL's encoding is 'UTF-8'."""

assert connection.execute("SHOW SERVER_ENCODING").fetchone()[0] == "UTF8"


def test_locale(connection: psycopg.Connection):
"""Test that PostgreSQL's locale is 'en_US.UTF-8'."""

assert connection.execute("SHOW LC_COLLATE").fetchone()[0] == "en_US.UTF-8"
assert connection.execute("SHOW LC_CTYPE").fetchone()[0] == "en_US.UTF-8"


def test_user_permissions(connection: psycopg.Connection):
"""Test that a user can create databases but is not a superuser."""

Expand Down Expand Up @@ -53,6 +66,21 @@ def test_user_create_insert_select(connection: psycopg.Connection):
assert records == [(1, "42")]


def test_user_create_insert_non_ascii(connection: psycopg.Connection):
"""Test that non-ASCII characters can be stored and fetched."""

table_name = "test_setup_postgres"

with connection, connection.transaction(force_rollback=True):
records = connection \
.execute(f"CREATE TABLE {table_name}(eggs INTEGER, rice VARCHAR)") \
.execute(f"INSERT INTO {table_name}(eggs, rice) VALUES (1, 'Україна')") \
.execute(f"INSERT INTO {table_name}(eggs, rice) VALUES (2, 'ウクライナ')") \
.execute(f"SELECT * FROM {table_name}") \
.fetchall()
assert records == [(1, "Україна"), (2, "ウクライナ")]


def test_user_create_drop_database(connection: psycopg.Connection):
"""Test that a user has no permissions to create databases."""

Expand Down