Skip to content

test(cli/clitest): pad replacements for table alignment #15942

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

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
40 changes: 25 additions & 15 deletions cli/clitest/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestGoldenFile(t *testing.T, fileName string, actual []byte, replacements m
// equality check.
func normalizeGoldenFile(t *testing.T, byt []byte) []byte {
// Replace any timestamps with a placeholder.
byt = timestampRegex.ReplaceAll(byt, []byte("[timestamp]"))
byt = timestampRegex.ReplaceAll(byt, []byte(pad("[timestamp]", 20)))

homeDir, err := os.UserHomeDir()
require.NoError(t, err)
Expand Down Expand Up @@ -202,21 +202,31 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
workspaceBuild := coderdtest.AwaitWorkspaceBuildJobCompleted(t, rootClient, workspace.LatestBuild.ID)

replacements := map[string]string{
firstUser.UserID.String(): "[first user ID]",
secondUser.ID.String(): "[second user ID]",
firstUser.OrganizationID.String(): "[first org ID]",
version.ID.String(): "[version ID]",
version.Name: "[version name]",
version.Job.ID.String(): "[version job ID]",
version.Job.FileID.String(): "[version file ID]",
version.Job.WorkerID.String(): "[version worker ID]",
template.ID.String(): "[template ID]",
workspace.ID.String(): "[workspace ID]",
workspaceBuild.ID.String(): "[workspace build ID]",
workspaceBuild.Job.ID.String(): "[workspace build job ID]",
workspaceBuild.Job.FileID.String(): "[workspace build file ID]",
workspaceBuild.Job.WorkerID.String(): "[workspace build worker ID]",
firstUser.UserID.String(): pad("[first user ID]", 36),
secondUser.ID.String(): pad("[second user ID]", 36),
firstUser.OrganizationID.String(): pad("[first org ID]", 36),
version.ID.String(): pad("[version ID]", 36),
version.Name: pad("[version name]", 36),
version.Job.ID.String(): pad("[version job ID]", 36),
version.Job.FileID.String(): pad("[version file ID]", 36),
version.Job.WorkerID.String(): pad("[version worker ID]", 36),
template.ID.String(): pad("[template ID]", 36),
workspace.ID.String(): pad("[workspace ID]", 36),
workspaceBuild.ID.String(): pad("[workspace build ID]", 36),
workspaceBuild.Job.ID.String(): pad("[workspace build job ID]", 36),
workspaceBuild.Job.FileID.String(): pad("[workspace build file ID]", 36),
workspaceBuild.Job.WorkerID.String(): pad("[workspace build worker ID]", 36),
}

return rootClient, replacements
}

func pad(s string, n int) string {
if len(s) >= n {
return s
}
n -= len(s)
pre := n / 2
post := n - pre
return strings.Repeat("=", pre) + s + strings.Repeat("=", post)
}
48 changes: 24 additions & 24 deletions cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
[
{
"id": "[workspace ID]",
"created_at": "[timestamp]",
"updated_at": "[timestamp]",
"owner_id": "[first user ID]",
"id": "===========[workspace ID]===========",
"created_at": "====[timestamp]=====",
"updated_at": "====[timestamp]=====",
"owner_id": "==========[first user ID]===========",
"owner_name": "testuser",
"owner_avatar_url": "",
"organization_id": "[first org ID]",
"organization_id": "===========[first org ID]===========",
"organization_name": "coder",
"template_id": "[template ID]",
"template_id": "===========[template ID]============",
"template_name": "test-template",
"template_display_name": "",
"template_icon": "",
"template_allow_user_cancel_workspace_jobs": false,
"template_active_version_id": "[version ID]",
"template_active_version_id": "============[version ID]============",
"template_require_active_version": false,
"latest_build": {
"id": "[workspace build ID]",
"created_at": "[timestamp]",
"updated_at": "[timestamp]",
"workspace_id": "[workspace ID]",
"id": "========[workspace build ID]========",
"created_at": "====[timestamp]=====",
"updated_at": "====[timestamp]=====",
"workspace_id": "===========[workspace ID]===========",
"workspace_name": "test-workspace",
"workspace_owner_id": "[first user ID]",
"workspace_owner_id": "==========[first user ID]===========",
"workspace_owner_name": "testuser",
"workspace_owner_avatar_url": "",
"template_version_id": "[version ID]",
"template_version_name": "[version name]",
"template_version_id": "============[version ID]============",
"template_version_name": "===========[version name]===========",
"build_number": 1,
"transition": "start",
"initiator_id": "[first user ID]",
"initiator_id": "==========[first user ID]===========",
"initiator_name": "testuser",
"job": {
"id": "[workspace build job ID]",
"created_at": "[timestamp]",
"started_at": "[timestamp]",
"completed_at": "[timestamp]",
"id": "======[workspace build job ID]======",
"created_at": "====[timestamp]=====",
"started_at": "====[timestamp]=====",
"completed_at": "====[timestamp]=====",
"status": "succeeded",
"worker_id": "[workspace build worker ID]",
"file_id": "[workspace build file ID]",
"worker_id": "====[workspace build worker ID]=====",
"file_id": "=====[workspace build file ID]======",
"tags": {
"owner": "",
"scope": "organization"
Expand All @@ -47,7 +47,7 @@
},
"reason": "initiator",
"resources": [],
"deadline": "[timestamp]",
"deadline": "====[timestamp]=====",
"max_deadline": null,
"status": "running",
"daily_cost": 0,
Expand All @@ -61,7 +61,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 All @@ -71,6 +71,6 @@
"automatic_updates": "never",
"allow_renames": false,
"favorite": false,
"next_start_at": "[timestamp]"
"next_start_at": "====[timestamp]====="
}
]
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
20 changes: 10 additions & 10 deletions cli/testdata/coder_users_list_--output_json.golden
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"id": "[first user ID]",
"id": "==========[first user ID]===========",
"username": "testuser",
"avatar_url": "",
"name": "Test User",
"email": "testuser@coder.com",
"created_at": "[timestamp]",
"updated_at": "[timestamp]",
"last_seen_at": "[timestamp]",
"created_at": "====[timestamp]=====",
"updated_at": "====[timestamp]=====",
"last_seen_at": "====[timestamp]=====",
"status": "active",
"login_type": "password",
"theme_preference": "",
"organization_ids": [
"[first org ID]"
"===========[first org ID]==========="
],
"roles": [
{
Expand All @@ -22,19 +22,19 @@
]
},
{
"id": "[second user ID]",
"id": "==========[second user ID]==========",
"username": "testuser2",
"avatar_url": "",
"name": "",
"email": "testuser2@coder.com",
"created_at": "[timestamp]",
"updated_at": "[timestamp]",
"last_seen_at": "[timestamp]",
"created_at": "====[timestamp]=====",
"updated_at": "====[timestamp]=====",
"last_seen_at": "====[timestamp]=====",
"status": "dormant",
"login_type": "password",
"theme_preference": "",
"organization_ids": [
"[first org ID]"
"===========[first org ID]==========="
],
"roles": []
}
Expand Down
Loading