Skip to content

Commit

Permalink
Merge pull request #4 from ikalnytskyi/encoding
Browse files Browse the repository at this point in the history
Use encoding="UTF-8" and locale="en_US.UTF-8"
  • Loading branch information
ikalnytskyi authored Jul 2, 2022
2 parents 7e58e4b + 9e09d9b commit e5b7793
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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

0 comments on commit e5b7793

Please sign in to comment.