Skip to content

Commit d9faa90

Browse files
committed
SNOW-2306184: config refactor - e2e fix attempt 4
1 parent d124bdf commit d9faa90

File tree

6 files changed

+131
-148
lines changed

6 files changed

+131
-148
lines changed

tests_e2e/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,31 @@ def example_connection_config_file(test_root_path, prepare_test_config_file):
210210
yield prepare_test_config_file(
211211
SecurePath(test_root_path) / "config" / "example_connection.toml"
212212
)
213+
214+
215+
@pytest.fixture
216+
def config_mode(request, monkeypatch):
217+
"""
218+
Fixture to switch between legacy and config_ng modes.
219+
220+
When parameterized with ["legacy", "config_ng"], this fixture sets the
221+
appropriate environment variable to enable/disable the new config system.
222+
Each parameter value creates a separate test instance with its own snapshot.
223+
224+
Usage:
225+
@pytest.mark.parametrize("config_mode", ["legacy", "config_ng"], indirect=True)
226+
def test_something(config_mode, snapshot):
227+
# Test runs twice: once with legacy, once with config_ng
228+
# Each gets its own snapshot: test_something[legacy] and test_something[config_ng]
229+
...
230+
"""
231+
mode = getattr(request, "param", "config_ng") # default to config_ng
232+
233+
if mode == "config_ng":
234+
# Enable new config system
235+
monkeypatch.setenv("SNOWFLAKE_CLI_CONFIG_V2_ENABLED", "true")
236+
else:
237+
# Ensure new config system is disabled (legacy mode)
238+
monkeypatch.delenv("SNOWFLAKE_CLI_CONFIG_V2_ENABLED", raising=False)
239+
240+
return mode

tests_e2e/test_import_snowsql_connections.py

Lines changed: 44 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import json
2-
from typing import Optional
3-
41
import pytest
52

63
from 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
9054
def 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
13288
def 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
177126
def 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,

tests_integration/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,32 @@ def enable_snowpark_glob_support_feature_flag():
308308
def global_setup(monkeypatch):
309309
width = 81 if IS_WINDOWS else 80
310310
monkeypatch.setenv("COLUMNS", str(width))
311+
312+
313+
@pytest.fixture
314+
def config_mode(request, monkeypatch):
315+
"""
316+
Fixture to switch between legacy and config_ng modes.
317+
318+
When parameterized with ["legacy", "config_ng"], this fixture sets the
319+
appropriate environment variable to enable/disable the new config system.
320+
Each parameter value creates a separate test instance with its own snapshot.
321+
322+
Usage:
323+
@pytest.mark.parametrize("config_mode", ["legacy", "config_ng"], indirect=True)
324+
@pytest.mark.integration
325+
def test_something(runner, config_mode, snapshot):
326+
# Test runs twice: once with legacy, once with config_ng
327+
# Each gets its own snapshot
328+
...
329+
"""
330+
mode = getattr(request, "param", "config_ng") # default to config_ng
331+
332+
if mode == "config_ng":
333+
# Enable new config system
334+
monkeypatch.setenv("SNOWFLAKE_CLI_CONFIG_V2_ENABLED", "true")
335+
else:
336+
# Ensure new config system is disabled (legacy mode)
337+
monkeypatch.delenv("SNOWFLAKE_CLI_CONFIG_V2_ENABLED", raising=False)
338+
339+
return mode

tests_integration/plugin/test_broken_plugin.py

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

15-
import json
16-
1715
import pytest
1816

1917

18+
@pytest.mark.parametrize("config_mode", ["legacy", "config_ng"], indirect=True)
2019
@pytest.mark.integration
21-
def test_broken_command_path_plugin(runner, test_root_path, _install_plugin, caplog):
20+
def test_broken_command_path_plugin(
21+
runner, test_root_path, _install_plugin, caplog, snapshot, config_mode
22+
):
23+
"""Test broken plugin with both legacy and config_ng systems."""
2224
config_path = (
2325
test_root_path / "config" / "plugin_tests" / "broken_plugin_config.toml"
2426
)
@@ -34,16 +36,9 @@ def test_broken_command_path_plugin(runner, test_root_path, _install_plugin, cap
3436
in caplog.messages
3537
)
3638

37-
# Parse JSON output and check for test connection existence
38-
connections = json.loads(result.output)
39-
40-
# Find the 'test' connection
41-
test_connection = next(
42-
(conn for conn in connections if conn["connection_name"] == "test"), None
43-
)
44-
assert test_connection is not None, "Expected 'test' connection not found in output"
45-
assert test_connection["parameters"] == {"account": "test"}
46-
assert test_connection["is_default"] is False
39+
# Use snapshot to capture the output
40+
# Each config_mode gets its own snapshot automatically
41+
assert result.output == snapshot
4742

4843

4944
@pytest.fixture(scope="module")

tests_integration/plugin/test_failing_plugin.py

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

15-
import json
16-
1715
import pytest
1816

1917

18+
@pytest.mark.parametrize("config_mode", ["legacy", "config_ng"], indirect=True)
2019
@pytest.mark.integration
21-
def test_failing_plugin(runner, test_root_path, _install_plugin, caplog):
20+
def test_failing_plugin(
21+
runner, test_root_path, _install_plugin, caplog, snapshot, config_mode
22+
):
23+
"""Test failing plugin with both legacy and config_ng systems."""
2224
config_path = (
2325
test_root_path / "config" / "plugin_tests" / "failing_plugin_config.toml"
2426
)
@@ -32,16 +34,9 @@ def test_failing_plugin(runner, test_root_path, _install_plugin, caplog):
3234
in caplog.messages
3335
)
3436

35-
# Parse JSON output and check for test connection existence
36-
connections = json.loads(result.output)
37-
38-
# Find the 'test' connection
39-
test_connection = next(
40-
(conn for conn in connections if conn["connection_name"] == "test"), None
41-
)
42-
assert test_connection is not None, "Expected 'test' connection not found in output"
43-
assert test_connection["parameters"] == {"account": "test"}
44-
assert test_connection["is_default"] is False
37+
# Use snapshot to capture the output
38+
# Each config_mode gets its own snapshot automatically
39+
assert result.output == snapshot
4540

4641

4742
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)