Skip to content

Commit 0019bde

Browse files
committed
SNOW-2306184: config refactor - e2e fix attempt
1 parent 3ffe462 commit 0019bde

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/snowflake/cli/api/config_ng/sources.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def _parse_toml_file(
254254
connections = data.get("connections", {})
255255
for conn_name, conn_data in connections.items():
256256
if isinstance(conn_data, dict):
257+
# Process parameters if they exist
257258
for param_key, param_value in conn_data.items():
258259
full_key = f"connections.{conn_name}.{param_key}"
259260
if key is None or full_key == key:
@@ -264,6 +265,18 @@ def _parse_toml_file(
264265
raw_value=param_value,
265266
)
266267

268+
# For empty connections, we need to ensure they are recognized
269+
# even if they have no parameters. We add a special marker.
270+
if not conn_data: # Empty connection section
271+
marker_key = f"connections.{conn_name}._empty_connection"
272+
if key is None or marker_key == key:
273+
result[marker_key] = ConfigValue(
274+
key=marker_key,
275+
value=True,
276+
source_name=self.source_name,
277+
raw_value=True,
278+
)
279+
267280
return result
268281

269282
except Exception as e:

src/snowflake/cli/api/config_provider.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,13 @@ def _get_all_connections_dict(self) -> Dict[str, Dict[str, Any]]:
499499
conn_name, param_name = parts
500500
if conn_name not in connections:
501501
connections[conn_name] = {}
502+
503+
# Skip internal markers, but ensure connection exists
504+
if param_name == "_empty_connection":
505+
# This is just a marker for empty connections
506+
# Connection dict already created above
507+
continue
508+
502509
connections[conn_name][param_name] = value
503510

504511
return connections

tests/test_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def test_fails_if_existing_connection(runner):
293293

294294

295295
@mock.patch("snowflake.cli._plugins.connection.commands.get_default_connection_name")
296+
@mock.patch.dict(os.environ, {}, clear=True)
296297
def test_lists_connection_information(mock_get_default_conn_name, runner):
297298
mock_get_default_conn_name.return_value = "empty"
298299
result = runner.invoke(["connection", "list", "--format", "json"])

tests_e2e/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import shutil
1617
import subprocess
1718
import sys
@@ -111,6 +112,18 @@ def isolate_default_config_location(monkeypatch, temporary_directory):
111112
monkeypatch.setenv("SNOWFLAKE_HOME", temporary_directory)
112113

113114

115+
@pytest.fixture(autouse=True)
116+
def isolate_environment_variables(monkeypatch):
117+
"""
118+
Clear Snowflake-specific environment variables that could interfere with e2e tests.
119+
This ensures tests run in a clean environment and only use the config files they specify.
120+
"""
121+
# Clear all SNOWFLAKE_CONNECTIONS_* environment variables
122+
for env_var in list(os.environ.keys()):
123+
if env_var.startswith(("SNOWFLAKE_CONNECTIONS_", "SNOWSQL_")):
124+
monkeypatch.delenv(env_var, raising=False)
125+
126+
114127
def _create_venv(tmp_dir: Path) -> None:
115128
subprocess_check_output(["python", "-m", "venv", tmp_dir])
116129

0 commit comments

Comments
 (0)