|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2024 Red Hat, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +import json |
| 18 | +import pytest |
| 19 | + |
| 20 | + |
| 21 | +def test_download_pull_secret(tmp_path, runner, rhel10_topic): |
| 22 | + pull_secret = rhel10_topic["data"]["pull_secret"] |
| 23 | + destination_file = tmp_path / "auth.json" |
| 24 | + destination_file_path = str(destination_file) |
| 25 | + runner.invoke_raw( |
| 26 | + [ |
| 27 | + "download-pull-secret", |
| 28 | + "--topic", |
| 29 | + rhel10_topic["name"], |
| 30 | + "--destination", |
| 31 | + destination_file_path, |
| 32 | + ] |
| 33 | + ) |
| 34 | + with open(destination_file_path) as f: |
| 35 | + assert f.read() == json.dumps(pull_secret) |
| 36 | + |
| 37 | + |
| 38 | +def test_download_pull_secret_without_a_pull_secret_in_topic_data(runner, topic): |
| 39 | + with pytest.raises(SystemExit): |
| 40 | + runner.invoke_raw( |
| 41 | + [ |
| 42 | + "download-pull-secret", |
| 43 | + "--topic", |
| 44 | + topic, |
| 45 | + "--destination", |
| 46 | + "/tmp/auth.json", |
| 47 | + ] |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def test_download_pull_secret_without_specified_topic(runner): |
| 52 | + with pytest.raises(SystemExit): |
| 53 | + runner.invoke_raw( |
| 54 | + [ |
| 55 | + "download-pull-secret", |
| 56 | + "--topic", |
| 57 | + "unknown-topic", |
| 58 | + "--destination", |
| 59 | + "/tmp/auth.json", |
| 60 | + ] |
| 61 | + ) |
0 commit comments