Skip to content

chore: pad golden file timestamps #12256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cli/clitest/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
@@ -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": "",
Expand All @@ -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]",
Expand All @@ -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]",
Expand All @@ -46,7 +46,7 @@
},
"reason": "initiator",
"resources": [],
"deadline": "[timestamp]",
"deadline": "[timestamp ]",
"max_deadline": null,
"status": "running",
"daily_cost": 0
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions cli/testdata/coder_users_list.golden
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions cli/testdata/coder_users_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -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": "",
Expand Down