|
| 1 | +from linodecli.exit_codes import ExitCodes |
| 2 | +from tests.integration.helpers import ( |
| 3 | + BASE_CMDS, |
| 4 | + assert_headers_in_lines, |
| 5 | + assert_help_actions_list, |
| 6 | + exec_failing_test_command, |
| 7 | + exec_test_command, |
| 8 | + get_random_text, |
| 9 | +) |
| 10 | +from tests.integration.streams.fixtures import ( |
| 11 | + create_destination_akamai_object_storage_type, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +def test_help_streams(): |
| 16 | + output = exec_test_command( |
| 17 | + BASE_CMDS["streams"] + ["--help", "--text", "--delimiter=,"] |
| 18 | + ) |
| 19 | + actions = [ |
| 20 | + "create", |
| 21 | + "delete", |
| 22 | + "destination-create", |
| 23 | + "destination-delete", |
| 24 | + "destination-history-view", |
| 25 | + "destination-update", |
| 26 | + "destination-view", |
| 27 | + "destinations-list", |
| 28 | + "history-view", |
| 29 | + "ls, list", |
| 30 | + "update", |
| 31 | + "view", |
| 32 | + ] |
| 33 | + assert_help_actions_list(actions, output) |
| 34 | + |
| 35 | + |
| 36 | +def test_list_destinations(create_destination_akamai_object_storage_type): |
| 37 | + result = exec_test_command( |
| 38 | + BASE_CMDS["streams"] + ["destinations-list", "--delimiter", ",", "--text"] |
| 39 | + ) |
| 40 | + lines = result.splitlines() |
| 41 | + headers = [ |
| 42 | + "created", |
| 43 | + "created_by", |
| 44 | + "details", |
| 45 | + "id", |
| 46 | + "label", |
| 47 | + "status", |
| 48 | + "type", |
| 49 | + "updated", |
| 50 | + "updated_by", |
| 51 | + "version", |
| 52 | + ] |
| 53 | + assert_headers_in_lines(headers, lines) |
| 54 | + |
| 55 | + |
| 56 | +def test_create_destination_error(): |
| 57 | + result = exec_failing_test_command( |
| 58 | + BASE_CMDS["streams"] |
| 59 | + + [ |
| 60 | + "destination-create", |
| 61 | + "--label", |
| 62 | + "test", |
| 63 | + "--type", |
| 64 | + "custom_https", |
| 65 | + "--details", |
| 66 | + "test", |
| 67 | + "--delimiter", |
| 68 | + ",", |
| 69 | + "--text", |
| 70 | + ], |
| 71 | + expected_code=ExitCodes.REQUEST_FAILED, |
| 72 | + ) |
| 73 | + assert "Request failed: 400" in result |
| 74 | + assert "details,Must be of type Object" in result |
| 75 | + |
| 76 | + |
| 77 | +def test_create_view_update_remove_destination(): |
| 78 | + label = get_random_text(8) + "_destination_cli_test" |
| 79 | + result_create_stream = exec_test_command( |
| 80 | + BASE_CMDS["streams"] |
| 81 | + + [ |
| 82 | + "destination-create", |
| 83 | + "--details", |
| 84 | + "--label", |
| 85 | + label, |
| 86 | + "--type", |
| 87 | + "--delimiter", |
| 88 | + ",", |
| 89 | + "--text", |
| 90 | + ] |
| 91 | + ).splitlines() |
| 92 | + headers = [ |
| 93 | + "created", |
| 94 | + "created_by", |
| 95 | + "details", |
| 96 | + "id", |
| 97 | + "label", |
| 98 | + "status", |
| 99 | + "type", |
| 100 | + "updated", |
| 101 | + "updated_by", |
| 102 | + "version", |
| 103 | + ] |
| 104 | + assert_headers_in_lines(headers, result_create_stream) |
| 105 | + assert label in result_create_stream[1] |
| 106 | + |
| 107 | + result_view = exec_test_command( |
| 108 | + BASE_CMDS["streams"] |
| 109 | + + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] |
| 110 | + ).splitlines() |
| 111 | + assert_headers_in_lines(headers, result_view) |
| 112 | + assert label in result_view[1] |
| 113 | + |
| 114 | + result_update_stream = exec_test_command( |
| 115 | + BASE_CMDS["streams"] |
| 116 | + + [ |
| 117 | + "destination-update", |
| 118 | + result_create_stream[0], |
| 119 | + "--delimiter", |
| 120 | + ",", |
| 121 | + "--text", |
| 122 | + ] |
| 123 | + ).splitlines() |
| 124 | + assert_headers_in_lines(headers, result_update_stream) |
| 125 | + |
| 126 | + exec_test_command( |
| 127 | + BASE_CMDS["streams"] |
| 128 | + + [ |
| 129 | + "destination-delete", |
| 130 | + result_create_stream[0], |
| 131 | + "--delimiter", |
| 132 | + ",", |
| 133 | + "--text", |
| 134 | + ] |
| 135 | + ).splitlines() |
| 136 | + |
| 137 | + exec_test_command( |
| 138 | + BASE_CMDS["streams"] |
| 139 | + + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] |
| 140 | + ) |
| 141 | + |
| 142 | + |
| 143 | +def test_list_streams(): |
| 144 | + result = exec_test_command( |
| 145 | + BASE_CMDS["streams"] + ["list", "--delimiter", ",", "--text"] |
| 146 | + ) |
| 147 | + lines = result.splitlines() |
| 148 | + headers = [ |
| 149 | + "created", |
| 150 | + "created_by", |
| 151 | + "destinations.details.access_key_id", |
| 152 | + "destinations.details.bucket_name", |
| 153 | + "destinations.details.host", |
| 154 | + "destinations.details.path", |
| 155 | + "details.cluster_ids", |
| 156 | + "details.is_auto_add_all_clusters_enabled", |
| 157 | + "id", |
| 158 | + "label", |
| 159 | + "status", |
| 160 | + "type", |
| 161 | + "updated", |
| 162 | + "updated_by", |
| 163 | + "version", |
| 164 | + ] |
| 165 | + assert_headers_in_lines(headers, lines) |
| 166 | + |
| 167 | + |
| 168 | +def test_create_stream_invalid_destination_error(): |
| 169 | + result = exec_failing_test_command( |
| 170 | + BASE_CMDS["streams"] |
| 171 | + + [ |
| 172 | + "create", |
| 173 | + "--label", |
| 174 | + "test", |
| 175 | + "--type", |
| 176 | + "audit_logs", |
| 177 | + "--destinations", |
| 178 | + "12341234", |
| 179 | + "--delimiter", |
| 180 | + ",", |
| 181 | + "--text", |
| 182 | + ], |
| 183 | + expected_code=ExitCodes.REQUEST_FAILED, |
| 184 | + ) |
| 185 | + assert "Request failed: 400" in result |
| 186 | + assert "Destination not found" in result |
0 commit comments