diff --git a/README.md b/README.md index 4ec3083..7bac009 100644 --- a/README.md +++ b/README.md @@ -501,20 +501,19 @@ on a debuggee will be installed on all running instances of it. Run the following command ``` -snapshot-dbg-cli list_debuggees +snapshot-dbg-cli list_debuggees --include-inactive ``` The output resembles the following: ``` -Name ID Description -------------- ---------- ---------------------------------------- -test-app - v1 d-24abc4f1 node index.js module:test-app version:v1 -test-app - v2 d-8dd7f149 node index.js module:test-app version:v2 +Name ID Description Last Active Status +------------- ---------- ---------------------------------------- -------------------- -------- +test-app - v2 d-8dd7f149 node index.js module:test-app version:v2 2022-12-16T21:45:07Z ACTIVE +test-app - v1 d-24abc4f1 node index.js module:test-app version:v1 2022-10-16T21:45:07Z INACTIVE ``` - ### Set Snapshots Snapshots capture local variables and the call stack at a specific line location @@ -636,12 +635,12 @@ Where: The output resembles the following: ``` -Status Location Condition CompletedTime ID ---------- ----------- ----------- --------------------------- ------------ -ACTIVE index.js:21 b-1648008775 -ACTIVE index.js:21 b-1648044994 -ACTIVE index.js:21 b-1648045010 -COMPLETED index.js:21 2022-03-23T02:52:23.558000Z b-1648003845 +Status Location Condition CompletedTime ID +--------- ----------- ----------- -------------------- ------------ +ACTIVE index.js:21 b-1648008775 +ACTIVE index.js:21 b-1648044994 +ACTIVE index.js:21 b-1648045010 +COMPLETED index.js:21 2022-03-23T02:52:23Z b-1648003845 ``` ### Get snapshot @@ -667,8 +666,8 @@ Location: index.js:30 Condition: No condition set. Expressions: No expressions set. Status: Complete -Create Time: 2022-05-13T14:14:01.444000Z -Final Time: 2022-05-13T14:14:02.516000Z +Create Time: 2022-05-13T14:14:01Z +Final Time: 2022-05-13T14:14:02Z ------------------------------------------------------------------------------- | Evaluated Expressions @@ -802,8 +801,8 @@ Log Message Format: a == 3 Location: Main.java:23 Condition: No condition set Status: EXPIRED -Create Time: 2022-08-19T18:14:38.240000Z -Final Time: 2022-08-20T18:14:39.618000Z +Create Time: 2022-08-19T18:14:38Z +Final Time: 2022-08-20T18:14:39Z User Email: foo1@bar.com ``` @@ -825,10 +824,10 @@ The output resembles the following: ``` This command will delete the following debuggees: -Name ID Last Active Status -------------------------- ---------- --------------------------- ------ -default - 20221125t224954 d-39f7082e 2022-12-05T03:13:42.166000Z STALE -default - 20221125t154414 d-dba89292 2022-12-04T03:02:48.780000Z STALE +Name ID Last Active Status +------------------------- ---------- -------------------- ------ +default - 20221125t224954 d-39f7082e 2022-12-05T03:13:42Z STALE +default - 20221125t154414 d-dba89292 2022-12-04T03:02:48Z STALE diff --git a/samples/java/appengine-flexible/helloworld-springboot/README.md b/samples/java/appengine-flexible/helloworld-springboot/README.md index 336f4f9..d3481b3 100644 --- a/samples/java/appengine-flexible/helloworld-springboot/README.md +++ b/samples/java/appengine-flexible/helloworld-springboot/README.md @@ -67,9 +67,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221125t224954`. ``` -Name ID Description --------------------------- ---------- ------------------------------------------------ -default - 20221125t224954 d-62259477 my-project-id-20221125t224954-448130606220701265 +Name ID Description Last Active Status +------------------------- ---------- ------------------------------------------------ -------------------- ------ +default - 20221125t224954 d-62259477 my-project-id-20221125t224954-448130606220701265 2022-11-25T22:50:00Z ACTIVE ``` The debuggee ID in this case is `d-62259477`. Using this ID you may now run diff --git a/samples/java/appengine-flexible/helloworld/README.md b/samples/java/appengine-flexible/helloworld/README.md index 0565d1a..f81c856 100644 --- a/samples/java/appengine-flexible/helloworld/README.md +++ b/samples/java/appengine-flexible/helloworld/README.md @@ -66,9 +66,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221125t154414`. ``` -Name ID Description --------------------------- ---------- ------------------------------------------------ -default - 20221125t154414 d-85ad2c65 my-project-id-20221125t154414-448123750866017122 +Name ID Description Last Active Status +-------------------------- --------- ------------------------------------------------ -------------------- ------ +default - 20221125t154414 d-85ad2c65 my-project-id-20221125t154414-448123750866017122 2022-11-25T15:45:00Z ACTIVE ``` The debuggee ID in this case is `d-85ad2c65`. Using this ID you may now run diff --git a/samples/java/appengine-java11/helloworld-servlet/README.md b/samples/java/appengine-java11/helloworld-servlet/README.md index 47de13d..36606b5 100644 --- a/samples/java/appengine-java11/helloworld-servlet/README.md +++ b/samples/java/appengine-java11/helloworld-servlet/README.md @@ -125,9 +125,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221122t182924`. ``` -Name ID Description -------------------------- ---------- ------------------------------------------------ -default - 20221122t182924 d-7f891f30 my-project-id-20221122t182924-448056845967981019 +Name ID Description Last Active Status +------------------------- ---------- ------------------------------------------------ -------------------- ------ +default - 20221122t182924 d-7f891f30 my-project-id-20221122t182924-448056845967981019 2022-11-22T18:30:00Z ACTIVE ``` The debuggee ID in this case is `d-7f891f30`. Using this ID you may now run diff --git a/samples/java/appengine-java11/simple-server/README.md b/samples/java/appengine-java11/simple-server/README.md index 21a1321..3f765ee 100644 --- a/samples/java/appengine-java11/simple-server/README.md +++ b/samples/java/appengine-java11/simple-server/README.md @@ -75,9 +75,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221117t213436`. ``` -Name ID Description --------------------------- ---------- ------------------------------------------------ -default - 20221122t161333 d-ad4829f7 my-project-id-20221122t161333-448054658875855015 +Name ID Description Last Active Status +------------------------- ---------- ------------------------------------------------ -------------------- ------ +default - 20221122t161333 d-ad4829f7 my-project-id-20221122t161333-448054658875855015 2022-11-22T16:14:00Z ACTIVE ``` The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run diff --git a/samples/node-js/appengine-flexible/README.md b/samples/node-js/appengine-flexible/README.md index ff21510..06ad363 100644 --- a/samples/node-js/appengine-flexible/README.md +++ b/samples/node-js/appengine-flexible/README.md @@ -57,9 +57,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221117t213436`. ``` -Name ID Description --------------------------- ---------- ------------------------------------------------ -default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 +Name ID Description Last Active Status +------------------------- ---------- ----------------------------------- -------------------- ------ +default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 2022-11-22T16:15:00Z ACTIVE ``` The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run diff --git a/samples/node-js/appengine-standard/README.md b/samples/node-js/appengine-standard/README.md index 51f1205..cd7b452 100644 --- a/samples/node-js/appengine-standard/README.md +++ b/samples/node-js/appengine-standard/README.md @@ -59,9 +59,9 @@ The output will resemble the following. The first column will contain an entry ` - `, which in this case is `default - 20221117t213436`. ``` -Name ID Description --------------------------- ---------- ------------------------------------------------ -default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 +Name ID Description Last Active Status +------------------------- ---------- ----------------------------------- -------------------- ------ +default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 2022-11-22T16:15:00Z ACTIVE ``` The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run diff --git a/snapshot_dbg_cli/debuggee_utils.py b/snapshot_dbg_cli/debuggee_utils.py index 26181f7..f8865bc 100644 --- a/snapshot_dbg_cli/debuggee_utils.py +++ b/snapshot_dbg_cli/debuggee_utils.py @@ -36,6 +36,19 @@ def set_converted_timestamps(debuggee): debuggee, field_mappings) +def get_debuggee_status(debuggee): + if not debuggee['activeDebuggeeEnabled']: + return 'UNKNOWN' + + if debuggee['isActive']: + return 'ACTIVE' + + if not debuggee['isStale']: + return 'INACTIVE' + + return 'STALE' + + def normalize_debuggee(debuggee, current_time_unix_msec): """Validates and normalizes a debuggee. diff --git a/snapshot_dbg_cli/delete_debuggees_command.py b/snapshot_dbg_cli/delete_debuggees_command.py index 9f0d715..104916a 100644 --- a/snapshot_dbg_cli/delete_debuggees_command.py +++ b/snapshot_dbg_cli/delete_debuggees_command.py @@ -18,6 +18,7 @@ """ from snapshot_dbg_cli.exceptions import SilentlyExitError +from snapshot_dbg_cli.debuggee_utils import get_debuggee_status from snapshot_dbg_cli.debuggee_utils import sort_debuggees from snapshot_dbg_cli.time_utils import get_current_time_unix_msec @@ -50,8 +51,6 @@ QUIET_HELP = 'If set, suppresses user confirmation of the command.' -SUMMARY_HEADERS = ['Name', 'ID', 'Last Active', 'Status'] - DELETE_ABORTED_QUIET_NOT_ALLOWED_MSG = """ Delete aborted. Run the command again without the --quiet option specified, it cannot be used due to the unknown status of one or more debuggees. @@ -63,6 +62,8 @@ future install the latest available version of the agent. """ +SUMMARY_HEADERS = ['Name', 'ID', 'Last Active', 'Status'] + def transform_to_debuggee_summary(debuggee): # Match the fields from SUMMARY_HEADERS @@ -74,19 +75,6 @@ def transform_to_debuggee_summary(debuggee): ] -def get_debuggee_status(debuggee): - if not debuggee['activeDebuggeeEnabled']: - return 'UNKNOWN' - - if debuggee['isActive']: - return 'ACTIVE' - - if not debuggee['isStale']: - return 'INACTIVE' - - return 'STALE' - - def should_delete_debuggee_check(debuggee, args): if args.include_all: return True diff --git a/snapshot_dbg_cli/list_debuggees_command.py b/snapshot_dbg_cli/list_debuggees_command.py index 7bcc931..09cc354 100644 --- a/snapshot_dbg_cli/list_debuggees_command.py +++ b/snapshot_dbg_cli/list_debuggees_command.py @@ -17,6 +17,7 @@ (debuggees) registered with the Snapshot Debugger. """ +from snapshot_dbg_cli.debuggee_utils import get_debuggee_status from snapshot_dbg_cli.debuggee_utils import sort_debuggees from snapshot_dbg_cli.time_utils import get_current_time_unix_msec @@ -30,6 +31,21 @@ INCLUDE_INACTIVE_HELP = 'Include inactive debuggees.' +SUMMARY_HEADERS = headers = [ + 'Name', 'ID', 'Description', 'Last Active', 'Status' +] + + +def transform_to_debuggee_summary(debuggee): + # Match the fields from SUMMARY_HEADERS + return [ + debuggee['displayName'], + debuggee['id'], + debuggee['description'], + debuggee['lastUpdateTime'], + get_debuggee_status(debuggee), + ] + class ListDebuggeesCommand: """This class implements the list_debuggees command. @@ -72,9 +88,5 @@ def cmd(self, args, cli_services): if args.format.is_a_json_value(): user_output.json_format(debuggees, pretty=args.format.is_pretty_json()) else: - headers = ['Name', 'ID', 'Description'] - - values = [[d['displayName'], d['id'], d['description']] for d in debuggees - ] - - user_output.tabular(headers, values) + values = list(map(transform_to_debuggee_summary, debuggees)) + user_output.tabular(SUMMARY_HEADERS, values) diff --git a/snapshot_dbg_cli/time_utils.py b/snapshot_dbg_cli/time_utils.py index 5f2ac9d..2f9a932 100644 --- a/snapshot_dbg_cli/time_utils.py +++ b/snapshot_dbg_cli/time_utils.py @@ -31,14 +31,13 @@ def convert_unix_msec_to_rfc3339(unix_msec): unix_msec: The Unix timestamp, represented in milliseconds since the epoch. Returns: - An RFC3339 encoded timestamp string in format: "%Y-%m-%dT%H:%M:%S.%fZ". + An RFC3339 encoded timestamp string in format: "%Y-%m-%dT%H:%M:%SZ". """ try: seconds = unix_msec / 1000 - msec = unix_msec % 1000 timestamp = seconds dt = datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc) - return dt.strftime(f'%Y-%m-%dT%H:%M:%S.{msec:03}000') + 'Z' + return dt.strftime('%Y-%m-%dT%H:%M:%S') + 'Z' except (OverflowError, OSError, TypeError, ValueError): # By using 0, we'll still get the expected formatted string, and the value # will be '1970-01-01...', which visually will be recognizable as beginning @@ -65,9 +64,9 @@ def set_converted_timestamps(data, field_mappings): set_converted_timestamps(data, field_mappings) data = { fooTimeUnixMsec: 1649962215000 - fooTime: '2022-04-14T18:50:15.000000Z' + fooTime: '2022-04-14T18:50:15Z' barTimeUnixMsec = 1649962216000 - barTime: '2022-04-14T18:50:16.000000Z' + barTime: '2022-04-14T18:50:16Z' } diff --git a/snapshot_dbg_cli_tests/test_breakpoint_utils.py b/snapshot_dbg_cli_tests/test_breakpoint_utils.py index 4eb7258..7be6c48 100644 --- a/snapshot_dbg_cli_tests/test_breakpoint_utils.py +++ b/snapshot_dbg_cli_tests/test_breakpoint_utils.py @@ -32,7 +32,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.426000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_COMPLETE = { @@ -43,8 +43,8 @@ 'isFinalState': True, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.426000Z', - 'finalTime': '2022-04-14T18:50:30.637000Z', + 'createTime': '2022-04-14T18:50:15Z', + 'finalTime': '2022-04-14T18:50:30Z', } # yapf: disable (Subjectively, more readable hand formatted) class SnapshotDebuggerBreakpointUtilsTests(unittest.TestCase): @@ -120,7 +120,7 @@ def test_set_converted_timestamps(self): }, { 'createTimeUnixMsec': 1649962215000, - 'createTime': '2022-04-14T18:50:15.000000Z' + 'createTime': '2022-04-14T18:50:15Z' }, ), ( @@ -141,7 +141,7 @@ def test_set_converted_timestamps(self): }, { 'finalTimeUnixMsec': 1649962215000, - 'finalTime': '2022-04-14T18:50:15.000000Z' + 'finalTime': '2022-04-14T18:50:15Z' }, ), ( @@ -163,9 +163,9 @@ def test_set_converted_timestamps(self): }, { 'createTimeUnixMsec': 1649962215000, - 'createTime': '2022-04-14T18:50:15.000000Z', + 'createTime': '2022-04-14T18:50:15Z', 'finalTimeUnixMsec': 1649962215001, - 'finalTime': '2022-04-14T18:50:15.001000Z' + 'finalTime': '2022-04-14T18:50:15Z' }, ), ] @@ -363,7 +363,7 @@ def test_logpoint_get_short_status_active(self): 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) self.assertEqual(get_logpoint_short_status(logpoint), 'ACTIVE') @@ -386,8 +386,8 @@ def test_logpoint_get_short_status_complete(self): 'isFinalState': True, 'location': {'line': 27, 'path': 'index.js'}, 'userEmail': 'user_b@foo.com', - 'createTime': '2022-04-14T18:50:16.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:16Z', + 'finalTime': '2022-04-14T18:50:31Z', } # yapf: disable (Subjectively, more readable hand formatted) self.assertEqual(get_logpoint_short_status(logpoint), 'COMPLETED') @@ -404,8 +404,8 @@ def test_logpoint_get_short_status_expired(self): 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user_c@foo.com', - 'createTime': '2022-04-14T18:50:17.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:17Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The logpoint has expired' @@ -430,8 +430,8 @@ def test_logpoint_get_short_status_failed(self): 'isFinalState': True, 'location': {'line': 29, 'path': 'index.js'}, 'userEmail': 'user_d@foo.com', - 'createTime': '2022-04-14T18:50:18.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:18Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'No code found at line 29' @@ -458,8 +458,8 @@ def test_logpoint_get_short_status_data_incomplete(self): 'isFinalState': True, 'location': {'line': 29, 'path': 'index.js'}, 'userEmail': 'user_d@foo.com', - 'createTime': '2022-04-14T18:50:18.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:18Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'No code found at line 29' diff --git a/snapshot_dbg_cli_tests/test_debuggee_utils.py b/snapshot_dbg_cli_tests/test_debuggee_utils.py index 56808c0..caf2ddf 100644 --- a/snapshot_dbg_cli_tests/test_debuggee_utils.py +++ b/snapshot_dbg_cli_tests/test_debuggee_utils.py @@ -17,15 +17,90 @@ import copy import unittest +from snapshot_dbg_cli.debuggee_utils import get_debuggee_status from snapshot_dbg_cli.debuggee_utils import get_display_name from snapshot_dbg_cli.debuggee_utils import normalize_debuggee from snapshot_dbg_cli.debuggee_utils import set_converted_timestamps +DEBUGGEE_ACTIVE = { + 'id': 'd-123', + 'labels': { + 'module': 'app123', + 'version': 'v1' + }, + 'description': 'desc 1', + 'displayName': 'app123 - v1', + 'activeDebuggeeEnabled': True, + 'isActive': True, + 'isStale': False, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1670000000000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:20Z', +} + +DEBUGGEE_INACTIVE = { + 'id': 'd-456', + 'labels': { + 'module': 'app456', + 'version': 'v2' + }, + 'description': 'desc 2', + 'displayName': 'app456 - v2', + 'activeDebuggeeEnabled': True, + 'isActive': False, + 'isStale': False, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1669913600000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-01T16:53:20Z', +} + +DEBUGGEE_STALE = { + 'id': 'd-789', + 'labels': { + 'module': 'app789', + 'version': 'v3' + }, + 'description': 'desc 3', + 'displayName': 'app789 - v3', + 'activeDebuggeeEnabled': True, + 'isActive': False, + 'isStale': True, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1669308800000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-11-24T16:53:20Z', +} + +DEBUGGEE_UNKNOWN_ACTIVITY = { + 'id': 'd-100', + 'labels': { + 'module': 'app100', + 'version': 'v3' + }, + 'description': 'desc 3', + 'displayName': 'app100 - v3', + 'activeDebuggeeEnabled': False, + 'isActive': False, + 'isStale': True, + 'registrationTimeUnixMsec': 0, + 'lastUpdateTimeUnixMsec': 0, + 'registrationTime': 'not set', + 'lastUpdateTime': 'not set', +} + class SnapshotDebuggerDebuggeeUtilsTests(unittest.TestCase): """ Contains the unit tests for the breakpoint_utils module. """ + def test_get_debuggee_state(self): + self.assertEqual('ACTIVE', get_debuggee_status(DEBUGGEE_ACTIVE)) + self.assertEqual('INACTIVE', get_debuggee_status(DEBUGGEE_INACTIVE)) + self.assertEqual('STALE', get_debuggee_status(DEBUGGEE_STALE)) + self.assertEqual('UNKNOWN', get_debuggee_status(DEBUGGEE_UNKNOWN_ACTIVITY)) + def test_set_converted_timestamps(self): """Verifies the set_converted_timestamps() works as expected. @@ -46,7 +121,7 @@ def test_set_converted_timestamps(self): }, { 'registrationTimeUnixMsec': 1649962215000, - 'registrationTime': '2022-04-14T18:50:15.000000Z' + 'registrationTime': '2022-04-14T18:50:15Z' }, ), ( @@ -67,7 +142,7 @@ def test_set_converted_timestamps(self): }, { 'lastUpdateTimeUnixMsec': 1649962215000, - 'lastUpdateTime': '2022-04-14T18:50:15.000000Z' + 'lastUpdateTime': '2022-04-14T18:50:15Z' }, ), ( @@ -89,9 +164,9 @@ def test_set_converted_timestamps(self): }, { 'registrationTimeUnixMsec': 1649962215000, - 'registrationTime': '2022-04-14T18:50:15.000000Z', + 'registrationTime': '2022-04-14T18:50:15Z', 'lastUpdateTimeUnixMsec': 1649962215001, - 'lastUpdateTime': '2022-04-14T18:50:15.001000Z' + 'lastUpdateTime': '2022-04-14T18:50:15Z' }, ), ] @@ -268,8 +343,8 @@ def test_normalize_debuggee_populates_missing_fields_as_expected(self): 'description': 'foo msg', 'registrationTimeUnixMsec': 1649962215426, 'lastUpdateTimeUnixMsec': 1649962230637, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-04-14T18:50:30.637000Z', + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-04-14T18:50:30Z', 'displayName': 'foo - v1', } @@ -278,8 +353,8 @@ def test_normalize_debuggee_populates_missing_fields_as_expected(self): ('description', ''), ('registrationTimeUnixMsec', 0), ('lastUpdateTimeUnixMsec', 0), - ('registrationTime', '2022-04-14T18:50:15.426000Z'), - ('lastUpdateTime', '2022-04-14T18:50:30.637000Z'), + ('registrationTime', '2022-04-14T18:50:15Z'), + ('lastUpdateTime', '2022-04-14T18:50:30Z'), ('displayName', 'foo - v1'), ] diff --git a/snapshot_dbg_cli_tests/test_delete_debuggees_command.py b/snapshot_dbg_cli_tests/test_delete_debuggees_command.py index 5272156..4627584 100644 --- a/snapshot_dbg_cli_tests/test_delete_debuggees_command.py +++ b/snapshot_dbg_cli_tests/test_delete_debuggees_command.py @@ -46,8 +46,8 @@ 'isStale': False, 'registrationTimeUnixMsec': 1649962215426, 'lastUpdateTimeUnixMsec': 1670000000000, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-12-02T16:53:20.000000Z', + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:20Z', } DEBUGGEE_INACTIVE = { @@ -63,8 +63,8 @@ 'isStale': False, 'registrationTimeUnixMsec': 1649962215426, 'lastUpdateTimeUnixMsec': 1669913600000, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-12-01T16:53:20.000000Z', + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-01T16:53:20Z', } DEBUGGEE_STALE = { @@ -80,8 +80,8 @@ 'isStale': True, 'registrationTimeUnixMsec': 1649962215426, 'lastUpdateTimeUnixMsec': 1669308800000, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-11-24T16:53:20.000000Z', + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-11-24T16:53:20Z', } DEBUGGEE_UNKNOWN_ACTIVITY = { @@ -222,13 +222,13 @@ def test_include_all_flag_deletes_inactive_stale_and_acitve_debuggees(self): def test_user_prompted_with_debuggee_summary_before_delete(self): expected_headers = ['Name', 'ID', 'Last Active', 'Status'] expected_active_row = [ - 'app123 - v1', 'd-123', '2022-12-02T16:53:20.000000Z', 'ACTIVE' + 'app123 - v1', 'd-123', '2022-12-02T16:53:20Z', 'ACTIVE' ] expected_inactive_row = [ - 'app456 - v2', 'd-456', '2022-12-01T16:53:20.000000Z', 'INACTIVE' + 'app456 - v2', 'd-456', '2022-12-01T16:53:20Z', 'INACTIVE' ] expected_stale_row = [ - 'app789 - v3', 'd-789', '2022-11-24T16:53:20.000000Z', 'STALE' + 'app789 - v3', 'd-789', '2022-11-24T16:53:20Z', 'STALE' ] expected_unknown_activity_row = [ 'app100 - v3', 'd-100', 'not set', 'UNKNOWN' diff --git a/snapshot_dbg_cli_tests/test_delete_logpoints_command.py b/snapshot_dbg_cli_tests/test_delete_logpoints_command.py index 0ac7c83..b813beb 100644 --- a/snapshot_dbg_cli_tests/test_delete_logpoints_command.py +++ b/snapshot_dbg_cli_tests/test_delete_logpoints_command.py @@ -44,7 +44,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_WITH_CONDITION = { @@ -59,7 +59,7 @@ 'isFinalState': False, 'location': {'line': 27, 'path': 'index.js'}, 'userEmail': 'user_b@foo.com', - 'createTime': '2022-04-14T18:50:16.852000Z', + 'createTime': '2022-04-14T18:50:16Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_EXPIRED = { @@ -73,8 +73,8 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user_c@foo.com', - 'createTime': '2022-04-14T18:50:17.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:17Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The logpoint has expired' @@ -91,7 +91,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) class DeleteLogpointsCommandTests(unittest.TestCase): diff --git a/snapshot_dbg_cli_tests/test_delete_snapshots_command.py b/snapshot_dbg_cli_tests/test_delete_snapshots_command.py index dec8ade..41e773d 100644 --- a/snapshot_dbg_cli_tests/test_delete_snapshots_command.py +++ b/snapshot_dbg_cli_tests/test_delete_snapshots_command.py @@ -40,7 +40,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_WITH_CONDITION = { @@ -51,7 +51,7 @@ 'isFinalState': False, 'location': {'line': 27, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) @@ -62,7 +62,7 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_ACTIVE = { @@ -76,7 +76,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) class DeleteSnapshotsCommandTests(unittest.TestCase): diff --git a/snapshot_dbg_cli_tests/test_get_logpoint_command.py b/snapshot_dbg_cli_tests/test_get_logpoint_command.py index 6da1aa6..6c4b5ff 100644 --- a/snapshot_dbg_cli_tests/test_get_logpoint_command.py +++ b/snapshot_dbg_cli_tests/test_get_logpoint_command.py @@ -42,7 +42,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_EXPIRED = { @@ -56,8 +56,8 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user_c@foo.com', - 'createTime': '2022-04-14T18:50:17.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:17Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The logpoint has expired' @@ -78,8 +78,8 @@ 'isFinalState': True, 'location': {'line': 29, 'path': 'index.js'}, 'userEmail': 'user_d@foo.com', - 'createTime': '2022-04-14T18:50:18.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:18Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'No code found at line 29' @@ -101,7 +101,7 @@ 'isFinalState': False, 'location': {'line': 30, 'path': 'index.js'}, 'userEmail': 'user_e@foo.com', - 'createTime': '2022-04-14T18:50:19.852000Z', + 'createTime': '2022-04-14T18:50:19Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_ACTIVE = { @@ -113,7 +113,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) class GetLogpointTests(unittest.TestCase): @@ -247,15 +247,14 @@ def test_logpoint_summary_is_as_expected(self): logpoint_user_email_missing = logpoint_active.copy() del logpoint_user_email_missing['userEmail'] - expected_summary_active = ( - 'Logpoint ID: b-1649962215\n' - 'Log Message Format: a: {a}\n' - 'Location: index.js:26\n' - 'Condition: No condition set\n' - 'Status: ACTIVE\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' - 'Final Time: \n' - 'User Email: user_a@foo.com\n') + expected_summary_active = ('Logpoint ID: b-1649962215\n' + 'Log Message Format: a: {a}\n' + 'Location: index.js:26\n' + 'Condition: No condition set\n' + 'Status: ACTIVE\n' + 'Create Time: 2022-04-14T18:50:15Z\n' + 'Final Time: \n' + 'User Email: user_a@foo.com\n') expected_summary_with_condition = ( 'Logpoint ID: b-1649962219\n' @@ -263,7 +262,7 @@ def test_logpoint_summary_is_as_expected(self): 'Location: index.js:30\n' 'Condition: a == 3\n' 'Status: ACTIVE\n' - 'Create Time: 2022-04-14T18:50:19.852000Z\n' + 'Create Time: 2022-04-14T18:50:19Z\n' 'Final Time: \n' 'User Email: user_e@foo.com\n') @@ -273,7 +272,7 @@ def test_logpoint_summary_is_as_expected(self): 'Location: index.js:30\n' 'Condition: No condition set\n' 'Status: ACTIVE\n' - 'Create Time: 2022-04-14T18:50:19.852000Z\n' + 'Create Time: 2022-04-14T18:50:19Z\n' 'Final Time: \n' 'User Email: user_e@foo.com\n') @@ -281,15 +280,14 @@ def test_logpoint_summary_is_as_expected(self): # present but empty should produce the same result. expected_summary_condition_empty = expected_summary_without_condition - expected_summary_expired = ( - 'Logpoint ID: b-1649962217\n' - 'Log Message Format: c: {c}\n' - 'Location: index.js:28\n' - 'Condition: No condition set\n' - 'Status: EXPIRED\n' - 'Create Time: 2022-04-14T18:50:17.852000Z\n' - 'Final Time: 2022-04-14T18:50:31.274000Z\n' - 'User Email: user_c@foo.com\n') + expected_summary_expired = ('Logpoint ID: b-1649962217\n' + 'Log Message Format: c: {c}\n' + 'Location: index.js:28\n' + 'Condition: No condition set\n' + 'Status: EXPIRED\n' + 'Create Time: 2022-04-14T18:50:17Z\n' + 'Final Time: 2022-04-14T18:50:31Z\n' + 'User Email: user_c@foo.com\n') expected_summary_failed = ( 'Logpoint ID: b-1649962218\n' @@ -297,8 +295,8 @@ def test_logpoint_summary_is_as_expected(self): 'Location: index.js:29\n' 'Condition: No condition set\n' 'Status: SOURCE_LOCATION: No code found at line 29\n' - 'Create Time: 2022-04-14T18:50:18.852000Z\n' - 'Final Time: 2022-04-14T18:50:31.274000Z\n' + 'Create Time: 2022-04-14T18:50:18Z\n' + 'Final Time: 2022-04-14T18:50:31Z\n' 'User Email: user_d@foo.com\n') expected_summary_user_email_missing = ( @@ -307,7 +305,7 @@ def test_logpoint_summary_is_as_expected(self): 'Location: index.js:26\n' 'Condition: No condition set\n' 'Status: ACTIVE\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' + 'Create Time: 2022-04-14T18:50:15Z\n' 'Final Time: \n' 'User Email: \n') diff --git a/snapshot_dbg_cli_tests/test_get_snapshot_command.py b/snapshot_dbg_cli_tests/test_get_snapshot_command.py index 05aa8e5..bdcb3e3 100644 --- a/snapshot_dbg_cli_tests/test_get_snapshot_command.py +++ b/snapshot_dbg_cli_tests/test_get_snapshot_command.py @@ -41,7 +41,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_COMPLETE = { @@ -91,8 +91,8 @@ } ], 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:15Z', + 'finalTime': '2022-04-14T18:50:31Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_EXPIRED = { @@ -104,8 +104,8 @@ 'isFinalState': True, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:15Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The snapshot has expired' @@ -124,8 +124,8 @@ 'isFinalState': True, 'location': {'line': 100, 'path': 'index.js'}, 'userEmail': 'foo@bar.com', - 'createTime': '2022-04-14T18:50:15.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:15Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'Invalid snapshot position: index.js:100.' @@ -146,7 +146,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) class GetSnapshotTests(unittest.TestCase): @@ -296,7 +296,7 @@ def test_summary_section(self): 'Condition: a == 3\n' "Expressions: ['a', 'b', 'a+b']\n" 'Status: Active\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' + 'Create Time: 2022-04-14T18:50:15Z\n' 'Final Time: \n') expected_summary_with_condition = expected_summary_active @@ -306,7 +306,7 @@ def test_summary_section(self): 'Condition: No condition set\n' "Expressions: ['a', 'b', 'a+b']\n" 'Status: Active\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' + 'Create Time: 2022-04-14T18:50:15Z\n' 'Final Time: \n') expected_summary_condition_empty = expected_summary_without_condition @@ -318,7 +318,7 @@ def test_summary_section(self): 'Condition: a == 3\n' 'Expressions: No expressions set\n' 'Status: Active\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' + 'Create Time: 2022-04-14T18:50:15Z\n' 'Final Time: \n') expected_summary_expressions_empty = expected_summary_without_expressions @@ -328,16 +328,16 @@ def test_summary_section(self): 'Condition: a == 3\n' "Expressions: ['a', 'b', 'a+b']\n" 'Status: Complete\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' - 'Final Time: 2022-04-14T18:50:31.274000Z\n') + 'Create Time: 2022-04-14T18:50:15Z\n' + 'Final Time: 2022-04-14T18:50:31Z\n') expected_summary_expired = ( expected_header + 'Location: index.js:26\n' 'Condition: a == 3\n' "Expressions: ['a', 'b', 'a+b']\n" 'Status: The snapshot has expired\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' - 'Final Time: 2022-04-14T18:50:31.274000Z\n') + 'Create Time: 2022-04-14T18:50:15Z\n' + 'Final Time: 2022-04-14T18:50:31Z\n') expected_summary_failed = ( expected_header + 'Location: index.js:100\n' @@ -345,8 +345,8 @@ def test_summary_section(self): "Expressions: ['a', 'b', 'a+b']\n" 'Status: ERROR: Invalid snapshot position: index.js:100. ' '(refers to: BREAKPOINT_SOURCE_LOCATION)\n' - 'Create Time: 2022-04-14T18:50:15.852000Z\n' - 'Final Time: 2022-04-14T18:50:31.274000Z\n') + 'Create Time: 2022-04-14T18:50:15Z\n' + 'Final Time: 2022-04-14T18:50:31Z\n') # We tag each testcase with information on wether the summary section is the # only expected output from the test. Since the condition/expressions tests diff --git a/snapshot_dbg_cli_tests/test_list_debuggees_command.py b/snapshot_dbg_cli_tests/test_list_debuggees_command.py index d1e5d2a..f157cb4 100644 --- a/snapshot_dbg_cli_tests/test_list_debuggees_command.py +++ b/snapshot_dbg_cli_tests/test_list_debuggees_command.py @@ -37,6 +37,74 @@ # data returned from the rtdb query, so the first field is the expected json # response data. +DEBUGGEE_ACTIVE = ({ + 'id': 'd-123', + 'labels': { + 'module': 'app123', + 'version': 'v1' + }, + 'description': 'desc 1', + 'displayName': 'app123 - v1', + 'activeDebuggeeEnabled': True, + 'isActive': True, + 'isStale': False, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1670000000000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:20Z', +}, ['app123 - v1', 'd-123', 'desc 1', '2022-12-02T16:53:20Z', 'ACTIVE']) + +DEBUGGEE_INACTIVE = ({ + 'id': 'd-456', + 'labels': { + 'module': 'app456', + 'version': 'v2' + }, + 'description': 'desc 2', + 'displayName': 'app456 - v2', + 'activeDebuggeeEnabled': True, + 'isActive': False, + 'isStale': False, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1669913600000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-01T16:53:20Z', +}, ['app456 - v2', 'd-456', 'desc 2', '2022-12-01T16:53:20Z', 'INACTIVE']) + +DEBUGGEE_STALE = ({ + 'id': 'd-789', + 'labels': { + 'module': 'app789', + 'version': 'v3' + }, + 'description': 'desc 3', + 'displayName': 'app789 - v3', + 'activeDebuggeeEnabled': True, + 'isActive': False, + 'isStale': True, + 'registrationTimeUnixMsec': 1649962215426, + 'lastUpdateTimeUnixMsec': 1669308800000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-11-24T16:53:20Z', +}, ['app789 - v3', 'd-789', 'desc 3', '2022-11-24T16:53:20Z', 'STALE']) + +DEBUGGEE_UNKNOWN_ACTIVITY = ({ + 'id': 'd-100', + 'labels': { + 'module': 'app100', + 'version': 'v3' + }, + 'description': 'desc 3', + 'displayName': 'app100 - v3', + 'activeDebuggeeEnabled': False, + 'isActive': False, + 'isStale': True, + 'registrationTimeUnixMsec': 0, + 'lastUpdateTimeUnixMsec': 0, + 'registrationTime': 'not set', + 'lastUpdateTime': 'not set', +}, ['app100 - v3', 'd-100', 'desc 3', 'not set', 'UNKNOWN']) + debuggee1 = ({ 'id': '123', 'labels': { @@ -49,10 +117,10 @@ 'isActive': True, 'isStale': False, 'registrationTimeUnixMsec': 1649962215426, - 'lastUpdateTimeUnixMsec': 1670000000001, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-12-02T16:53:20.001000Z', -}, ['app123 - v1', '123', 'desc 1']) + 'lastUpdateTimeUnixMsec': 1670000001000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:21Z', +}, ['app123 - v1', '123', 'desc 1', '2022-12-02T16:53:21Z', 'ACTIVE']) debuggee2 = ({ 'id': '456', @@ -66,10 +134,10 @@ 'isActive': True, 'isStale': False, 'registrationTimeUnixMsec': 1649962215426, - 'lastUpdateTimeUnixMsec': 1670000000002, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-12-02T16:53:20.002000Z', -}, ['app456 - v2', '456', 'desc 2']) + 'lastUpdateTimeUnixMsec': 1670000002000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:22Z', +}, ['app456 - v2', '456', 'desc 2', '2022-12-02T16:53:22Z', 'ACTIVE']) debuggee3 = ({ 'agentVersion': 'google.com/node-gcp/v6.0.0', @@ -94,10 +162,13 @@ 'isActive': True, 'isStale': False, 'registrationTimeUnixMsec': 1649962215426, - 'lastUpdateTimeUnixMsec': 1670000000003, - 'registrationTime': '2022-04-14T18:50:15.426000Z', - 'lastUpdateTime': '2022-12-02T16:53:20.003000Z', -}, ['test-app - v1', 'd-ff02524f', 'node index.js module:test-app version:v1']) + 'lastUpdateTimeUnixMsec': 1670000003000, + 'registrationTime': '2022-04-14T18:50:15Z', + 'lastUpdateTime': '2022-12-02T16:53:23Z', +}, [ + 'test-app - v1', 'd-ff02524f', 'node index.js module:test-app version:v1', + '2022-12-02T16:53:23Z', 'ACTIVE' +]) class ListDebuggeesCommandTests(unittest.TestCase): @@ -144,7 +215,7 @@ def test_get_debuggees_called_once(self): self.rtdb_service_mock.get_debuggees.assert_called_once() def test_output_format_default(self): - expected_headers = ['Name', 'ID', 'Description'] + expected_headers = ['Name', 'ID', 'Description', 'Last Active', 'Status'] testcases = [ ('No debuggees present', {}, []), @@ -163,11 +234,32 @@ def test_output_format_default(self): [debuggee1[0], debuggee2[0], debuggee3[0]], [debuggee1[1], debuggee2[1], debuggee3[1]] ), + ( + 'Debuggee Active', + [DEBUGGEE_ACTIVE[0]], + [DEBUGGEE_ACTIVE[1]] + ), + ( + 'Debuggee Inactive', + [DEBUGGEE_INACTIVE[0]], + [DEBUGGEE_INACTIVE[1]] + ), + ( + 'Debuggee Stale', + [DEBUGGEE_STALE[0]], + [DEBUGGEE_STALE[1]] + ), + ( + 'Debuggee Unknown Activity', + [DEBUGGEE_UNKNOWN_ACTIVITY[0]], + [DEBUGGEE_UNKNOWN_ACTIVITY[1]] + ), ] # yapf: disable (Subjectively, testcases more readable hand formatted) for test_name, debuggees_response, expected_tabular_data in testcases: with self.subTest(test_name): - testargs = [] + # This will ensure the exact debuggee list returned gets emitted. + testargs = ['--include-inactive'] self.user_output_mock.reset_mock() self.rtdb_service_mock.get_debuggees = MagicMock( return_value=debuggees_response) diff --git a/snapshot_dbg_cli_tests/test_list_logpoints_command.py b/snapshot_dbg_cli_tests/test_list_logpoints_command.py index 9e07c46..ba47a1c 100644 --- a/snapshot_dbg_cli_tests/test_list_logpoints_command.py +++ b/snapshot_dbg_cli_tests/test_list_logpoints_command.py @@ -44,7 +44,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user_a@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) # NOTE: It would actually be unexpected to receive a logpoint that is complete @@ -63,8 +63,8 @@ 'isFinalState': True, 'location': {'line': 27, 'path': 'index.js'}, 'userEmail': 'user_b@foo.com', - 'createTime': '2022-04-14T18:50:16.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:16', + 'finalTime': '2022-04-14T18:50:31Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_EXPIRED = { @@ -78,8 +78,8 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user_c@foo.com', - 'createTime': '2022-04-14T18:50:17.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:17Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The logpoint has expired' @@ -101,8 +101,8 @@ 'isFinalState': True, 'location': {'line': 29, 'path': 'index.js'}, 'userEmail': 'user_d@foo.com', - 'createTime': '2022-04-14T18:50:18.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:18Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'No code found at line 29' @@ -124,7 +124,7 @@ 'isFinalState': False, 'location': {'line': 30, 'path': 'index.js'}, 'userEmail': 'user_e@foo.com', - 'createTime': '2022-04-14T18:50:19.852000Z', + 'createTime': '2022-04-14T18:50:19Z', } # yapf: disable (Subjectively, more readable hand formatted) class ListLogpointTests(unittest.TestCase): diff --git a/snapshot_dbg_cli_tests/test_list_snapshots_command.py b/snapshot_dbg_cli_tests/test_list_snapshots_command.py index 1e31944..ef2f5d1 100644 --- a/snapshot_dbg_cli_tests/test_list_snapshots_command.py +++ b/snapshot_dbg_cli_tests/test_list_snapshots_command.py @@ -42,7 +42,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_COMPLETE = { @@ -70,8 +70,8 @@ }, ], 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:16.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:16Z', + 'finalTime': '2022-04-14T18:50:31Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_EXPIRED = { @@ -83,8 +83,8 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:17.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:17Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'The snapshot has expired' @@ -103,8 +103,8 @@ 'isFinalState': True, 'location': {'line': 29, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:18.852000Z', - 'finalTime': '2022-04-14T18:50:31.274000Z', + 'createTime': '2022-04-14T18:50:18Z', + 'finalTime': '2022-04-14T18:50:31Z', 'status': { 'description': { 'format': 'Invalid snapshot position: index.js:100.' @@ -123,7 +123,7 @@ 'isFinalState': False, 'location': {'line': 30, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:19.852000Z', + 'createTime': '2022-04-14T18:50:19Z', } # yapf: disable (Subjectively, more readable hand formatted) class ListSnapshotTests(unittest.TestCase): @@ -271,11 +271,11 @@ def test_output_format_json_pretty(self): def test_output_default(self): expected_active_row = ('ACTIVE', 'index.js:26', '', '', 'b-1649962215') expected_completed_row = ('COMPLETED', 'index.js:27', '', - '2022-04-14T18:50:31.274000Z', 'b-1649962216') + '2022-04-14T18:50:31Z', 'b-1649962216') expected_expired_row = ('EXPIRED', 'index.js:28', '', - '2022-04-14T18:50:31.274000Z', 'b-1649962217') - expected_failed_row = ('FAILED', 'index.js:29', '', - '2022-04-14T18:50:31.274000Z', 'b-1649962218') + '2022-04-14T18:50:31Z', 'b-1649962217') + expected_failed_row = ('FAILED', 'index.js:29', '', '2022-04-14T18:50:31Z', + 'b-1649962218') expected_with_condition_row = ('ACTIVE', 'index.js:30', 'a == 3', '', 'b-1649962219') diff --git a/snapshot_dbg_cli_tests/test_set_logpoint_command.py b/snapshot_dbg_cli_tests/test_set_logpoint_command.py index 49261a7..cbae718 100644 --- a/snapshot_dbg_cli_tests/test_set_logpoint_command.py +++ b/snapshot_dbg_cli_tests/test_set_logpoint_command.py @@ -40,7 +40,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) diff --git a/snapshot_dbg_cli_tests/test_set_snapshot_command.py b/snapshot_dbg_cli_tests/test_set_snapshot_command.py index 663377f..c79ac4d 100644 --- a/snapshot_dbg_cli_tests/test_set_snapshot_command.py +++ b/snapshot_dbg_cli_tests/test_set_snapshot_command.py @@ -39,7 +39,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) diff --git a/snapshot_dbg_cli_tests/test_snapshot_debugger_rtdb_service.py b/snapshot_dbg_cli_tests/test_snapshot_debugger_rtdb_service.py index 9368655..924aebb 100644 --- a/snapshot_dbg_cli_tests/test_snapshot_debugger_rtdb_service.py +++ b/snapshot_dbg_cli_tests/test_snapshot_debugger_rtdb_service.py @@ -53,7 +53,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) SNAPSHOT_COMPLETED = { @@ -63,7 +63,7 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', } # yapf: disable (Subjectively, more readable hand formatted) LOGPOINT_ACTIVE = { @@ -73,7 +73,7 @@ 'isFinalState': False, 'location': {'line': 26, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', 'logMessageFormat': 'Message 1', } # yapf: disable (Subjectively, more readable hand formatted) @@ -84,7 +84,7 @@ 'isFinalState': True, 'location': {'line': 28, 'path': 'index.js'}, 'userEmail': 'user@foo.com', - 'createTime': '2022-04-14T18:50:15.852000Z', + 'createTime': '2022-04-14T18:50:15Z', 'logMessageFormat': 'Message 2', } # yapf: disable (Subjectively, more readable hand formatted) diff --git a/snapshot_dbg_cli_tests/test_time_utils.py b/snapshot_dbg_cli_tests/test_time_utils.py index 7eeb7c2..db0dbc5 100644 --- a/snapshot_dbg_cli_tests/test_time_utils.py +++ b/snapshot_dbg_cli_tests/test_time_utils.py @@ -25,24 +25,18 @@ class ListDebuggeesCommandTests(unittest.TestCase): """ def test_convert_unix_msec_to_rfc3339(self): - self.assertEqual('2022-04-14T18:50:15.000000Z', + self.assertEqual('2022-04-14T18:50:15Z', convert_unix_msec_to_rfc3339(1649962215000)) - self.assertEqual('2022-04-14T18:50:15.001000Z', - convert_unix_msec_to_rfc3339(1649962215001)) - self.assertEqual('2022-04-14T18:50:15.010000Z', - convert_unix_msec_to_rfc3339(1649962215010)) - self.assertEqual('2022-04-14T18:50:15.100000Z', - convert_unix_msec_to_rfc3339(1649962215100)) - self.assertEqual('2022-04-14T18:50:15.426000Z', - convert_unix_msec_to_rfc3339(1649962215426)) + self.assertEqual('2022-04-14T18:50:16Z', + convert_unix_msec_to_rfc3339(1649962216000)) # For any invalid input, the function will default to using a value of 0, # which represents the epoch (1970-01-01). This way the function can still # return a properly formatting string, and the value is recognizable as # indicating there was an issue and the actual time is not known. - self.assertEqual('1970-01-01T00:00:00.000000Z', + self.assertEqual('1970-01-01T00:00:00Z', convert_unix_msec_to_rfc3339(999999999999999)) - self.assertEqual('1970-01-01T00:00:00.000000Z', + self.assertEqual('1970-01-01T00:00:00Z', convert_unix_msec_to_rfc3339('asdf')) def test_set_converted_timestamps_one_conversion(self): @@ -53,7 +47,7 @@ def test_set_converted_timestamps_one_conversion(self): ] expected_data = { - 'fooTime': '2022-04-14T18:50:15.000000Z', + 'fooTime': '2022-04-14T18:50:15Z', 'fooTimeUnixMsec': 1649962215000 } @@ -69,9 +63,9 @@ def test_set_converted_timestamps_two_conversions(self): ] expected_data = { - 'fooTime': '2022-04-14T18:50:15.000000Z', + 'fooTime': '2022-04-14T18:50:15Z', 'fooTimeUnixMsec': 1649962215000, - 'barTime': '2022-04-14T18:50:16.000000Z', + 'barTime': '2022-04-14T18:50:16Z', 'barTimeUnixMsec': 1649962216000 }