Repository: astronomer/astro-sdk

Issue:
All connections tested even though one's been specified
**Describe the bug**
I ran `astro flow validate --connection=<connection_id>` and all connections were tested even though I passed one conn id specifically. 

**Version**
* Astro Runtime: 7.0.0
* Astro CLI: 1.8.3

**To Reproduce**
Steps to reproduce the behavior:
1. Update file `config/default/configuration.yml` as shown below:
```
connections:
  - conn_id: sqlite_conn
    conn_type: sqlite
    host: /Users/magdagultekin/magda-dev/data/imdb.db
    login: null
    password: null
    schema: null
  - conn_id: sqlite_default
    conn_type: sqlite
    host: /tmp/sqlite.db
    login: null
    password: null
    schema: null
```
4. Run `astro flow validate --connection=sqlite_default`
5. See message:
```
Validating connection(s) for environment 'default'
Validating connection sqlite_conn               PASSED
Validating connection sqlite_default            FAILED
```

**Expected behavior**
Only `sqlite_default` should be tested.

**Screenshots**
![image](https://user-images.githubusercontent.com/97064715/205905971-7c71dc2d-36c8-44ac-9857-9e98180c5ef4.png)




Discussion:

Resolving patch:
diff --git a/sql-cli/sql_cli/connections.py b/sql-cli/sql_cli/connections.py
--- a/sql-cli/sql_cli/connections.py
+++ b/sql-cli/sql_cli/connections.py
@@ -15,14 +15,17 @@ def validate_connections(connections: list[Connection], connection_id: str | Non
     Validates that the given connections are valid and registers them to Airflow with replace policy for existing
     connections.
     """
-    for connection in connections:
-        os.environ[f"AIRFLOW_CONN_{connection.conn_id.upper()}"] = connection.get_uri()
-        status = "[bold green]PASSED[/bold green]" if _is_valid(connection) else "[bold red]FAILED[/bold red]"
-        rprint(f"Validating connection {connection.conn_id:{CONNECTION_ID_OUTPUT_STRING_WIDTH}}", status)
-
     if connection_id and not any(connection.conn_id == connection_id for connection in connections):
         rprint("[bold red]Error: Config file does not contain given connection[/bold red]", connection_id)
 
+    for connection in connections:
+        if not connection_id or connection_id and connection.conn_id == connection_id:
+            os.environ[f"AIRFLOW_CONN_{connection.conn_id.upper()}"] = connection.get_uri()
+            status = (
+                "[bold green]PASSED[/bold green]" if _is_valid(connection) else "[bold red]FAILED[/bold red]"
+            )
+            rprint(f"Validating connection {connection.conn_id:{CONNECTION_ID_OUTPUT_STRING_WIDTH}}", status)
+
 
 def _is_valid(connection: Connection) -> bool:
     # Sqlite automatically creates the file if it does not exist,


Test patch:
diff --git a/sql-cli/tests/test_connections.py b/sql-cli/tests/test_connections.py
--- a/sql-cli/tests/test_connections.py
+++ b/sql-cli/tests/test_connections.py
@@ -1,9 +1,16 @@
 import os
 from unittest.mock import patch
 
+from airflow.models import Connection
+
 from sql_cli.connections import CONNECTION_ID_OUTPUT_STRING_WIDTH, validate_connections
 from tests.utils import get_connection_by_id
 
+two_valid_connections = [
+    Connection(conn_id="sqlite_conn1", conn_type="sqlite", host="data/imdb.db"),
+    Connection(conn_id="sqlite_conn2", conn_type="sqlite", host="data/imdb.db"),
+]
+
 
 @patch("sql_cli.connections.Path.is_file", return_value=True)
 @patch("sql_cli.connections.Connection.test_connection", return_value=(True, ""))
@@ -41,3 +48,35 @@ def test_validate_connections_config_file_does_not_contain_connection(
     captured = capsys.readouterr()
     assert f"Config file does not contain given connection {unknown_connection_id}" in captured.out
     assert f"AIRFLOW_CONN_{unknown_connection_id.upper()}" not in os.environ
+
+
+@patch("sql_cli.connections.Path.is_file", return_value=True)
+@patch("sql_cli.connections.Connection.test_connection", return_value=(True, ""))
+@patch.dict(os.environ, {}, clear=True)
+def test_validate_two_connections_validates_both(
+    mock_test_connection,
+    mock_is_file,
+    initialised_project,
+    capsys,
+):
+    validate_connections(connections=two_valid_connections)
+    captured = capsys.readouterr()
+    assert captured.out.count("PASSED") == 2
+    assert "AIRFLOW_CONN_SQLITE_CONN1" in os.environ
+    assert "AIRFLOW_CONN_SQLITE_CONN2" in os.environ
+
+
+@patch("sql_cli.connections.Path.is_file", return_value=True)
+@patch("sql_cli.connections.Connection.test_connection", return_value=(True, ""))
+@patch.dict(os.environ, {}, clear=True)
+def test_validate_two_connections_validates_specified_one(
+    mock_test_connection,
+    mock_is_file,
+    initialised_project,
+    capsys,
+):
+    validate_connections(connections=two_valid_connections, connection_id="sqlite_conn1")
+    captured = capsys.readouterr()
+    assert captured.out.count("PASSED") == 1
+    assert "AIRFLOW_CONN_SQLITE_CONN1" in os.environ
+    assert "AIRFLOW_CONN_SQLITE_CONN2" not in os.environ