|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | from wasi_test_runner.test_case import ( |
8 | | - Config, Failure, Result, Run, Wait, Read, Connect, Send, Recv, ProtocolType |
| 8 | + Config, Failure, Result, Run, Wait, Read, Connect, Send, Recv, ProtocolType, WasiProposal |
9 | 9 | ) |
10 | 10 |
|
11 | 11 |
|
@@ -69,13 +69,13 @@ def test_test_config_should_fail_when_mixing_config_styles(_mock_file: Mock) -> |
69 | 69 |
|
70 | 70 |
|
71 | 71 | def test_test_results_should_mark_failed_if_multiple_failures() -> None: |
72 | | - results = Result([], True, [Failure("type", "message")]) |
| 72 | + results = Result(True, [Failure("type", "message")]) |
73 | 73 |
|
74 | 74 | assert results.failed is True |
75 | 75 |
|
76 | 76 |
|
77 | 77 | def test_test_results_should_not_mark_failed_if_no_failure() -> None: |
78 | | - results = Result([], True, []) |
| 78 | + results = Result(True, []) |
79 | 79 |
|
80 | 80 | assert results.failed is False |
81 | 81 |
|
@@ -179,3 +179,45 @@ def test_recv_from_config_with_default_payload() -> None: |
179 | 179 |
|
180 | 180 | assert recv.id == "conn1" |
181 | 181 | assert recv.payload == "" |
| 182 | + |
| 183 | + |
| 184 | +@patch("builtins.open", new_callable=mock_open, read_data="{}") |
| 185 | +def test_legacy_config_should_have_http_proposal_by_default(_mock_file: Mock) -> None: |
| 186 | + config = Config.from_file("file") |
| 187 | + |
| 188 | + assert len(config.proposals) == 1 |
| 189 | + assert config.proposals[0] == WasiProposal.HTTP |
| 190 | + |
| 191 | + |
| 192 | +@patch( |
| 193 | + "builtins.open", |
| 194 | + new_callable=mock_open, |
| 195 | + read_data='{"operations": [{"type": "run"}, {"type": "wait"}], "proposals": []}', |
| 196 | +) |
| 197 | +def test_new_config_with_empty_proposals(_mock_file: Mock) -> None: |
| 198 | + config = Config.from_file("file") |
| 199 | + |
| 200 | + assert len(config.proposals) == 0 |
| 201 | + |
| 202 | + |
| 203 | +@patch( |
| 204 | + "builtins.open", |
| 205 | + new_callable=mock_open, |
| 206 | + read_data='{"operations": [{"type": "run"}], "proposals": ["http", "sockets"]}', |
| 207 | +) |
| 208 | +def test_new_config_with_multiple_proposals(_mock_file: Mock) -> None: |
| 209 | + config = Config.from_file("file") |
| 210 | + |
| 211 | + assert len(config.proposals) == 2 |
| 212 | + assert config.proposals[0] == WasiProposal.HTTP |
| 213 | + assert config.proposals[1] == WasiProposal.SOCKETS |
| 214 | + |
| 215 | + |
| 216 | +@patch( |
| 217 | + "builtins.open", |
| 218 | + new_callable=mock_open, |
| 219 | + read_data='{"operations": [{"type": "run"}], "proposals": ["invalid"]}', |
| 220 | +) |
| 221 | +def test_new_config_should_fail_with_invalid_proposal(_mock_file: Mock) -> None: |
| 222 | + with pytest.raises(ValueError): |
| 223 | + Config.from_file("file") |
0 commit comments