|
1 | 1 | import os
|
2 | 2 | import sys
|
3 | 3 |
|
4 |
| -from localstack.cli.profiles import set_profile_from_sys_argv |
| 4 | +from localstack.cli.profiles import set_and_remove_profile_from_sys_argv |
5 | 5 |
|
6 | 6 |
|
7 |
| -def test_profiles_equals_notation(monkeypatch): |
8 |
| - monkeypatch.setattr(sys, "argv", ["--profile=non-existing-test-profile"]) |
| 7 | +def profile_test(monkeypatch, input_args, expected_profile, expected_argv): |
| 8 | + monkeypatch.setattr(sys, "argv", input_args) |
9 | 9 | monkeypatch.setenv("CONFIG_PROFILE", "")
|
10 |
| - set_profile_from_sys_argv() |
11 |
| - assert os.environ["CONFIG_PROFILE"] == "non-existing-test-profile" |
| 10 | + set_and_remove_profile_from_sys_argv() |
| 11 | + assert os.environ["CONFIG_PROFILE"] == expected_profile |
| 12 | + assert sys.argv == expected_argv |
| 13 | + |
| 14 | + |
| 15 | +def test_profiles_equals_notation(monkeypatch): |
| 16 | + profile_test( |
| 17 | + monkeypatch, |
| 18 | + input_args=["--profile=non-existing-test-profile"], |
| 19 | + expected_profile="non-existing-test-profile", |
| 20 | + expected_argv=[], |
| 21 | + ) |
12 | 22 |
|
13 | 23 |
|
14 | 24 | def test_profiles_separate_args_notation(monkeypatch):
|
15 |
| - monkeypatch.setattr(sys, "argv", ["--profile", "non-existing-test-profile"]) |
16 |
| - monkeypatch.setenv("CONFIG_PROFILE", "") |
17 |
| - set_profile_from_sys_argv() |
18 |
| - assert os.environ["CONFIG_PROFILE"] == "non-existing-test-profile" |
| 25 | + profile_test( |
| 26 | + monkeypatch, |
| 27 | + input_args=["--profile", "non-existing-test-profile"], |
| 28 | + expected_profile="non-existing-test-profile", |
| 29 | + expected_argv=[], |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +def test_p_equals_notation(monkeypatch): |
| 34 | + profile_test( |
| 35 | + monkeypatch, |
| 36 | + input_args=["-p=non-existing-test-profile"], |
| 37 | + expected_profile="non-existing-test-profile", |
| 38 | + expected_argv=["-p=non-existing-test-profile"], |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +def test_p_separate_args_notation(monkeypatch): |
| 43 | + profile_test( |
| 44 | + monkeypatch, |
| 45 | + input_args=["-p", "non-existing-test-profile"], |
| 46 | + expected_profile="non-existing-test-profile", |
| 47 | + expected_argv=["-p", "non-existing-test-profile"], |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def test_profiles_args_before_and_after(monkeypatch): |
| 52 | + profile_test( |
| 53 | + monkeypatch, |
| 54 | + input_args=["cli", "-D", "--profile=non-existing-test-profile", "start"], |
| 55 | + expected_profile="non-existing-test-profile", |
| 56 | + expected_argv=["cli", "-D", "start"], |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +def test_profiles_args_before_and_after_separate(monkeypatch): |
| 61 | + profile_test( |
| 62 | + monkeypatch, |
| 63 | + input_args=["cli", "-D", "--profile", "non-existing-test-profile", "start"], |
| 64 | + expected_profile="non-existing-test-profile", |
| 65 | + expected_argv=["cli", "-D", "start"], |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def test_p_args_before_and_after_separate(monkeypatch): |
| 70 | + profile_test( |
| 71 | + monkeypatch, |
| 72 | + input_args=["cli", "-D", "-p", "non-existing-test-profile", "start"], |
| 73 | + expected_profile="non-existing-test-profile", |
| 74 | + expected_argv=["cli", "-D", "-p", "non-existing-test-profile", "start"], |
| 75 | + ) |
| 76 | + |
| 77 | + |
| 78 | +def test_profiles_args_multiple(monkeypatch): |
| 79 | + profile_test( |
| 80 | + monkeypatch, |
| 81 | + input_args=[ |
| 82 | + "cli", |
| 83 | + "--profile", |
| 84 | + "non-existing-test-profile", |
| 85 | + "start", |
| 86 | + "--profile", |
| 87 | + "another-profile", |
| 88 | + ], |
| 89 | + expected_profile="another-profile", |
| 90 | + expected_argv=["cli", "start"], |
| 91 | + ) |
| 92 | + |
| 93 | + |
| 94 | +def test_p_args_multiple(monkeypatch): |
| 95 | + profile_test( |
| 96 | + monkeypatch, |
| 97 | + input_args=[ |
| 98 | + "cli", |
| 99 | + "-p", |
| 100 | + "non-existing-test-profile", |
| 101 | + "start", |
| 102 | + "-p", |
| 103 | + "another-profile", |
| 104 | + ], |
| 105 | + expected_profile="non-existing-test-profile", |
| 106 | + expected_argv=[ |
| 107 | + "cli", |
| 108 | + "-p", |
| 109 | + "non-existing-test-profile", |
| 110 | + "start", |
| 111 | + "-p", |
| 112 | + "another-profile", |
| 113 | + ], |
| 114 | + ) |
| 115 | + |
| 116 | + |
| 117 | +def test_p_and_profile_args(monkeypatch): |
| 118 | + profile_test( |
| 119 | + monkeypatch, |
| 120 | + input_args=[ |
| 121 | + "cli", |
| 122 | + "-p", |
| 123 | + "non-existing-test-profile", |
| 124 | + "start", |
| 125 | + "--profile", |
| 126 | + "the_profile", |
| 127 | + "-p", |
| 128 | + "another-profile", |
| 129 | + ], |
| 130 | + expected_profile="the_profile", |
| 131 | + expected_argv=[ |
| 132 | + "cli", |
| 133 | + "-p", |
| 134 | + "non-existing-test-profile", |
| 135 | + "start", |
| 136 | + "-p", |
| 137 | + "another-profile", |
| 138 | + ], |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +def test_trailing_p_argument(monkeypatch): |
| 143 | + profile_test( |
| 144 | + monkeypatch, |
| 145 | + input_args=["cli", "start", "-p"], |
| 146 | + expected_profile="", |
| 147 | + expected_argv=["cli", "start", "-p"], |
| 148 | + ) |
0 commit comments