From ff4d5c136dc15c4ff5b608cb09d88829a1bcdb68 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 21 Feb 2024 15:58:52 -0600 Subject: [PATCH 1/2] chore: padding on golden file timestamps Making the replacement the same length keeps table formats the same in a golden file. --- cli/clitest/golden.go | 10 +++++++++- cli/testdata/coder_list_--output_json.golden | 18 +++++++++--------- cli/testdata/coder_users_list.golden | 4 ++-- .../coder_users_list_--output_json.golden | 8 ++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cli/clitest/golden.go b/cli/clitest/golden.go index cfd253613cd22..5f644266931d3 100644 --- a/cli/clitest/golden.go +++ b/cli/clitest/golden.go @@ -122,7 +122,15 @@ ExtractCommandPathsLoop: // equality check. func NormalizeGoldenFile(t *testing.T, byt []byte) []byte { // Replace any timestamps with a placeholder. - byt = timestampRegex.ReplaceAll(byt, []byte("[timestamp]")) + byt = timestampRegex.ReplaceAllFunc(byt, func(source []byte) []byte { + // Pad the timestamps to maintain the same length. This is mainly for tabled + // output where the padding is important for alignment. + lenSrc := len(source) + rpl := "timestamp" + required := lenSrc - 2 + + return []byte("[" + fmt.Sprintf("%-*s", required, rpl) + "]") + }) homeDir, err := os.UserHomeDir() require.NoError(t, err) diff --git a/cli/testdata/coder_list_--output_json.golden b/cli/testdata/coder_list_--output_json.golden index 903e5681c2689..32b993d5f9b4b 100644 --- a/cli/testdata/coder_list_--output_json.golden +++ b/cli/testdata/coder_list_--output_json.golden @@ -1,8 +1,8 @@ [ { "id": "[workspace ID]", - "created_at": "[timestamp]", - "updated_at": "[timestamp]", + "created_at": "[timestamp ]", + "updated_at": "[timestamp ]", "owner_id": "[first user ID]", "owner_name": "testuser", "owner_avatar_url": "", @@ -16,8 +16,8 @@ "template_require_active_version": false, "latest_build": { "id": "[workspace build ID]", - "created_at": "[timestamp]", - "updated_at": "[timestamp]", + "created_at": "[timestamp ]", + "updated_at": "[timestamp ]", "workspace_id": "[workspace ID]", "workspace_name": "test-workspace", "workspace_owner_id": "[first user ID]", @@ -31,9 +31,9 @@ "initiator_name": "testuser", "job": { "id": "[workspace build job ID]", - "created_at": "[timestamp]", - "started_at": "[timestamp]", - "completed_at": "[timestamp]", + "created_at": "[timestamp ]", + "started_at": "[timestamp ]", + "completed_at": "[timestamp ]", "status": "succeeded", "worker_id": "[workspace build worker ID]", "file_id": "[workspace build file ID]", @@ -46,7 +46,7 @@ }, "reason": "initiator", "resources": [], - "deadline": "[timestamp]", + "deadline": "[timestamp ]", "max_deadline": null, "status": "running", "daily_cost": 0 @@ -55,7 +55,7 @@ "name": "test-workspace", "autostart_schedule": "CRON_TZ=US/Central 30 9 * * 1-5", "ttl_ms": 28800000, - "last_used_at": "[timestamp]", + "last_used_at": "[timestamp ]", "deleting_at": null, "dormant_at": null, "health": { diff --git a/cli/testdata/coder_users_list.golden b/cli/testdata/coder_users_list.golden index 0d2f2e30c933f..2a34b1f3fc67e 100644 --- a/cli/testdata/coder_users_list.golden +++ b/cli/testdata/coder_users_list.golden @@ -1,3 +1,3 @@ USERNAME EMAIL CREATED AT STATUS -testuser testuser@coder.com [timestamp] active -testuser2 testuser2@coder.com [timestamp] dormant +testuser testuser@coder.com [timestamp ] active +testuser2 testuser2@coder.com [timestamp ] dormant diff --git a/cli/testdata/coder_users_list_--output_json.golden b/cli/testdata/coder_users_list_--output_json.golden index b62ce009922f6..adc58065bba4d 100644 --- a/cli/testdata/coder_users_list_--output_json.golden +++ b/cli/testdata/coder_users_list_--output_json.golden @@ -5,8 +5,8 @@ "avatar_url": "", "name": "", "email": "testuser@coder.com", - "created_at": "[timestamp]", - "last_seen_at": "[timestamp]", + "created_at": "[timestamp ]", + "last_seen_at": "[timestamp ]", "status": "active", "login_type": "password", "theme_preference": "", @@ -26,8 +26,8 @@ "avatar_url": "", "name": "", "email": "testuser2@coder.com", - "created_at": "[timestamp]", - "last_seen_at": "[timestamp]", + "created_at": "[timestamp ]", + "last_seen_at": "[timestamp ]", "status": "dormant", "login_type": "password", "theme_preference": "", From b1581758133d847a4297d8d18888d1ae6b846c44 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Fri, 23 Feb 2024 11:06:08 -0600 Subject: [PATCH 2/2] padding --- cli/testdata/coder_list_--output_json.golden | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/testdata/coder_list_--output_json.golden b/cli/testdata/coder_list_--output_json.golden index 32b993d5f9b4b..c1b71ccd436d7 100644 --- a/cli/testdata/coder_list_--output_json.golden +++ b/cli/testdata/coder_list_--output_json.golden @@ -1,8 +1,8 @@ [ { "id": "[workspace ID]", - "created_at": "[timestamp ]", - "updated_at": "[timestamp ]", + "created_at": "[timestamp ]", + "updated_at": "[timestamp ]", "owner_id": "[first user ID]", "owner_name": "testuser", "owner_avatar_url": "",