diff --git a/README.md b/README.md index 5c12c1c47..8350a3855 100644 --- a/README.md +++ b/README.md @@ -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/ diff --git a/action.yml b/action.yml index f8f0076a1..dbd3ead98 100644 --- a/action.yml +++ b/action.yml @@ -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. diff --git a/test_action.py b/test_action.py index 4f468a8c3..057ba2492 100644 --- a/test_action.py +++ b/test_action.py @@ -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.""" @@ -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."""