|
5 | 5 | import os |
6 | 6 | import subprocess |
7 | 7 | from pathlib import Path |
| 8 | +from unittest.mock import Mock |
8 | 9 |
|
9 | 10 | import pytest |
10 | 11 |
|
|
17 | 18 | here = Path(__file__).resolve().parent |
18 | 19 |
|
19 | 20 |
|
| 21 | +def test_push_quiet_output_does_not_write_stdout(tmp_path, monkeypatch, capsys): |
| 22 | + client = oras.provider.Registry(hostname="registry.example", insecure=True) |
| 23 | + artifact = tmp_path / "artifact.txt" |
| 24 | + artifact.write_text("content") |
| 25 | + |
| 26 | + class Response: |
| 27 | + status_code = 201 |
| 28 | + |
| 29 | + container = client.get_container("registry.example/repository:tag") |
| 30 | + monkeypatch.setattr(client, "get_container", lambda target: container) |
| 31 | + monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None) |
| 32 | + monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response()) |
| 33 | + monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response()) |
| 34 | + monkeypatch.setattr(client, "_check_200_response", lambda response: None) |
| 35 | + info = Mock() |
| 36 | + monkeypatch.setattr(oras.provider.logger, "info", info) |
| 37 | + |
| 38 | + client.push( |
| 39 | + files=[artifact], |
| 40 | + target="registry.example/repository:tag", |
| 41 | + disable_path_validation=True, |
| 42 | + quiet=False, |
| 43 | + ) |
| 44 | + |
| 45 | + assert capsys.readouterr().out == "" |
| 46 | + info.assert_called_once_with(f"Successfully pushed {container}") |
| 47 | + |
| 48 | + |
| 49 | +def test_push_quiet_suppresses_completion_message(tmp_path, monkeypatch): |
| 50 | + client = oras.provider.Registry(hostname="registry.example", insecure=True) |
| 51 | + artifact = tmp_path / "artifact.txt" |
| 52 | + artifact.write_text("content") |
| 53 | + |
| 54 | + class Response: |
| 55 | + status_code = 201 |
| 56 | + |
| 57 | + container = client.get_container("registry.example/repository:tag") |
| 58 | + monkeypatch.setattr(client, "get_container", lambda target: container) |
| 59 | + monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None) |
| 60 | + monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response()) |
| 61 | + monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response()) |
| 62 | + monkeypatch.setattr(client, "_check_200_response", lambda response: None) |
| 63 | + info = Mock() |
| 64 | + monkeypatch.setattr(oras.provider.logger, "info", info) |
| 65 | + |
| 66 | + client.push( |
| 67 | + files=[artifact], |
| 68 | + target="registry.example/repository:tag", |
| 69 | + disable_path_validation=True, |
| 70 | + quiet=True, |
| 71 | + ) |
| 72 | + |
| 73 | + info.assert_not_called() |
| 74 | + |
| 75 | + |
20 | 76 | @pytest.mark.with_auth(False) |
21 | 77 | def test_annotated_registry_push(tmp_path, registry, credentials, target): |
22 | 78 | """ |
|
0 commit comments