|
| 1 | +""" |
| 2 | +Copyright 2025 Google LLC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +from xpk.core.workload import get_workload_list_gcp_link |
| 18 | + |
| 19 | +TEST_PROJECT = 'test-project' |
| 20 | +TEST_CLUSTER = 'test-cluster' |
| 21 | +TEST_ZONE = 'us-central1-c' |
| 22 | +LINK_WITHOUT_NAME_FILTER = 'https://console.cloud.google.com/kubernetes/workload/overview?project=test-project&pageState=(%22workload_list_table%22:(%22f%22:%22%255B%257B_22k_22_3A_22Cluster_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22test-cluster_5C_22_22_2C_22i_22_3A_22metadata%252FclusterReference%252Fname_22%257D_2C%257B_22k_22_3A_22Location_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22us-central1_5C_22_22_2C_22i_22_3A_22metadata%252FclusterReference%252FgcpLocation_22%257D_2C%257B_22k_22_3A_22Type_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22Job_5C_22_22_2C_22i_22_3A_22type_meta%252FkindName_22%257D%255D%22))' |
| 23 | +LINK_WITH_NAME_FILTER = 'https://console.cloud.google.com/kubernetes/workload/overview?project=test-project&pageState=(%22workload_list_table%22:(%22f%22:%22%255B%257B_22k_22_3A_22Cluster_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22test-cluster_5C_22_22_2C_22i_22_3A_22metadata%252FclusterReference%252Fname_22%257D_2C%257B_22k_22_3A_22Location_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22us-central1_5C_22_22_2C_22i_22_3A_22metadata%252FclusterReference%252FgcpLocation_22%257D_2C%257B_22k_22_3A_22Type_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22Job_5C_22_22_2C_22i_22_3A_22type_meta%252FkindName_22%257D_2C%257B_22k_22_3A_22Name_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22test-workload_5C_22_22_2C_22i_22_3A_22metadata%252Fname_22%257D%255D%22))' |
| 24 | + |
| 25 | + |
| 26 | +def test_get_workload_list_gcp_link_without_job_name_filter(): |
| 27 | + result = get_workload_list_gcp_link( |
| 28 | + project=TEST_PROJECT, |
| 29 | + cluster=TEST_CLUSTER, |
| 30 | + zone=TEST_ZONE, |
| 31 | + job_name_filter=None, |
| 32 | + ) |
| 33 | + |
| 34 | + assert result == LINK_WITHOUT_NAME_FILTER |
| 35 | + |
| 36 | + |
| 37 | +def test_get_workload_list_gcp_link_with_job_name_filter(): |
| 38 | + result = get_workload_list_gcp_link( |
| 39 | + project=TEST_PROJECT, |
| 40 | + cluster=TEST_CLUSTER, |
| 41 | + zone=TEST_ZONE, |
| 42 | + job_name_filter='test-workload', |
| 43 | + ) |
| 44 | + |
| 45 | + assert result == LINK_WITH_NAME_FILTER |
| 46 | + |
| 47 | + |
| 48 | +def test_get_workload_list_gcp_link_with_invalid_job_name_filter(): |
| 49 | + result = get_workload_list_gcp_link( |
| 50 | + project=TEST_PROJECT, |
| 51 | + cluster=TEST_CLUSTER, |
| 52 | + zone=TEST_ZONE, |
| 53 | + job_name_filter='test-workload.*', |
| 54 | + ) |
| 55 | + |
| 56 | + assert result == LINK_WITHOUT_NAME_FILTER |
0 commit comments