1- import json
2- from typing import Optional
3-
41import pytest
52
63from tests_e2e .conftest import subprocess_check_output , subprocess_run
74
85
9- def _get_connections_list (snowcli , config_file ) -> list :
10- """Helper function to get connections list as parsed JSON ."""
11- output = subprocess_check_output (
6+ def _get_connections_list_output (snowcli , config_file ) -> str :
7+ """Helper function to get connections list output as string ."""
8+ return subprocess_check_output (
129 [
1310 snowcli ,
1411 "--config-file" ,
@@ -19,22 +16,17 @@ def _get_connections_list(snowcli, config_file) -> list:
1916 "json" ,
2017 ]
2118 )
22- return json .loads (output )
23-
24-
25- def _find_connection (connections : list , name : str ) -> Optional [dict ]:
26- """Helper function to find a connection by name."""
27- for conn in connections :
28- if conn ["connection_name" ] == name :
29- return conn
30- return None
3119
3220
21+ @pytest .mark .parametrize ("config_mode" , ["legacy" , "config_ng" ], indirect = True )
3322@pytest .mark .e2e
34- def test_import_of_snowsql_connections (snowcli , test_root_path , empty_config_file ):
23+ def test_import_of_snowsql_connections (
24+ snowcli , test_root_path , empty_config_file , snapshot , config_mode
25+ ):
26+ """Test connection import with both legacy and config_ng systems."""
3527 # Initially should have empty or minimal connections list
36- initial_connections = _get_connections_list (snowcli , empty_config_file )
37- initial_count = len ( initial_connections )
28+ initial_output = _get_connections_list_output (snowcli , empty_config_file )
29+ assert initial_output == snapshot
3830
3931 # Import snowsql connections
4032 result = subprocess_run (
@@ -53,46 +45,19 @@ def test_import_of_snowsql_connections(snowcli, test_root_path, empty_config_fil
5345 assert result .returncode == 0
5446
5547 # After import, should have multiple connections
56- final_connections = _get_connections_list (snowcli , empty_config_file )
57-
58- # Should have more connections than initially
59- assert len (final_connections ) > initial_count
60-
61- # Check that expected connections exist
62- connection_names = {conn ["connection_name" ] for conn in final_connections }
63- expected_names = {"snowsql1" , "snowsql2" , "snowsql3" , "example" , "default" }
64- assert expected_names .issubset (connection_names )
65-
66- # Check specific connection details
67- snowsql1 = _find_connection (final_connections , "snowsql1" )
68- assert snowsql1 is not None
69- assert snowsql1 ["parameters" ]["account" ] == "a1"
70- assert snowsql1 ["parameters" ]["user" ] == "u1"
71- assert snowsql1 ["parameters" ]["host" ] == "h1_override" # From overriding config
72- assert snowsql1 ["is_default" ] is False
73-
74- snowsql2 = _find_connection (final_connections , "snowsql2" )
75- assert snowsql2 is not None
76- assert snowsql2 ["parameters" ]["account" ] == "a2"
77- assert snowsql2 ["parameters" ]["port" ] == 1234
78- assert snowsql2 ["is_default" ] is False
79-
80- default_conn = _find_connection (final_connections , "default" )
81- assert default_conn is not None
82- assert default_conn ["parameters" ]["account" ] == "default_connection_account"
83- assert (
84- default_conn ["parameters" ]["database" ] == "default_connection_database_override"
85- ) # From overriding config
86- assert default_conn ["is_default" ] is True
48+ final_output = _get_connections_list_output (snowcli , empty_config_file )
49+ assert final_output == snapshot
8750
8851
52+ @pytest .mark .parametrize ("config_mode" , ["legacy" , "config_ng" ], indirect = True )
8953@pytest .mark .e2e
9054def test_import_prompt_for_different_default_connection_name_on_conflict (
91- snowcli , test_root_path , empty_config_file
55+ snowcli , test_root_path , empty_config_file , snapshot , config_mode
9256):
57+ """Test importing with different default connection name."""
9358 # Initially should have empty or minimal connections list
94- initial_connections = _get_connections_list (snowcli , empty_config_file )
95- initial_count = len ( initial_connections )
59+ initial_output = _get_connections_list_output (snowcli , empty_config_file )
60+ assert initial_output == snapshot
9661
9762 # Import with different default connection name
9863 result = subprocess_run (
@@ -114,36 +79,25 @@ def test_import_prompt_for_different_default_connection_name_on_conflict(
11479 assert result .returncode == 0
11580
11681 # After import, snowsql2 should be the default
117- final_connections = _get_connections_list (snowcli , empty_config_file )
118-
119- # Should have more connections than initially
120- assert len (final_connections ) > initial_count
121-
122- snowsql2 = _find_connection (final_connections , "snowsql2" )
123- assert snowsql2 is not None
124- assert snowsql2 ["is_default" ] is True
125-
126- default_conn = _find_connection (final_connections , "default" )
127- assert default_conn is not None
128- assert default_conn ["is_default" ] is False
82+ final_output = _get_connections_list_output (snowcli , empty_config_file )
83+ assert final_output == snapshot
12984
13085
86+ @pytest .mark .parametrize ("config_mode" , ["legacy" , "config_ng" ], indirect = True )
13187@pytest .mark .e2e
13288def test_import_confirm_on_conflict_with_existing_cli_connection (
13389 snowcli ,
13490 test_root_path ,
13591 example_connection_config_file ,
92+ snapshot ,
93+ config_mode ,
13694):
95+ """Test import with confirmation on conflict."""
13796 # Initially should have example and integration connections
138- initial_connections = _get_connections_list (snowcli , example_connection_config_file )
139-
140- example_conn = _find_connection (initial_connections , "example" )
141- assert example_conn is not None
142- assert example_conn ["parameters" ]["user" ] == "u1"
143- assert example_conn ["parameters" ]["authenticator" ] == "SNOWFLAKE_JWT"
144-
145- integration_conn = _find_connection (initial_connections , "integration" )
146- assert integration_conn is not None
97+ initial_output = _get_connections_list_output (
98+ snowcli , example_connection_config_file
99+ )
100+ assert initial_output == snapshot
147101
148102 # Import with confirmation (y)
149103 result = subprocess_run (
@@ -163,29 +117,25 @@ def test_import_confirm_on_conflict_with_existing_cli_connection(
163117 assert result .returncode == 0
164118
165119 # After import, example connection should be overwritten with snowsql data
166- final_connections = _get_connections_list (snowcli , example_connection_config_file )
167-
168- example_conn = _find_connection (final_connections , "example" )
169- assert example_conn is not None
170- assert example_conn ["parameters" ]["account" ] == "accountname"
171- assert example_conn ["parameters" ]["user" ] == "username"
172- # Should not have the old JWT authenticator
173- assert "authenticator" not in example_conn ["parameters" ]
120+ final_output = _get_connections_list_output (snowcli , example_connection_config_file )
121+ assert final_output == snapshot
174122
175123
124+ @pytest .mark .parametrize ("config_mode" , ["legacy" , "config_ng" ], indirect = True )
176125@pytest .mark .e2e
177126def test_import_reject_on_conflict_with_existing_cli_connection (
178127 snowcli ,
179128 test_root_path ,
180129 example_connection_config_file ,
130+ snapshot ,
131+ config_mode ,
181132):
133+ """Test import with rejection on conflict."""
182134 # Initially should have example and integration connections
183- initial_connections = _get_connections_list (snowcli , example_connection_config_file )
184-
185- example_conn = _find_connection (initial_connections , "example" )
186- assert example_conn is not None
187- original_user = example_conn ["parameters" ]["user" ]
188- original_auth = example_conn ["parameters" ]["authenticator" ]
135+ initial_output = _get_connections_list_output (
136+ snowcli , example_connection_config_file
137+ )
138+ assert initial_output == snapshot
189139
190140 # Import with rejection (n)
191141 result = subprocess_run (
@@ -205,21 +155,17 @@ def test_import_reject_on_conflict_with_existing_cli_connection(
205155 assert result .returncode == 0
206156
207157 # After import, example connection should remain unchanged
208- final_connections = _get_connections_list (snowcli , example_connection_config_file )
209-
210- example_conn = _find_connection (final_connections , "example" )
211- assert example_conn is not None
212- assert example_conn ["parameters" ]["user" ] == original_user
213- assert example_conn ["parameters" ]["authenticator" ] == original_auth
214-
215158 # But other connections should still be imported
216- snowsql1 = _find_connection (final_connections , "snowsql1" )
217- assert snowsql1 is not None
218- assert snowsql1 ["parameters" ]["account" ] == "a1"
159+ final_output = _get_connections_list_output (snowcli , example_connection_config_file )
160+ assert final_output == snapshot
219161
220162
163+ @pytest .mark .parametrize ("config_mode" , ["legacy" , "config_ng" ], indirect = True )
221164@pytest .mark .e2e
222- def test_connection_imported_from_snowsql (snowcli , test_root_path , empty_config_file ):
165+ def test_connection_imported_from_snowsql (
166+ snowcli , test_root_path , empty_config_file , config_mode
167+ ):
168+ """Test that imported connection works."""
223169 result = subprocess_run (
224170 [
225171 snowcli ,
0 commit comments