Skip to content

Commit abfed86

Browse files
committed
adding tests
1 parent 25117d9 commit abfed86

6 files changed

Lines changed: 225 additions & 4 deletions

File tree

src/globus_cli/commands/streams/environment/_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def dumps(self) -> str:
113113
return out
114114

115115

116+
# This class is needed to manage the login requirements for the
117+
# `globus streams environment` commands. These operate differently
118+
# than the other globus commands in that we know they will need to
119+
# log into both GCS and Transfer only, and we know they will be
120+
# running these in an application environment for establishing
121+
# connections through a tunnel
116122
class LoginMgr:
117123
def __init__(self, endpoint_id: uuid.UUID | None = None) -> None:
118124
self.login_manager = globus_lm.LoginManager()
@@ -147,6 +153,7 @@ def __init__(
147153
self.contact_string = None
148154
self.transfer_client = transfer_client
149155
self.tunnel_doc = self.transfer_client.get_tunnel(tunnel_id)
156+
pass
150157

151158
def update_listener(self, cs: str) -> None:
152159
host, _, port = cs.rpartition(":")

src/globus_cli/commands/streams/environment/contact_lookup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ def contact_lookup(
4848
)
4949

5050
tm_now = int(time.time())
51-
if (
51+
52+
if not skip_update and (
5253
conf_obj.connector_contact_string is None
53-
or tm_now > conf_obj.update_time + conf_obj.connector_contact_string_ttl
54-
) and not skip_update:
54+
or (
55+
conf_obj.update_time is not None
56+
and conf_obj.connector_contact_string_ttl is not None
57+
and tm_now > conf_obj.update_time + conf_obj.connector_contact_string_ttl
58+
)
59+
):
5560
login_mgr = gt_utils.LoginMgr()
5661
xfer_client = login_mgr.get_transfer_client()
5762
xfer_mgr = gt_utils.TransferMgr(tunnel_id, xfer_client)

src/globus_cli/commands/streams/environment/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ def update_command(
7272
cs = xfer_mgr.get_contact_string()
7373
if cs:
7474
conf_obj.connector_contact_string = cs
75-
if cs_ttl is not None:
75+
if cs_ttl != globus_sdk.MISSING:
7676
conf_obj.connector_contact_string_ttl = cs_ttl
7777
conf_obj.update_keyfile()
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
metadata:
2+
tunnel_id: "689dcb43-cdbe-46bb-9a59-dad71091a247"
3+
lankey_id: "13fb1936-c8dd-4c6b-9af3-394075c08424"
4+
lankey: "93333879ea95"
5+
endpoint_id: "a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9"
6+
7+
8+
gcs:
9+
- path: /api/lan_secrets
10+
method: POST
11+
json:
12+
{
13+
"DATA": [
14+
{
15+
"secret": "93333879ea95",
16+
"id": "13fb1936-c8dd-4c6b-9af3-394075c08424"
17+
}
18+
]
19+
}
20+
21+
- path: /api/lan_secrets
22+
method: DELETE
23+
24+
transfer:
25+
- path: /v0.10/endpoint/a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9
26+
method: GET
27+
json:
28+
{
29+
"DATA": [
30+
{
31+
"DATA_TYPE": "server",
32+
"hostname": "abc.xyz.data.globus.org"
33+
}
34+
],
35+
"DATA_TYPE": "endpoint",
36+
"activated": false,
37+
"canonical_name": "a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9#myserver",
38+
"contact_email": null,
39+
"contact_info": null,
40+
"default_directory": null,
41+
"description": "example gcsv5 endpoint streaming",
42+
"department": null,
43+
"display_name": "myserver",
44+
"entity_type": "GCSv5_endpoint",
45+
"force_encryption": false,
46+
"gcs_manager_url": "https://abc.xyz.data.globus.org",
47+
"gcs_version": "5.4.10",
48+
"high_assurance": false,
49+
"host_endpoint_id": null,
50+
"id": "a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9",
51+
"is_globus_connect": false,
52+
"info_link": null,
53+
"keywords": null,
54+
"local_user_info_available": false,
55+
"non_functional": true,
56+
"organization": "My Org",
57+
"owner_id": "a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9",
58+
"owner_string": "a98f60bd-98bf-47bd-9a1d-6a0a3b70eef9@clients.auth.globus.org",
59+
"public": false,
60+
"shareable": false,
61+
"subscription_id": null
62+
}
63+
64+
- path: /v2/tunnels/689dcb43-cdbe-46bb-9a59-dad71091a247
65+
method: GET
66+
json:
67+
{
68+
"data": {
69+
"attributes": {
70+
"created_time": "2025-12-08T22:00:05.239465",
71+
"initiator_ip_address": null,
72+
"initiator_port": null,
73+
"label": "Test Stream Access Point",
74+
"lifetime_mins": 360,
75+
"listener_ip_address": null,
76+
"listener_port": null,
77+
"restartable": false,
78+
"state": "AWAITING_LISTENER",
79+
"status": "The tunnel is waiting for listening contact detail setup.",
80+
"submission_id": "3fc91c9a-d481-11f0-ae61-0affc202d2e9"
81+
},
82+
"id": "689dcb43-cdbe-46bb-9a59-dad71091a247",
83+
"relationships": {
84+
"initiator": {
85+
"data": {
86+
"id": "80583f05-75f3-4825-b8a5-6c3edf0bbc5c",
87+
"type": "StreamAccessPoint"
88+
}
89+
},
90+
"listener": {
91+
"data": {
92+
"id": "dd5fa993-749f-48fb-86cf-f07ad5797d7e",
93+
"type": "StreamAccessPoint"
94+
}
95+
},
96+
"owner": {
97+
"data": {
98+
"id": "4d443580-012d-4954-816f-e0592bd356e1",
99+
"type": "Identity"
100+
}
101+
}
102+
},
103+
"type": "Tunnel"
104+
},
105+
"meta": {
106+
"request_id": "yDZD2RwPk"
107+
}
108+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import glob
2+
import os
3+
import tempfile
4+
import time
5+
import unittest.mock as mock
6+
import uuid
7+
8+
import globus_cli.login_manager
9+
from globus_sdk.testing import load_response_set
10+
11+
import globus_cli.commands.streams.environment._common as gtutils
12+
13+
_g_xfer_mgr = "gtutils.TransferMgr"
14+
_g_login_mgr = "gtutils.LoginMgr"
15+
_g_gcs_mgr = "gtutils.GCSMgr"
16+
#
17+
#
18+
# @pytest.mark.parametrize("output_format", ["json", "text"])
19+
# def test_help(run_line, output_format):
20+
# result = run_line(["globus", "streams", "environment", "--help"])
21+
# assert result.exit_code == 0
22+
23+
24+
def test_initialize_happy(run_line, add_gcs_login):
25+
meta = load_response_set("cli.streams_environment").metadata
26+
27+
lankey = meta["lankey"]
28+
lankey_id = meta["lankey_id"]
29+
tunnel_id = meta["tunnel_id"]
30+
cs = "localhost:9999"
31+
cs_ttl = 99
32+
endpoint_id = meta["endpoint_id"]
33+
34+
add_gcs_login(endpoint_id)
35+
36+
with (
37+
tempfile.TemporaryDirectory() as tmp_path,
38+
mock.patch("globus_cli.login_manager.LoginManager.is_logged_in", return_value=True),
39+
):
40+
41+
# lm.is_logged_in.return_value = True
42+
result = run_line(
43+
[
44+
"globus",
45+
"streams",
46+
"environment",
47+
"initialize",
48+
"--base-dir",
49+
tmp_path,
50+
"--cs-ttl",
51+
cs_ttl,
52+
str(tunnel_id),
53+
endpoint_id,
54+
],
55+
)
56+
assert result.exit_code == 0
57+
58+
conf = gtutils.TunnelConf(tunnel_id, tmp_path)
59+
assert conf.endpoint_id == endpoint_id
60+
assert conf.connector_contact_string == cs
61+
assert conf.connector_contact_string_ttl == cs_ttl
62+
assert conf.lankey == lankey
63+
assert conf.lankey_id == lankey_id
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import tempfile
3+
import uuid
4+
5+
import globus_cli.commands.streams.environment._common as gtutils
6+
7+
8+
def test_default_values_config():
9+
with tempfile.TemporaryDirectory() as tmp_path:
10+
tunnel_id = uuid.uuid4()
11+
conf = gtutils.TunnelConf(tunnel_id, tmp_path)
12+
assert not conf.file_existed
13+
14+
for f in conf.file_key_values:
15+
if f != "fake_port":
16+
assert getattr(conf, f) is None
17+
18+
19+
def test_set_values_config():
20+
lankey = "XXXXX"
21+
lankey_id = str(uuid.uuid4())
22+
with tempfile.TemporaryDirectory() as tmp_path:
23+
tunnel_id = uuid.uuid4()
24+
conf = gtutils.TunnelConf(tunnel_id, tmp_path)
25+
26+
conf.lankey = lankey
27+
conf.lankey_id = lankey_id
28+
29+
conf.update_keyfile()
30+
31+
assert os.path.exists(conf.keyfile)
32+
33+
conf2 = gtutils.TunnelConf(tunnel_id, tmp_path)
34+
35+
assert conf2.file_existed
36+
assert conf2.lankey == lankey
37+
assert conf2.lankey_id == lankey_id
38+
assert conf2.connector_contact_string is None

0 commit comments

Comments
 (0)