feluelle commented on a change in pull request #8877:
URL: https://github.com/apache/airflow/pull/8877#discussion_r425901097



##########
File path: tests/test_utils/postgres_system_helpers.py
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from contextlib import contextmanager
+from typing import List
+
+import pytest
+
+from tests.test_utils.system_tests_class import SystemTest
+from tests.utils.logging_command_executor import get_executor
+
+
+@contextmanager
+def provide_postgres_schema(name):
+    PostgresSystemTest.create_schema(name)
+    yield name
+    PostgresSystemTest.delete_schema(name)
+
+
+@contextmanager
+def provide_postgres_table(schema_name, table_name, columns=None):
+    PostgresSystemTest.create_table(schema_name, table_name, columns)
+    yield
+    PostgresSystemTest.delete_table(schema_name, table_name)
+
+
+@pytest.mark.system("postgres")
+class PostgresSystemTest(SystemTest):
+
+    @classmethod
+    def execute_with_ctx(cls, cmd: str):
+        """
+        Executes command with postgres (psql cli) context.
+        """
+        executor = get_executor()
+        from os import getenv
+        connection_string = getenv("AIRFLOW_CONN_POSTGRES_DEFAULT")
+        auth = ["psql", connection_string]
+        executor.execute_cmd(cmd=auth + ["-c", cmd])

Review comment:
       > from os import getenv
   > connection_string = getenv("AIRFLOW_CONN_POSTGRES_DEFAULT")
   
   Getting the connection through a env variable that needs to be defined :/ Is 
there a better way to do that?
   
   > auth = ["psql", connection_string]
   > executor.execute_cmd(cmd=auth + ["-c", cmd])
   
   I don't like that part. I want to authenticate the context / the `psql` 
commands - that was the only way it worked. I also tried to authenticate the 
context through [Connection Service 
File](https://www.postgresql.org/docs/9.1/libpq-pgservice.html) and [Password 
File](https://www.postgresql.org/docs/9.1/libpq-pgpass.html) and mount them via 
`forward-credentials.yml` into the container.
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to